forked from ibenes/freecell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-strategies.h
72 lines (56 loc) · 1.77 KB
/
search-strategies.h
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
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef SEARCH_STRATEGIES_H
#define SEARCH_STRATEGIES_H
#include "search-interface.h"
#include "game.h"
#include <memory>
#include <vector>
class DummySearch : public SearchStrategyItf {
public:
DummySearch(size_t max_depth, size_t nb_attempts);
std::vector<SearchAction> solve(const SearchState &init_state) override ;
private:
size_t max_depth_;
size_t nb_attempts_;
std::default_random_engine rng_;
};
class BreadthFirstSearch : public SearchStrategyItf {
public:
BreadthFirstSearch(size_t mem_limit) : mem_limit_(mem_limit) {}
std::vector<SearchAction> solve(const SearchState &init_state) override ;
private:
size_t mem_limit_;
};
class DepthFirstSearch : public SearchStrategyItf {
public:
DepthFirstSearch(int depth_limit, size_t mem_limit) :
depth_limit_(depth_limit), mem_limit_(mem_limit) {}
std::vector<SearchAction> solve(const SearchState &init_state) override ;
private:
int depth_limit_;
size_t mem_limit_;
};
class AStarHeuristicItf {
public:
virtual double distanceLowerBound(const GameState &state) const =0;
};
class AStarSearch : public SearchStrategyItf {
public:
AStarSearch(std::unique_ptr<AStarHeuristicItf> &&heuristic, size_t mem_limit) :
heuristic_(std::move(heuristic)),
mem_limit_(mem_limit)
{}
std::vector<SearchAction> solve(const SearchState &init_state) override ;
private:
const std::unique_ptr<AStarHeuristicItf> heuristic_;
size_t mem_limit_;
};
// beware, this has been proven to NOT be a valid heuristic!
class OufOfHome_Pseudo : public AStarHeuristicItf {
public:
double distanceLowerBound(const GameState &state) const override;
};
class StudentHeuristic : public AStarHeuristicItf {
public:
double distanceLowerBound(const GameState &state) const override;
};
#endif