]> git.scottworley.com Git - slidingtile/blame - sliding_tile_lib.h
Keep a count of live Steps
[slidingtile] / sliding_tile_lib.h
CommitLineData
82d6eed5
SW
1#ifndef _SLIDING_TILE_LIB_H
2#define _SLIDING_TILE_LIB_H
3
32688d85 4#include <istream>
5d2f7c7c 5#include <memory>
cada47bf 6#include <ostream>
537a8dc7 7#include <string>
5d2f7c7c 8#include <vector>
32688d85 9
e86755d7
SW
10const int BOARD_DIM = 4;
11const int BOARD_SIZE = BOARD_DIM * BOARD_DIM;
32688d85 12
9c32325f
SW
13struct InvertedBoard {
14 signed char pos[BOARD_SIZE];
15};
16
19bd29f9
SW
17struct Board {
18 signed char board[BOARD_SIZE];
cea272cf
SW
19 bool is_valid() const;
20 signed char hole() const;
9c32325f
SW
21 InvertedBoard invert() const;
22 int distance(const Board& o) const;
23 int distance(const InvertedBoard& invo) const;
0e89d341
SW
24 bool operator==(const Board& o) const;
25 bool operator!=(const Board& o) const;
310a7132 26 bool operator<(const Board& o) const;
19bd29f9 27};
32688d85 28std::istream& operator>>(std::istream& is, Board& board);
cada47bf 29std::ostream& operator<<(std::ostream& os, const Board& board);
32688d85 30
5d2f7c7c 31struct Step {
537a8dc7 32 Step(Board board, std::shared_ptr<Step> prev);
1955dd8b 33 ~Step();
537a8dc7 34
5d2f7c7c
SW
35 Board board;
36 std::shared_ptr<Step> prev;
537a8dc7
SW
37
38 std::vector<std::shared_ptr<Step>> successors(std::shared_ptr<Step> shared_this) const;
39 int length() const;
40 int cost(const InvertedBoard& invgoal) const;
41
5d2f7c7c 42 static signed char adjacent[BOARD_SIZE][5];
1955dd8b 43 static int count;
5d2f7c7c 44};
49358f36 45std::ostream& operator<<(std::ostream& os, const Step& step);
5d2f7c7c 46
537a8dc7
SW
47std::shared_ptr<Step> find_path(const std::string& start, const std::string& goal);
48std::shared_ptr<Step> find_path(const Board& start, const Board& goal);
82d6eed5
SW
49
50#endif /* _SLIDING_TILE_LIB_H */