-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagboard.h
61 lines (49 loc) · 1.59 KB
/
tagboard.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
#ifndef TAGBOARD_H
#define TAGBOARD_H
#include <vector>
#include <list>
#include <utility>
#include <ostream>
#include <istream>
class TagBoard
{
public:
enum Move {left, right, top, bottom, notCorrect};
private:
typedef std::pair<std::size_t, std::size_t> Position;
typedef std::vector<int> Board;
std::size_t _size;
Board _board;
Position _emptyCellPos;
mutable int distanceToVictory = -1;
void resize(std::size_t size);
int &Value(Position cellPos);
int &Value(std::size_t first, std::size_t second);
void swapCell(Position firstCell, Position secondCell);
public:
TagBoard() : _size(0) {}
TagBoard(std::size_t size);
TagBoard(const TagBoard& parent, Move move);
bool makeMove(Move move);
bool isCorrectMove(Move move) const;
bool isSolutionExists() const;
int getDistanceToVictory() const;
int getDistanceToCell(int val, Position pos) const;
int getDistanceToCell(int val, std::size_t first, std::size_t second) const;
int getValue(std::size_t first, std::size_t second) const;
bool operator == (const TagBoard& tag) const;
bool operator != (const TagBoard& tag) const;
static bool isTurnBack(Move a, Move b);
friend std::ostream& operator << (std::ostream &out, const TagBoard& tag);
friend std::istream &operator >> (std::istream &in, TagBoard& tag);
friend struct std::hash<TagBoard>;
};
std::ostream &operator<<(std::ostream &out, const TagBoard::Move& move);
namespace std {
template<>
struct hash<TagBoard>
{
std::size_t operator() (const TagBoard &tag) const;
};
}
#endif // TAGBOARD_H