#include <iostream>
+int Step::count = 0;
signed char Step::adjacent[BOARD_SIZE][5] = {
1, 4, -1, -1, -1,
0, 2, 5, -1, -1,
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;
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;
}