From: Scott Worley Date: Sun, 10 Jan 2016 06:00:10 +0000 (-0800) Subject: Don't constrain the hole. X-Git-Url: http://git.scottworley.com/slidingtile/commitdiff_plain/ab51c07a99c1927c95a123e6912925adba83714f?ds=sidebyside Don't constrain the hole. --- diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index 51aeded..9ac0217 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -133,8 +133,10 @@ int Board::distance(const Board& o) const { 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; }