blob: 961072f35650e3bc5990017ab68306145e779ec8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
//
// Created by thecharlesblake on 10/24/17.
//
#ifndef SOLVITAIRE_SOLVER_H
#define SOLVITAIRE_SOLVER_H
#include <string>
#include <vector>
#include <atomic>
#include "../game/global_cache.h"
#include "../game/sol_rules.h"
class solver {
public:
enum class sol_state {solved, unsolvable, timed_out};
lru_cache cache;
struct node {
node(node*, move, boost::optional<lru_cache::item_list::iterator> = boost::none);
node* parent;
const move mv;
std::vector<node> children;
boost::optional<lru_cache::item_list::iterator> parent_state_iter; // Optional, as dominance moves aren't cached
};
explicit solver(const game_state&, uint64_t);
~solver();
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_unique_states_searched() const;
int get_cache_size() const;
const node& get_search_tree() const;
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);
const game_state init_state;
game_state state;
int states_searched;
int unique_states_searched;
int backtracks;
int dominance_moves;
int depth;
int max_depth;
node root;
node* current_node;
};
#endif //SOLVITAIRE_SOLVER_H
|