]> git.scottworley.com Git - slidingtile/blame - sliding_tile_lib.cc
Promote Board to a class so it can have methods.
[slidingtile] / sliding_tile_lib.cc
CommitLineData
82d6eed5
SW
1#include "sliding_tile_lib.h"
2
32688d85
SW
3#include <istream>
4
82d6eed5
SW
5signed 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};
32688d85
SW
23
24std::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;
19bd29f9 36 board.board[i] = numeric;
32688d85
SW
37 }
38 return is;
39}