]>
git.scottworley.com Git - slidingtile/blob - sliding_tile_lib.cc
1 #include "sliding_tile_lib.h"
7 signed char adjacent
[BOARD_SIZE
][5] = {
26 bool Board::is_valid() const {
27 bool seen
[BOARD_SIZE
];
28 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
32 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
33 if (board
[i
] < 0 || board
[i
] >= BOARD_SIZE
|| seen
[board
[i
]]) {
36 seen
[board
[i
]] = true;
39 // Redundant because pigeon-hole-principle, but check anyway
40 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
49 std::istream
& operator>>(std::istream
& is
, Board
& board
) {
50 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
52 is
.setstate(std::istream::failbit
);
55 if (i
> 0 && is
.get() != ',') {
56 is
.setstate(std::istream::failbit
);
61 board
.board
[i
] = numeric
;
63 if (!board
.is_valid()) {
64 is
.setstate(std::istream::failbit
);
69 std::ostream
& operator<<(std::ostream
& os
, const Board
& board
) {
70 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
74 os
<< int(board
.board
[i
]);
79 signed char Board::hole() const {
80 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
85 throw std::runtime_error("Board with no hole");