diff options
| -rw-r--r-- | src/main/solver/solver.cpp | 13 | ||||
| -rw-r--r-- | src/main/solver/solver.h | 11 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index bd19351..ffcbc09 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -13,8 +13,8 @@ using namespace std; using namespace boost; -solver::solver(const game_state& gs, const sol_rules& sr) - : initial_state(gs), rules(sr), states_searched(0) {} +solver::solver(const game_state& gs) + : initial_state(gs), states_searched(0) {} solver::node::node(const game_state::move m, vector<game_state::move> uc) @@ -27,7 +27,7 @@ bool solver::run() { states_searched++; LOG_DEBUG (state); frontier.emplace_back(game_state::move(0,0), state.get_legal_moves()); - global_cache.insert(state.get_data()); + cache.insert(state); while (!frontier.empty()) { node& current = frontier.back(); @@ -41,7 +41,7 @@ bool solver::run() { // (unless it's the null first move) if (frontier.size() > 1) { state.undo_move(current.move); - assert(global_cache.count(state.get_data()) == 1); + assert(cache.contains(state)); LOG_DEBUG (state); } // Returns to the previous state @@ -53,8 +53,9 @@ bool solver::run() { // Applies the first possible move in this state state.make_move(next_move); + assert(state.piles.size() == 18); // Insert the state into the global cache - bool is_new_state = global_cache.insert(state.get_data()).second; + bool is_new_state = cache.insert(state); if (is_new_state) { states_searched++; LOG_DEBUG (state); @@ -64,7 +65,7 @@ bool solver::run() { } else { // If we've seen the state before, undoes the move state.undo_move(next_move); - assert(global_cache.count(state.get_data()) == 1); + assert(cache.contains(state)); } } } diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 563a11e..526bd53 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -7,17 +7,13 @@ #include <string> #include <vector> -#include <unordered_set> -#include "../game/game_state.h" +#include "../game/global_cache.h" #include "../game/sol_rules.h" class solver { public: - std::unordered_set< - std::vector<pile>, - boost::hash<std::vector<pile>> - > global_cache; + global_cache cache; struct node { explicit node(game_state::move, std::vector<game_state::move>); @@ -25,14 +21,13 @@ public: std::vector<game_state::move> unsearched_children; }; - solver(const game_state&, const sol_rules&); + explicit solver(const game_state&); bool run(); void print_solution() const; private: const game_state initial_state; - const sol_rules rules; std::vector<node> frontier; int states_searched; }; |
