]> git.scottworley.com Git - slidingtile/blobdiff - sliding_tile_lib.h
operator< for Board
[slidingtile] / sliding_tile_lib.h
index 7b16a5164dae48870fdb431f2911fbd7bb91a16c..772817ea5ea57d84d28aafa6f6d0a9d607e39187 100644 (file)
@@ -1,20 +1,39 @@
+#ifndef _SLIDING_TILE_LIB_H
+#define _SLIDING_TILE_LIB_H
+
+#include <istream>
+#include <memory>
+#include <ostream>
+#include <vector>
+
 const int BOARD_DIM = 4;
 const int BOARD_SIZE = BOARD_DIM * BOARD_DIM;
-signed char adjacent[BOARD_SIZE][5] = {
-  1,   4,   -1,  -1,  -1,
-  0,   2,   5,   -1,  -1,
-  1,   3,   6,   -1,  -1,
-  2,   7,   -1,  -1,  -1,
-  0,   5,   8,   -1,  -1,
-  1,   4,   6,   9,   -1,
-  2,   5,   7,   10,  -1,
-  3,   6,   11,  -1,  -1,
-  4,   9,   12,  -1,  -1,
-  5,   8,   10,  13,  -1,
-  6,   9,   11,  14,  -1,
-  7,   10,  15,  -1,  -1,
-  8,   13,  -1,  -1,  -1,
-  9,   12,  14,  -1,  -1,
-  10,  13,  15,  -1,  -1,
-  11,  14,  -1,  -1,  -1,
+
+struct InvertedBoard {
+  signed char pos[BOARD_SIZE];
 };
+
+struct Board {
+  signed char board[BOARD_SIZE];
+  bool is_valid() const;
+  signed char hole() const;
+  InvertedBoard invert() const;
+  int distance(const Board& o) const;
+  int distance(const InvertedBoard& invo) const;
+  bool operator==(const Board& o) const;
+  bool operator!=(const Board& o) const;
+  bool operator<(const Board& o) const;
+};
+std::istream& operator>>(std::istream& is, Board& board);
+std::ostream& operator<<(std::ostream& os, const Board& board);
+
+struct Step {
+  Board board;
+  std::shared_ptr<Step> prev;
+  std::vector<Step*> successors(std::shared_ptr<Step> shared_this);
+  static signed char adjacent[BOARD_SIZE][5];
+};
+std::ostream& operator<<(std::ostream& os, const Step& step);
+
+
+#endif /* _SLIDING_TILE_LIB_H */