From cada47bfe401f2084c4248df10cdf0488bc8750a Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Fri, 1 Jan 2016 21:48:55 -0800 Subject: [PATCH] operator<< for printing for debugging --- sliding_tile_lib.cc | 11 +++++++++++ sliding_tile_lib.h | 2 ++ 2 files changed, 13 insertions(+) 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]; -- 2.44.1