From 27ebe493056ee29045361f86eea20cd176ff9143 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 15 Feb 2018 12:44:14 +0000 Subject: Fix solver bug for instant-solve games --- src/main/solver/solver.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index 7638d92..e55a4e3 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "solver.h" #include "../input-output/output/log_helper.h" @@ -23,15 +24,16 @@ solver::solver(const game_state& gs) } solver::node::node(node* p, const game_state::move m) - : parent(p), move(m) { + : parent(p), move(m), children() { } bool solver::run() { bool states_exhausted = false; while(!state.is_solved() && !states_exhausted) { #ifndef NDEBUG - if (current_node->move.is_dominance()) + if (current_node->move.is_dominance()) { LOG_DEBUG("(dominance move)"); + } LOG_DEBUG(state); #endif @@ -127,12 +129,14 @@ void solver::print_solution() const { cout << "Solution:\n"; cout << state_copy << "\n"; - // Ignores first move which is - while (!n->children.empty()) { - // TODO print move as well - state_copy.make_move(n->move); - cout << state_copy << "\n"; - n = &n->children.back(); + + if (states_searched > 1) { + while (!n->children.empty()) { + // TODO print move as well + state_copy.make_move(n->move); + cout << state_copy << "\n"; + n = &n->children.back(); + } } cout << "States Searched: " << states_searched << "\n"; } -- cgit v1.2.1