From: Scott Worley Date: Sun, 10 Jan 2016 05:59:30 +0000 (-0800) Subject: Keep a count of live Steps X-Git-Url: http://git.scottworley.com/slidingtile/commitdiff_plain/1955dd8bceb1bd5beef449ff1ac04c35c2714f31 Keep a count of live Steps --- 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);