-
Notifications
You must be signed in to change notification settings - Fork 0
/
findertaggame.h
85 lines (74 loc) · 2.46 KB
/
findertaggame.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
#ifndef FINDERTAGGAME_H
#define FINDERTAGGAME_H
#include <tagboard.h>
#include <set>
#include <unordered_set>
#include <list>
#include <istream>
#include <ostream>
class FinderTagGame
{
public:
typedef std::list<TagBoard::Move> TagMoveList;
typedef std::list<TagBoard> TagBoardList;
private:
class NodeTag
{
TagBoard _board;
const NodeTag* _parent;
int _length;
TagBoard::Move _move;
public:
NodeTag(const TagBoard &tag);
NodeTag(const NodeTag* parent, TagBoard::Move move);
const NodeTag *getParent() const;
int getDistanceToVicktory() const;
TagBoard::Move getMove() const;
bool isCorrectMove(TagBoard::Move move) const;
const TagBoard &getTagBoard() const;
int length() const;
int operator() () const;
bool operator < (const NodeTag& tag) const;
bool operator <= (const NodeTag& tag) const;
bool operator == (const NodeTag& tag) const;
};
class NodeTagPool
{
class NodeTagHash
{
public:
std::size_t operator() (const NodeTag &tag) const;
};
typedef std::unordered_set<FinderTagGame::NodeTag, NodeTagHash> Pool;
mutable Pool _nodesTag;
public:
const FinderTagGame::NodeTag &get(const NodeTag *parent, TagBoard::Move move) const;
const FinderTagGame::NodeTag &get(const TagBoard &board);
const FinderTagGame::NodeTag &get(NodeTag &&tag) const;
std::size_t poolSize() const;
};
class NodeTagPtr
{
const FinderTagGame::NodeTag& _link;
public:
NodeTagPtr(const NodeTag &obj);
const FinderTagGame::NodeTag &node() const;
bool operator < (const NodeTagPtr &a) const;
bool operator <= (const NodeTagPtr &a) const;
};
typedef std::multiset<NodeTagPtr, std::less_equal<NodeTagPtr> > Nodes;
Nodes _nodes;
NodeTagPool _pool;
const NodeTag *_nodeAnswer;
void addPointerInQueue(const NodeTag &node);
const NodeTag& createNode(const NodeTag &parent, TagBoard::Move move);
void createNode(const TagBoard &tag);
const NodeTag *makeDecisionTree();
public:
FinderTagGame(std::istream &input);
FinderTagGame(const TagBoard &initialTag);
TagMoveList getMoveList();
friend std::ostream &operator << (std::ostream &out, const NodeTag& node);
};
std::ostream &operator << (std::ostream &out, const FinderTagGame::NodeTag& node);
#endif // FINDERTAGGAME_H