From 252c7398925b5267963c1a48251cd7ba2d4ec381 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 25 Jan 2018 15:20:54 +0000 Subject: Refactor game_state & cache to remove static hack --- src/main/solver/solver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 19fa79b..072db18 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -16,7 +16,7 @@ using namespace std; using namespace boost; solver::solver(const game_state& gs) - : initial_state(gs), states_searched(0) {} + : cache(gs), initial_state(gs), states_searched(0) {} solver::node::node(const game_state::move m, vector uc) @@ -30,7 +30,7 @@ bool solver::run() { states_searched++; LOG_DEBUG (state); frontier.emplace_back(game_state::move(0,0), state.get_legal_moves()); - cache.insert(state); + cache.insert(state.get_data()); while (!frontier.empty()) { node& current = frontier.back(); @@ -47,7 +47,7 @@ bool solver::run() { // (unless it's the null first move) if (frontier.size() > 1) { state.undo_move(current.move); - assert(cache.contains(state)); + assert(cache.contains(state.get_data())); LOG_DEBUG (state); } // Returns to the previous state @@ -60,7 +60,7 @@ bool solver::run() { state.make_move(next_move); // Insert the state into the global cache - bool is_new_state = cache.insert(state); + bool is_new_state = cache.insert(state.get_data()); if (is_new_state) { states_searched++; LOG_DEBUG (state); @@ -70,7 +70,7 @@ bool solver::run() { } else { // If we've seen the state before, undoes the move state.undo_move(next_move); - assert(cache.contains(state)); + assert(cache.contains(state.get_data())); } } } -- cgit v1.2.1 From 375a45f4a2ecc17b1e77816b1e2192f15816d362 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 30 Jan 2018 15:50:35 +0000 Subject: Update solver: cache uses game state not pile vec --- src/main/solver/solver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 072db18..6dddfb4 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -24,13 +24,13 @@ solver::node::node(const game_state::move m, } bool solver::run() { - ProfilerStart("solvitaire"); + //ProfilerStart("solvitaire"); game_state state = initial_state; states_searched++; LOG_DEBUG (state); frontier.emplace_back(game_state::move(0,0), state.get_legal_moves()); - cache.insert(state.get_data()); + cache.insert(state); while (!frontier.empty()) { node& current = frontier.back(); @@ -47,7 +47,7 @@ bool solver::run() { // (unless it's the null first move) if (frontier.size() > 1) { state.undo_move(current.move); - assert(cache.contains(state.get_data())); + assert(cache.contains(state)); LOG_DEBUG (state); } // Returns to the previous state @@ -60,7 +60,7 @@ bool solver::run() { state.make_move(next_move); // Insert the state into the global cache - bool is_new_state = cache.insert(state.get_data()); + bool is_new_state = cache.insert(state); if (is_new_state) { states_searched++; LOG_DEBUG (state); @@ -70,7 +70,7 @@ bool solver::run() { } else { // If we've seen the state before, undoes the move state.undo_move(next_move); - assert(cache.contains(state.get_data())); + assert(cache.contains(state)); } } } -- cgit v1.2.1