aboutsummaryrefslogtreecommitdiff
path: root/src/main/solver/solver.h
blob: 21b8d6edbc0054add0f95e81d83ed215c2df38bc (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
//
// 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};
    global_cache cache;

    struct node {
        node(node*, move);
        node* parent;
        const move mv;
        std::vector<node> children;
    };

    explicit solver(const game_state&);
    ~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;
    const node& get_search_tree() const;

private:
    bool revert_to_last_node_with_children();
    void add_children(std::vector<move>&);
    void add_child(move);
    std::vector<move> get_next_moves();

    const game_state init_state;
    game_state state;

    int states_searched;
    int unique_states_searched;
    int backtracks;
    int dominance_moves;
    int depth;

    node root;
    node* current_node;
};


#endif //SOLVITAIRE_SOLVER_H