From 1955dd8bceb1bd5beef449ff1ac04c35c2714f31 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Sat, 9 Jan 2016 21:59:30 -0800 Subject: [PATCH] Keep a count of live Steps --- sliding_tile_lib.cc | 12 ++++++++++-- sliding_tile_lib.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index 9f6bfc9..51aeded 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -12,6 +12,7 @@ #include +int Step::count = 0; signed char Step::adjacent[BOARD_SIZE][5] = { 1, 4, -1, -1, -1, 0, 2, 5, -1, -1, @@ -138,7 +139,13 @@ int Board::distance(const InvertedBoard& invo) const { return dist; } -Step::Step(Board board, std::shared_ptr prev) : board(board), prev(prev) {} +Step::Step(Board board, std::shared_ptr prev) : board(board), prev(prev) { + count++; +} + +Step::~Step() { + count--; +} std::vector> Step::successors(std::shared_ptr shared_this) const { std::vector> suc; @@ -215,7 +222,8 @@ std::shared_ptr 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; } diff --git a/sliding_tile_lib.h b/sliding_tile_lib.h index de2ca1f..11d9de3 100644 --- a/sliding_tile_lib.h +++ b/sliding_tile_lib.h @@ -30,6 +30,7 @@ std::ostream& operator<<(std::ostream& os, const Board& board); struct Step { Step(Board board, std::shared_ptr prev); + ~Step(); Board board; std::shared_ptr prev; @@ -39,6 +40,7 @@ struct Step { int cost(const InvertedBoard& invgoal) const; static signed char adjacent[BOARD_SIZE][5]; + static int count; }; std::ostream& operator<<(std::ostream& os, const Step& step); -- 2.44.1