int Board::distance(const InvertedBoard& invo) const {
int dist = 0;
for (int i = 0; i < BOARD_SIZE; i++) {
- dist += std::abs(i % BOARD_DIM - invo.pos[board[i]] % BOARD_DIM) +
- std::abs(i / BOARD_DIM - invo.pos[board[i]] / BOARD_DIM);
+ if (board[i] != 0) {
+ dist += std::abs(i % BOARD_DIM - invo.pos[board[i]] % BOARD_DIM) +
+ std::abs(i / BOARD_DIM - invo.pos[board[i]] / BOARD_DIM);
+ }
}
return dist;
}