]>
git.scottworley.com Git - slidingtile/blob - sliding_tile_lib.cc
b8ddc154a1a829e3ce7843678c34901334ef7ddf
1 #include "sliding_tile_lib.h"
6 signed char adjacent
[BOARD_SIZE
][5] = {
25 bool Board::is_valid() {
26 bool seen
[BOARD_SIZE
];
27 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
31 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
32 if (board
[i
] < 0 || board
[i
] >= BOARD_SIZE
|| seen
[board
[i
]]) {
35 seen
[board
[i
]] = true;
38 // Redundant because pigeon-hole-principle, but check anyway
39 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
48 std::istream
& operator>>(std::istream
& is
, Board
& board
) {
49 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
51 is
.setstate(std::istream::failbit
);
54 if (i
> 0 && is
.get() != ',') {
55 is
.setstate(std::istream::failbit
);
60 board
.board
[i
] = numeric
;
62 if (!board
.is_valid()) {
63 is
.setstate(std::istream::failbit
);
68 signed char Board::hole() {
69 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
74 throw std::runtime_error("Board with no hole");