]> git.scottworley.com Git - slidingtile/commitdiff
Don't constrain the hole.
authorScott Worley <scottworley@scottworley.com>
Sun, 10 Jan 2016 06:00:10 +0000 (22:00 -0800)
committerScott Worley <scottworley@scottworley.com>
Sun, 10 Jan 2016 06:00:10 +0000 (22:00 -0800)
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;
 }