From fb3e96a333cc9b27529f5d2c7866a2f7c4d43ec2 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Wed, 13 Jun 2018 15:08:11 +0100 Subject: Add cache capacity command line option --- src/main/solver/solver.cpp | 17 ++++++++--------- 1 file changed, 8 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 d7c5465..fd80556 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "solver.h" #include "../game/move.h" @@ -20,12 +21,12 @@ using std::pair; using boost::optional; using std::max; -solver::solver(const game_state& gs) - : cache(lru_cache(gs, 1000000)) +solver::solver(const game_state& gs, uint64_t cache_capacity) + : cache(lru_cache(gs, cache_capacity)) , init_state(gs) , state(gs) - , states_searched(1) - , unique_states_searched(1) + , states_searched(0) + , unique_states_searched(0) , backtracks(0) , dominance_moves(0) , depth(0) @@ -75,7 +76,7 @@ solver::sol_state solver::run(boost::optional &> terminate_solver) bool is_new_state = insert_res.second; if (is_new_state) { // Gets the legal moves in the current state - vector next_moves = get_next_moves(); + vector next_moves = state.get_legal_moves(current_node->mv); // If there are none, reverts to the last node with children if (next_moves.empty()) { @@ -124,10 +125,6 @@ void solver::add_child(move m, optional i) { current_node->children.emplace_back(current_node, m, i); } -vector solver::get_next_moves() { - return state.get_legal_moves(current_node->mv); -} - // Called when the current node's children have been exhausted. Travels back up // the search tree until it finds a node which still has children. Returns true // unless all children have been exhausted. @@ -200,6 +197,8 @@ void solver::print_solution_info() const { << "Backtracks: " << backtracks << "\n" << "Dominance Moves: " << dominance_moves << "\n" << "States Removed From Cache: " << cache.get_states_removed_from_cache() << "\n" + << "Final States In Cache: " << cache.size() << "\n" + << "Final Buckets In Cache: " << cache.bucket_count() << "\n" << "Maximum Search Depth: " << max_depth << "\n" << "Final Search Depth: " << depth << "\n"; } -- cgit v1.2.1