Cleans up project and fixes some warnings
This commit is contained in:
parent
9e2c8f0c5c
commit
570bc18976
7 changed files with 34 additions and 48 deletions
|
@ -19,7 +19,7 @@ struct AnalyzedGrid {
|
|||
private:
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version){
|
||||
void serialize(Archive & ar, const unsigned int /*version*/){
|
||||
ar & grid & analysis.solution_traces;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -92,7 +92,7 @@ private:
|
|||
|
||||
//! \brief Serializes the grid
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version){
|
||||
void serialize(Archive & ar, const unsigned int /*version*/){
|
||||
ar & W & H & grid & positions;
|
||||
// archiving positions is redundant (I'm being lazy here)
|
||||
// consider make_nvp for readable json
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "grid.hpp"
|
||||
#include <random>
|
||||
|
||||
namespace detail {
|
||||
template <int W, int H, typename URNG, size_t... I>
|
||||
auto random_field(URNG&& r, std::index_sequence<I...>){
|
||||
std::uniform_int_distribution<int> dis(1, 2);
|
||||
return create_rectangular_field<W, H>({
|
||||
((void)I, dis(r))...
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <int W, int H, typename URNG>
|
||||
auto random_field(URNG&& r){
|
||||
using Indices = std::make_index_sequence<W*H>;
|
||||
return detail::random_field<W, H>(r, Indices{});
|
||||
}
|
|
@ -19,7 +19,7 @@ private:
|
|||
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version){
|
||||
void serialize(Archive & ar, const unsigned int /*version*/){
|
||||
ar & min_size;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -150,3 +150,19 @@ template <int W, int H, typename T>
|
|||
auto create_rectangular_field(std::initializer_list<T> grid){
|
||||
return Grid<W, H, T>(grid);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <int W, int H, typename URNG, size_t... I>
|
||||
auto random_field(URNG&& r, std::index_sequence<I...>){
|
||||
std::uniform_int_distribution<int> dis(1, 2);
|
||||
return create_rectangular_field<W, H>({
|
||||
((void)I, dis(r))...
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <int W, int H, typename URNG>
|
||||
auto random_static_grid(URNG&& r){
|
||||
using Indices = std::make_index_sequence<W*H>;
|
||||
return detail::random_field<W, H>(r, Indices{});
|
||||
}
|
|
@ -15,8 +15,8 @@ int main(int argc, char** argv){
|
|||
int w = 5;
|
||||
int h = 5;
|
||||
int c = 3;
|
||||
int explosion_size = 3;
|
||||
int n = 1000;
|
||||
unsigned int explosion_size = 3;
|
||||
unsigned int n = 1000;
|
||||
|
||||
// Describe program options
|
||||
po::options_description opts;
|
||||
|
@ -47,37 +47,31 @@ int main(int argc, char** argv){
|
|||
|
||||
BasicRules rules(explosion_size);
|
||||
|
||||
int solvable = 0;
|
||||
int unsolvable = 0;
|
||||
unsigned int solvable = 0;
|
||||
unsigned int unsolvable = 0;
|
||||
while(n--){
|
||||
auto field = random_dynamic_grid(w, h, c, gen);
|
||||
|
||||
if(verbose){
|
||||
std::cout << "= Puzzle " << n << " =\n";
|
||||
field.print(std::cout);
|
||||
}
|
||||
|
||||
auto solution = solve(field, rules);
|
||||
|
||||
if(!solution.solution_traces.empty()){
|
||||
++solvable;
|
||||
if(verbose){
|
||||
std::cout << solution.solution_traces.size() << " solutions\n";
|
||||
}
|
||||
} else {
|
||||
++unsolvable;
|
||||
if(verbose){
|
||||
std::cout << "no solutions\n";
|
||||
}
|
||||
}
|
||||
|
||||
std::string s = solution.solution_traces.empty() ? "u" : "s";
|
||||
std::string filename = "levels/" + std::to_string(w) + "_" + std::to_string(h) + "_" + std::to_string(c) + "_" + s + "_" + std::to_string(field.hash()) + ".lvl";
|
||||
grid_to_file({std::move(field), std::move(solution), rules}, filename);
|
||||
|
||||
if(verbose){
|
||||
std::cout << "= Puzzle " << n << " =\n";
|
||||
field.print(std::cout);
|
||||
std::cout << solution.solution_traces.size() << " solutions\n";
|
||||
std::cout << filename << "\n\n";
|
||||
}
|
||||
|
||||
grid_to_file({std::move(field), std::move(solution), rules}, filename);
|
||||
}
|
||||
|
||||
std::cout << solvable << " solvable\n";
|
||||
std::cout << unsolvable << " unsolvable\n";
|
||||
std::cout << solvable << " solvable (= " << 100 * solvable / double(solvable + unsolvable) << "%)\n";
|
||||
std::cout << unsolvable << " unsolvable (= " << 100 * unsolvable / double(solvable + unsolvable) << "%)\n";
|
||||
}
|
|
@ -32,13 +32,9 @@ int main(int argc, char** argv){
|
|||
std::cout << "= The puzzle =\n";
|
||||
auto level = grid_from_file(vm["file"].as<std::string>());
|
||||
level.grid.print(std::cout);
|
||||
if(level.analysis.solution_traces.empty()){
|
||||
std::cout << "has no solutions\n";
|
||||
} else {
|
||||
std::cout << "has " << level.analysis.solution_traces.size() << " solutions\n\n";
|
||||
}
|
||||
std::cout << "has " << level.analysis.solution_traces.size() << " solutions\n\n";
|
||||
|
||||
int count = 0;
|
||||
int count = 1;
|
||||
for(auto && solution : level.analysis.solution_traces){
|
||||
std::cout << "= Solution " << count++ << " =\n";
|
||||
|
Reference in a new issue