]> git.scottworley.com Git - slidingtile/blob - sliding_tile_lib.cc
24642f1480cdc78c671afa16f3436c350e9b6164
[slidingtile] / sliding_tile_lib.cc
1 #include "sliding_tile_lib.h"
2
3 #include <istream>
4
5 signed char adjacent[BOARD_SIZE][5] = {
6 1, 4, -1, -1, -1,
7 0, 2, 5, -1, -1,
8 1, 3, 6, -1, -1,
9 2, 7, -1, -1, -1,
10 0, 5, 8, -1, -1,
11 1, 4, 6, 9, -1,
12 2, 5, 7, 10, -1,
13 3, 6, 11, -1, -1,
14 4, 9, 12, -1, -1,
15 5, 8, 10, 13, -1,
16 6, 9, 11, 14, -1,
17 7, 10, 15, -1, -1,
18 8, 13, -1, -1, -1,
19 9, 12, 14, -1, -1,
20 10, 13, 15, -1, -1,
21 11, 14, -1, -1, -1,
22 };
23
24 std::istream& operator>>(std::istream& is, Board& board) {
25 for (int i = 0; i < BOARD_SIZE; i++) {
26 if (!is.good()) {
27 is.setstate(std::istream::failbit);
28 break;
29 }
30 if (i > 0 && is.get() != ',') {
31 is.setstate(std::istream::failbit);
32 break;
33 }
34 int numeric;
35 is >> numeric;
36 board.board[i] = numeric;
37 }
38 return is;
39 }