X-Git-Url: http://git.scottworley.com/slidingtile/blobdiff_plain/19bd29f9b2a3e4721943496debfc55e2a7d71da5..3edec61dc6b19f7c9030e971429d42b999a79e88:/sliding_tile_lib.h?ds=inline diff --git a/sliding_tile_lib.h b/sliding_tile_lib.h index 1ffe6fa..f0753fc 100644 --- a/sliding_tile_lib.h +++ b/sliding_tile_lib.h @@ -2,15 +2,49 @@ #define _SLIDING_TILE_LIB_H #include +#include +#include +#include +#include const int BOARD_DIM = 4; const int BOARD_SIZE = BOARD_DIM * BOARD_DIM; +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 { + Step(Board board, std::shared_ptr prev); + ~Step(); + + Board board; + std::shared_ptr prev; + + std::vector> successors(std::shared_ptr shared_this) const; + int length() const; + int cost(const InvertedBoard& invgoal) const; + + static signed char adjacent[BOARD_SIZE][5]; + static int count; +}; +std::ostream& operator<<(std::ostream& os, const Step& step); -extern signed char adjacent[BOARD_SIZE][5]; +std::shared_ptr find_path(const std::string& start, const std::string& goal, unsigned max_frontier); +std::shared_ptr find_path(const Board& start, const Board& goal, unsigned max_frontier); #endif /* _SLIDING_TILE_LIB_H */