From a1bda7d722d4eac4c91affcb52abcbd5138105db Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sun, 31 Dec 2017 11:48:02 +0000 Subject: Make solver representation efficient --- src/main/solver/solver.h | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'src/main/solver/solver.h') diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h index bb5f8cf..1ef841d 100644 --- a/src/main/solver/solver.h +++ b/src/main/solver/solver.h @@ -7,48 +7,33 @@ #include #include - -#include -#include -#include -#include -#include +#include #include "../game/game_state.h" #include "../game/sol_rules.h" class solver { public: - typedef boost::multi_index::multi_index_container< - game_state, - boost::multi_index::indexed_by< - boost::multi_index::sequenced<>, - boost::multi_index::hashed_unique> - > - > node_history; + std::unordered_set< + std::vector, + boost::hash> + > global_cache; struct node { - node(const node*, const game_state&); - node_history history; - game_state state; - - static const node_history gen_history(const node* parent); + explicit node(const game_state::move, std::vector&&); + const game_state::move move; + std::vector unsearched_children; }; - solver(const game_state, const sol_rules&); - - const node get_root() const; - int get_states_searched() const; + solver(const game_state&, const sol_rules&); - const boost::optional run(); - - friend std::ostream& operator<< (std::ostream&, const solver::node&); + bool run(); + void print_solution() const; private: - - const node root; + const game_state initial_state; const sol_rules rules; - node solution; + std::vector frontier; int states_searched; }; -- cgit v1.2.1