diff options
| author | thecharlesblake | 2018-03-08 14:46:59 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-03-08 14:46:59 +0000 |
| commit | 3def8c5c683ac48fdfe69f607fa54787093679ff (patch) | |
| tree | 8782467367ff9f99462e42437a851569c871ca04 /src | |
| parent | Add solvability code to main (diff) | |
| download | metasol-3def8c5c683ac48fdfe69f607fa54787093679ff.tar.gz metasol-3def8c5c683ac48fdfe69f607fa54787093679ff.zip | |
Fix strange segfault error
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/solver/solver.cpp | 16 | ||||
| -rw-r--r-- | src/main/solver/solver.h | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp index ab24824..463d059 100644 --- a/src/main/solver/solver.cpp +++ b/src/main/solver/solver.cpp @@ -23,13 +23,27 @@ solver::solver(const game_state& gs) , current_node(&root) { } +solver::~solver() { + // This code looks to be unnecessary, but on alpha-star 6212 without it, + // for reasons that I cannot fathom, it segfaults. + while (current_node != nullptr) { + current_node->children.clear(); + current_node = current_node->parent; + } +} + solver::node::node(node* p, const game_state::move m) : parent(p), move(m), children() { } -bool solver::run() { +bool solver::run(optional<atomic<bool> &> terminate_solver) { bool states_exhausted = false; 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 false; + } + #ifndef NDEBUG if (current_node->move.is_dominance()) { LOG_DEBUG("(dominance move)"); diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index 80d4ef5..2a024ac 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -7,6 +7,7 @@ #include <string> #include <vector> +#include <atomic> #include "../game/global_cache.h" #include "../game/sol_rules.h" @@ -23,8 +24,9 @@ public: }; explicit solver(const game_state&); + ~solver(); - bool run(); + bool run(boost::optional<std::atomic<bool> &> = boost::none); void print_solution() const; int get_states_searched() const; const node& get_search_tree() const; |
