]> git.scottworley.com Git - slidingtile/blobdiff - sliding_tile_lib.cc
Don't constrain the hole.
[slidingtile] / sliding_tile_lib.cc
index 9f6bfc9ff62dffa6b776a74350ed1ad110384d65..9ac0217c4a305247ccb5f3de5664546a48e61dfb 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <iostream>
 
+int Step::count = 0;
 signed char Step::adjacent[BOARD_SIZE][5] = {
   1,   4,   -1,  -1,  -1,
   0,   2,   5,   -1,  -1,
@@ -132,13 +133,21 @@ 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;
 }
 
-Step::Step(Board board, std::shared_ptr<Step> prev) : board(board), prev(prev) {}
+Step::Step(Board board, std::shared_ptr<Step> prev) : board(board), prev(prev) {
+  count++;
+}
+
+Step::~Step() {
+  count--;
+}
 
 std::vector<std::shared_ptr<Step>> Step::successors(std::shared_ptr<Step> shared_this) const {
   std::vector<std::shared_ptr<Step>> suc;
@@ -215,7 +224,8 @@ std::shared_ptr<Step> find_path(const Board& start, const Board& goal) {
         seen.emplace(s->board);
         todo.push(s);
         if (seen.size() % 10000 == 0) {
-          std::cerr << "Examined " << seen.size() << " boards.  " << todo.size()
+          std::cerr << "Examined " << seen.size() << " boards.  Tracking "
+                    << Step::count << " steps.  " << todo.size()
                     << " waiting.  Considering paths of length "
                     << todo.top()->cost(invgoal) << std::endl;
         }