aboutsummaryrefslogtreecommitdiff
path: root/src/main/solver
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/solver')
-rw-r--r--src/main/solver/solver.cpp17
-rw-r--r--src/main/solver/solver.h3
2 files changed, 9 insertions, 11 deletions
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 <iostream>
#include <algorithm>
#include <list>
+#include <malloc.h>
#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<atomic<bool> &> terminate_solver)
bool is_new_state = insert_res.second;
if (is_new_state) {
// Gets the legal moves in the current state
- vector<move> next_moves = get_next_moves();
+ vector<move> 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<lru_cache::item_list::iterator> i) {
current_node->children.emplace_back(current_node, m, i);
}
-vector<move> 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";
}
diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h
index 73d5e41..bc3af0a 100644
--- a/src/main/solver/solver.h
+++ b/src/main/solver/solver.h
@@ -25,7 +25,7 @@ public:
boost::optional<lru_cache::item_list::iterator> parent_state_iter; // Optional, as dominance moves aren't cached
};
- explicit solver(const game_state&);
+ explicit solver(const game_state&, uint64_t);
~solver();
sol_state run(boost::optional<std::atomic<bool> &> = boost::none);
@@ -39,7 +39,6 @@ private:
bool revert_to_last_node_with_children(boost::optional<lru_cache::item_list::iterator> = boost::none);
void add_children(std::vector<move>&, boost::optional<lru_cache::item_list::iterator> = boost::none);
void add_child(move, boost::optional<lru_cache::item_list::iterator> = boost::none);
- std::vector<move> get_next_moves();
const game_state init_state;
game_state state;