-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
87 lines (63 loc) · 2.47 KB
/
game.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef GAME_H
#define GAME_H
#include "card-storage.h"
#include "move.h"
#include <array>
#include <random>
inline constexpr int nb_freecells = 4;
inline constexpr int nb_homes = 4;
inline constexpr int nb_stacks = 8;
struct GameState {
GameState(void);
GameState(const GameState &other);
GameState& operator=(GameState &&other);
std::array<HomeDestination, nb_homes> homes;
std::array<FreeCell, nb_freecells> free_cells;
std::array<WorkStack, nb_stacks> stacks;
std::array<CardStorage *, nb_stacks+nb_freecells> non_homes;
std::array<CardStorage *, nb_stacks+nb_freecells+nb_homes> all_storage;
void recalculatePointerArrays_(void) ;
};
bool operator<(const GameState &lhs, const GameState &rhs);
bool operator==(const GameState &lhs, const GameState &rhs);
enum class LocationClass {FreeCells, Homes, Stacks};
struct Location {
LocationClass cl;
long id;
};
bool operator== (const Location &lhs, const Location &rhs) ;
bool operator!= (const Location &lhs, const Location &rhs) ;
std::ostream& operator<< (std::ostream& os, const Location & state) ;
std::ostream& operator<< (std::ostream& os, const GameState & state) ;
void initializeGameState(GameState *gs, std::default_random_engine &rng) ;
std::optional<std::pair<CardStorage *, WorkStack *>> findIrreversibleMove(GameState *gs, std::default_random_engine &rng) ;
void initializeFullRandom(GameState *gs, std::default_random_engine &rng) ;
void forceMove(CardStorage *from, WorkStack *to) ;
std::vector<Card> topCards(const GameState &gs) ;
bool cardIsHome(const GameState &gs, Card card) ;
bool cardCouldGoHome(const GameState &gs, Card card) ;
auto findHomeFor(const GameState &gs, Card card) -> decltype(gs.homes)::const_iterator;
const CardStorage * ptrFromLoc(const GameState &gs, Location const& loc) ;
Location locFromPtr(const GameState &gs, const CardStorage *ptr) ;
std::vector<RawMove> safeHomeMoves(const GameState &gs) ;
class InitialStateProducerItf {
public:
virtual GameState produce() =0;
virtual ~InitialStateProducerItf() {};
};
class RandomProducer : public InitialStateProducerItf {
public:
RandomProducer(int seed) : rng_(seed) {}
GameState produce() override;
private:
std::default_random_engine rng_;
};
class EasyProducer : public InitialStateProducerItf {
public:
EasyProducer(int seed, int difficulty) : rng_(seed), difficulty_(difficulty) {}
GameState produce() override;
private:
std::default_random_engine rng_;
int difficulty_;
};
#endif