X-Git-Url: http://git.scottworley.com/slidingtile/blobdiff_plain/82d6eed523b5c102d826b66e21c03f5577199714..32688d85f745574d7bbf941985234458d2776cce:/sliding_tile_lib.cc?ds=sidebyside diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index 4b422c1..a4d522e 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -1,5 +1,7 @@ #include "sliding_tile_lib.h" +#include + signed char adjacent[BOARD_SIZE][5] = { 1, 4, -1, -1, -1, 0, 2, 5, -1, -1, @@ -18,3 +20,20 @@ signed char adjacent[BOARD_SIZE][5] = { 10, 13, 15, -1, -1, 11, 14, -1, -1, -1, }; + +std::istream& operator>>(std::istream& is, Board& board) { + for (int i = 0; i < BOARD_SIZE; i++) { + if (!is.good()) { + is.setstate(std::istream::failbit); + break; + } + if (i > 0 && is.get() != ',') { + is.setstate(std::istream::failbit); + break; + } + int numeric; + is >> numeric; + board[i] = numeric; + } + return is; +}