diff options
| author | thecharlesblake | 2017-10-28 22:21:03 +0100 |
|---|---|---|
| committer | thecharlesblake | 2017-10-28 22:21:03 +0100 |
| commit | c3e6f892599f145c14317e5712263b3e5562b785 (patch) | |
| tree | 05df02feec122f24ba8f8086b16ac7d8b3178a45 /src/main/solver.cpp | |
| parent | Add build order to game rules class (diff) | |
| download | metasol-c3e6f892599f145c14317e5712263b3e5562b785.tar.gz metasol-c3e6f892599f145c14317e5712263b3e5562b785.zip | |
Add generic solving and pile class
Diffstat (limited to 'src/main/solver.cpp')
| -rw-r--r-- | src/main/solver.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/solver.cpp b/src/main/solver.cpp index ac8ffb8..c706a01 100644 --- a/src/main/solver.cpp +++ b/src/main/solver.cpp @@ -5,6 +5,7 @@ #include <string> #include <ostream> #include <iostream> +#include <algorithm> #include "solver.h" #include "log_helper.h" @@ -34,9 +35,17 @@ bool solver::run() { // Create new nodes for each of the children vector<game_state> new_children = current.state.get_next_legal_states(); for (auto it = new_children.rbegin(); it != new_children.rend(); it++) { + game_state new_state = *it; + + // If we have seen the state before, ignore it (loop detection) + if (find(begin(current.history), end(current.history), new_state) + != end(current.history)) { + continue; + } + node n = current; n.history.push_back(n.state); - n.state = *it; + n.state = new_state; frontier.push_back(n); } |
