]> git.scottworley.com Git - slidingtile/blob - sliding_tile_lib.h
300ecdd6de243964e2bd066eec37bdbfa5b060ed
[slidingtile] / sliding_tile_lib.h
1 #ifndef _SLIDING_TILE_LIB_H
2 #define _SLIDING_TILE_LIB_H
3
4 #include <istream>
5 #include <memory>
6 #include <ostream>
7 #include <vector>
8
9 const int BOARD_DIM = 4;
10 const int BOARD_SIZE = BOARD_DIM * BOARD_DIM;
11
12 struct InvertedBoard {
13 signed char pos[BOARD_SIZE];
14 };
15
16 struct Board {
17 signed char board[BOARD_SIZE];
18 bool is_valid() const;
19 signed char hole() const;
20 InvertedBoard invert() const;
21 int distance(const Board& o) const;
22 int distance(const InvertedBoard& invo) const;
23 bool operator==(const Board& o) const;
24 bool operator!=(const Board& o) const;
25 };
26 std::istream& operator>>(std::istream& is, Board& board);
27 std::ostream& operator<<(std::ostream& os, const Board& board);
28
29 struct Step {
30 Board board;
31 std::shared_ptr<Step> prev;
32 std::vector<Step*> successors(std::shared_ptr<Step> shared_this);
33 static signed char adjacent[BOARD_SIZE][5];
34 };
35 std::ostream& operator<<(std::ostream& os, const Step& step);
36
37
38 #endif /* _SLIDING_TILE_LIB_H */