diff --git a/include/analyzed_grid.hpp b/include/analyzed_grid.hpp index bcef08c..6e02b3b 100644 --- a/include/analyzed_grid.hpp +++ b/include/analyzed_grid.hpp @@ -19,7 +19,7 @@ struct AnalyzedGrid { private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version){ + void serialize(Archive & ar, const unsigned int /*version*/){ ar & grid & analysis.solution_traces; } }; diff --git a/include/dynamic_grid.hpp b/include/dynamic_grid.hpp index 5c7eb20..ef9c71c 100644 --- a/include/dynamic_grid.hpp +++ b/include/dynamic_grid.hpp @@ -92,7 +92,7 @@ private: //! \brief Serializes the grid template - 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 diff --git a/include/generator.hpp b/include/generator.hpp deleted file mode 100644 index cd043c4..0000000 --- a/include/generator.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "grid.hpp" -#include - -namespace detail { - template - auto random_field(URNG&& r, std::index_sequence){ - std::uniform_int_distribution dis(1, 2); - return create_rectangular_field({ - ((void)I, dis(r))... - }); - } -} - -template -auto random_field(URNG&& r){ - using Indices = std::make_index_sequence; - return detail::random_field(r, Indices{}); -} diff --git a/include/rules.hpp b/include/rules.hpp index 2eea107..b9f9d9f 100644 --- a/include/rules.hpp +++ b/include/rules.hpp @@ -19,7 +19,7 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version){ + void serialize(Archive & ar, const unsigned int /*version*/){ ar & min_size; } }; diff --git a/include/grid.hpp b/include/static_grid.hpp similarity index 88% rename from include/grid.hpp rename to include/static_grid.hpp index 1c5fb1c..0a0f5fe 100644 --- a/include/grid.hpp +++ b/include/static_grid.hpp @@ -150,3 +150,19 @@ template auto create_rectangular_field(std::initializer_list grid){ return Grid(grid); } + +namespace detail { + template + auto random_field(URNG&& r, std::index_sequence){ + std::uniform_int_distribution dis(1, 2); + return create_rectangular_field({ + ((void)I, dis(r))... + }); + } +} + +template +auto random_static_grid(URNG&& r){ + using Indices = std::make_index_sequence; + return detail::random_field(r, Indices{}); +} diff --git a/src/PuzzleWuzzleGenerator.cpp b/src/generate.cpp similarity index 82% rename from src/PuzzleWuzzleGenerator.cpp rename to src/generate.cpp index d2ebdd7..2095357 100644 --- a/src/PuzzleWuzzleGenerator.cpp +++ b/src/generate.cpp @@ -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"; } diff --git a/src/Replayer.cpp b/src/replay.cpp similarity index 86% rename from src/Replayer.cpp rename to src/replay.cpp index 671072c..811157d 100644 --- a/src/Replayer.cpp +++ b/src/replay.cpp @@ -32,13 +32,9 @@ int main(int argc, char** argv){ std::cout << "= The puzzle =\n"; auto level = grid_from_file(vm["file"].as()); 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";