]>
git.scottworley.com Git - slidingtile/blob - sliding_tile_lib.cc
1 #include "sliding_tile_lib.h"
5 signed char adjacent
[BOARD_SIZE
][5] = {
24 bool Board::is_valid() {
25 bool seen
[BOARD_SIZE
];
26 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
30 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
31 if (board
[i
] < 0 || board
[i
] >= BOARD_SIZE
|| seen
[board
[i
]]) {
34 seen
[board
[i
]] = true;
37 // Redundant because pigeon-hole-principle, but check anyway
38 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
47 std::istream
& operator>>(std::istream
& is
, Board
& board
) {
48 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
50 is
.setstate(std::istream::failbit
);
53 if (i
> 0 && is
.get() != ',') {
54 is
.setstate(std::istream::failbit
);
59 board
.board
[i
] = numeric
;
61 if (!board
.is_valid()) {
62 is
.setstate(std::istream::failbit
);