]> git.scottworley.com Git - slidingtile/blobdiff - sliding_tile_lib.cc
Don't constrain the hole.
[slidingtile] / sliding_tile_lib.cc
index 51aeded95e8ded018c2bff508c9d62daa3ac0fad..9ac0217c4a305247ccb5f3de5664546a48e61dfb 100644 (file)
@@ -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;
 }