diff options
Diffstat (limited to 'src/main/solver')
| -rw-r--r-- | src/main/solver/solver.cpp | 15 | ||||
| -rw-r--r-- | src/main/solver/solver.h | 4 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index e55a4e3..ab24824 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -19,7 +19,7 @@ solver::solver(const game_state& gs) , init_state(gs) , state(gs) , states_searched(1) - , root(nullptr, game_state::move(0, 0)) + , root(nullptr, game_state::move(255, 255, 255)) , current_node(&root) { } @@ -48,10 +48,10 @@ bool solver::run() { bool is_new_state = cache.insert(state); if (is_new_state) { // Gets the legal moves in the current state - vector<game_state::move> next_moves = state.get_legal_moves(); + vector<game_state::move> next_moves = get_next_moves(); // If there are none, reverts to the last node with children - if (state.get_legal_moves().empty()) { + if (next_moves.empty()) { states_exhausted = revert_to_last_node_with_children(); } else { add_children(next_moves); @@ -77,11 +77,20 @@ bool solver::run() { } void solver::add_children(std::vector<game_state::move>& moves) { + current_node->children.reserve(moves.size()); for (auto move : moves) { add_child(move); } } +vector<game_state::move> solver::get_next_moves() { +#ifndef NO_CARD_JUST_MOVED + return state.get_legal_moves(current_node->move); +#else + return state.get_legal_moves(); +#endif +} + void solver::add_child(game_state::move move) { current_node->children.emplace_back(current_node, move); } diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 9488dda..80d4ef5 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -6,7 +6,6 @@ #define SOLVITAIRE_SOLVER_H #include <string> -#include <list> #include <vector> #include "../game/global_cache.h" @@ -20,7 +19,7 @@ public: node(node*, game_state::move); node* parent; const game_state::move move; - std::list<node> children; + std::vector<node> children; }; explicit solver(const game_state&); @@ -34,6 +33,7 @@ private: bool revert_to_last_node_with_children(); void add_children(std::vector<game_state::move>&); void add_child(game_state::move); + std::vector<game_state::move> get_next_moves(); const game_state init_state; game_state state; |
