X-Git-Url: http://git.scottworley.com/slidingtile/blobdiff_plain/49358f3664c36c346dba758ae1b7da9106c42e3b..f92e9dcac70dc0859e1cf176b84b39c42f677e3e:/sliding_tile_lib.cc diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index 82402a5..5284dab 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -49,6 +49,30 @@ bool Board::is_valid() const { return true; } +bool Board::operator==(const Board& o) const { + for (int i = 0; i < BOARD_SIZE; i++) { + if (board[i] != o.board[i]) { + return false; + } + } + return true; +} + +bool Board::operator!=(const Board& o) const { + return !operator==(o); +} + +bool Board::operator<(const Board& o) const { + for (int i = 0; i < BOARD_SIZE; i++) { + if (board[i] < o.board[i]) { + return true; + } else if (board[i] > o.board[i]) { + return false; + } + } + return false; +} + std::istream& operator>>(std::istream& is, Board& board) { for (int i = 0; i < BOARD_SIZE; i++) { if (!is.good()) { @@ -109,7 +133,7 @@ int Board::distance(const InvertedBoard& invo) const { return dist; } -std::vector Step::successors(std::shared_ptr shared_this) { +std::vector Step::successors(std::shared_ptr shared_this) const { std::vector suc; signed char hole_pos = board.hole(); for (int i = 0; adjacent[hole_pos][i] > 0; i++) {