aboutsummaryrefslogtreecommitdiff
path: root/src/main/solver
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/solver')
-rw-r--r--src/main/solver/solver.cpp23
-rw-r--r--src/main/solver/solver.h10
2 files changed, 20 insertions, 13 deletions
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 9af10a3..51cb574 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -19,7 +19,9 @@ solver::solver(const game_state& gs)
, init_state(gs)
, state(gs)
, states_searched(1)
+ , unique_states_searched(1)
, backtracks(0)
+ , dominance_moves(0)
, depth(0)
, root(nullptr, game_state::move(255, 255, 255))
, current_node(&root) {
@@ -44,7 +46,7 @@ solver::sol_state solver::run(optional<atomic<bool> &> terminate_solver) {
while(!(state.is_solved() || states_exhausted)) {
// If the terminate flag was supplied and has been set to true, return
if (terminate_solver && *terminate_solver) {
- return sol_state::cutoff;
+ return sol_state::timed_out;
}
#ifndef NDEBUG
@@ -76,6 +78,7 @@ solver::sol_state solver::run(optional<atomic<bool> &> terminate_solver) {
}
// If the state is not a new one, reverts to the last node with children
else {
+ unique_states_searched--;
states_exhausted = revert_to_last_node_with_children();
}
}
@@ -86,9 +89,11 @@ solver::sol_state solver::run(optional<atomic<bool> &> terminate_solver) {
current_node = &current_node->children.back();
state.make_move(current_node->move);
depth++;
+ if (current_node->move.is_dominance()) dominance_moves++;
}
states_searched++;
+ unique_states_searched++;
}
if (state.is_solved()) {
@@ -170,18 +175,18 @@ void solver::print_solution() const {
cout << "\n";
}
-int solver::get_states_searched() const {
- return states_searched;
-}
-
-int solver::get_final_depth() const {
- return depth;
+void solver::print_solution_info() const {
+ cout << "States Searched: " << states_searched << "\n"
+ << "Unique States Searched: " << unique_states_searched << "\n"
+ << "Backtracks: " << backtracks << "\n"
+ << "Dominance Moves: " << dominance_moves << "\n"
+ << "Final Search Depth: " << depth << "\n";
}
const solver::node& solver::get_search_tree() const {
return root;
}
-int solver::get_backtrack_count() {
- return backtracks;
+int solver::get_states_searched() const {
+ return states_searched;
}
diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h
index 665d72a..77e8bde 100644
--- a/src/main/solver/solver.h
+++ b/src/main/solver/solver.h
@@ -14,7 +14,7 @@
class solver {
public:
- enum class sol_state {solved, unsolvable, cutoff};
+ enum class sol_state {solved, unsolvable, timed_out};
global_cache cache;
struct node {
@@ -30,10 +30,9 @@ public:
sol_state run(boost::optional<std::atomic<bool> &> = boost::none);
void print_solution() const;
+ void print_solution_info() const;
int get_states_searched() const;
- int get_final_depth() const;
const node& get_search_tree() const;
- int get_backtrack_count();
private:
bool revert_to_last_node_with_children();
@@ -43,9 +42,12 @@ private:
const game_state init_state;
game_state state;
+
int states_searched;
+ int unique_states_searched;
int backtracks;
- uint depth;
+ int dominance_moves;
+ int depth;
node root;
node* current_node;