aboutsummaryrefslogtreecommitdiff
path: root/src/main/solver/solver.h
blob: 14dedc55aef1e3d958dfc5893b783653c976280b (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
//
// 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(move);
        const move mv;
        std::vector<move> child_moves;
        boost::optional<lru_cache::item_list::iterator> cache_state; // Optional, as dominance moves aren't cached
    };

    explicit solver(const game_state&, uint64_t);

    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;
    int get_states_rem_from_cache() const;
    const std::vector<node> get_frontier() const;

private:
    bool revert_to_last_node_with_children(boost::optional<lru_cache::item_list::iterator> = boost::none);
    void set_to_child();

    const game_state init_state;
    game_state state;
    std::vector<node> frontier;

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

    node root;
    std::vector<node>::iterator current_node;
};


#endif //SOLVITAIRE_SOLVER_H