From 74d43eaf200d42a3060de0f7b458902d52274225 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 1 Jan 2018 17:56:54 +0000 Subject: Fix bug in solver - improper ref to vector element --- src/main/solver/solver.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 23ed693..694ad4e 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -18,7 +18,7 @@ solver::solver(const game_state& gs, const sol_rules& sr) : initial_state(gs), rules(sr), states_searched(0) {} solver::node::node(const game_state::move m, - vector &&uc) + vector uc) : move(m), unsearched_children(std::move(uc)) { } @@ -27,10 +27,10 @@ bool solver::run() { frontier.emplace_back(NULL_MOVE, state.get_legal_moves()); states_searched++; + LOG_DEBUG (state); while (!frontier.empty()) { node& current = frontier.back(); - LOG_DEBUG (state); // If we have a solution, returns true if (state.is_solved()) return true; @@ -45,23 +45,24 @@ bool solver::run() { // Returns to the previous state frontier.pop_back(); } else { + game_state::move next_move = current.unsearched_children[current.unsearched_children.size()-1]; + current.unsearched_children.pop_back(); + // Applies the first possible move in this state - state.make_move(current.unsearched_children.back()); + state.make_move(next_move); // Insert the state into the global cache bool is_new_state = global_cache.insert(state.get_data()).second; if (is_new_state) { // If the state is new, creates a new node in the frontier to // represent the move just made, and those that are now possible - frontier.emplace_back(current.unsearched_children.back(), - state.get_legal_moves()); + frontier.emplace_back(next_move, state.get_legal_moves()); states_searched++; + LOG_DEBUG (state); } else { - // If we've seen the state before, undo the move - state.undo_move(current.unsearched_children.back()); + // If we've seen the state before, undoes the move + state.undo_move(next_move); } - // Removes the move just made from the list of possible moves - current.unsearched_children.pop_back(); } } -- cgit v1.2.1 From 77a7aeba7854d15b140cc6dc3c69b15ed5f3b936 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 3 Jan 2018 12:30:14 +0000 Subject: Major refactor, putting pile logic into game_state Much of the logic that was in the pile class was beginning to seem out of place. A lot of the rules have fairly arbitrary interactons *between* piles, which weren't best represented in the pile classes themselves, which were getting unweildy and inefficient. Hence, much of this logic has been moved to the game state class. --- src/main/solver/solver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 694ad4e..66dcc07 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -25,9 +25,9 @@ solver::node::node(const game_state::move m, bool solver::run() { game_state state = initial_state; - frontier.emplace_back(NULL_MOVE, state.get_legal_moves()); states_searched++; LOG_DEBUG (state); + frontier.emplace_back(NULL_MOVE, state.get_legal_moves()); while (!frontier.empty()) { node& current = frontier.back(); @@ -54,11 +54,11 @@ bool solver::run() { // Insert the state into the global cache bool is_new_state = global_cache.insert(state.get_data()).second; if (is_new_state) { + states_searched++; + LOG_DEBUG (state); // If the state is new, creates a new node in the frontier to // represent the move just made, and those that are now possible frontier.emplace_back(next_move, state.get_legal_moves()); - states_searched++; - LOG_DEBUG (state); } else { // If we've seen the state before, undoes the move state.undo_move(next_move); -- cgit v1.2.1 From 7f4712b292632becfc83bc0e887271b25fefd21a Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 3 Jan 2018 13:05:31 +0000 Subject: Refactor io dir structure --- src/main/solver/solver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 66dcc07..b7d6de1 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -9,7 +9,7 @@ #include #include "solver.h" -#include "../input-output/log_helper.h" +#include "../input-output/output/log_helper.h" using namespace std; using namespace boost; -- cgit v1.2.1 From 4208d2570e74ab54d1878c72110bd380e7b197f2 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 3 Jan 2018 15:21:47 +0000 Subject: Move game state printing into dedicated class --- src/main/solver/solver.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index b7d6de1..e0fbbc6 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "solver.h" #include "../input-output/output/log_helper.h" -- cgit v1.2.1 From 067152f57ced18c5f706144909345125754e8664 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 8 Jan 2018 19:02:36 +0000 Subject: Add game logic for built pile (AA) and refactor --- src/main/solver/solver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/solver/solver.cpp') diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index e0fbbc6..aaaf530 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -26,7 +26,7 @@ bool solver::run() { states_searched++; LOG_DEBUG (state); - frontier.emplace_back(NULL_MOVE, state.get_legal_moves()); + frontier.emplace_back(game_state::null_move(), state.get_legal_moves()); while (!frontier.empty()) { node& current = frontier.back(); -- cgit v1.2.1