From: Scott Worley Date: Sat, 2 Jan 2016 05:48:55 +0000 (-0800) Subject: operator<< for printing for debugging X-Git-Url: http://git.scottworley.com/slidingtile/commitdiff_plain/cada47bfe401f2084c4248df10cdf0488bc8750a?ds=sidebyside;hp=e0768fd268b2b06ddd08f24bfc828b397d52a1bb operator<< for printing for debugging --- diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index 5b2e798..5037c8e 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -1,6 +1,7 @@ #include "sliding_tile_lib.h" #include +#include #include signed char adjacent[BOARD_SIZE][5] = { @@ -65,6 +66,16 @@ std::istream& operator>>(std::istream& is, Board& board) { return is; } +std::ostream& operator<<(std::ostream& os, const Board& board) { + for (int i = 0; i < BOARD_SIZE; i++) { + if (i > 0) { + os << " "; + } + os << int(board.board[i]); + } + return os; +} + signed char Board::hole() const { for (int i = 0; i < BOARD_SIZE; i++) { if (board[i] == 0) { diff --git a/sliding_tile_lib.h b/sliding_tile_lib.h index 4d6c015..d144789 100644 --- a/sliding_tile_lib.h +++ b/sliding_tile_lib.h @@ -2,6 +2,7 @@ #define _SLIDING_TILE_LIB_H #include +#include const int BOARD_DIM = 4; const int BOARD_SIZE = BOARD_DIM * BOARD_DIM; @@ -12,6 +13,7 @@ struct Board { signed char hole() const; }; std::istream& operator>>(std::istream& is, Board& board); +std::ostream& operator<<(std::ostream& os, const Board& board); extern signed char adjacent[BOARD_SIZE][5];