summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-04-22 14:57:31 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-04-22 14:57:31 +0200
commitba3c0382264fd6844fee3b1ea26c47c9d5332b82 (patch)
tree89928fde638fdb937a5e72212e4bf9e6f4920460
parentcff0b04e9092613ee24a6a291ba42c086b65c7c8 (diff)
Add fancy debug to maze_solver
-rw-r--r--maze_solver.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/maze_solver.rb b/maze_solver.rb
index d529495..e5fd87e 100644
--- a/maze_solver.rb
+++ b/maze_solver.rb
@@ -14,8 +14,27 @@ class MazeSolver
end
def solve!()
+ if ENV["DEBUG"] == "visual"
+ print "\e[?1049h" # Save the state of the terminal
+ print "\e[2J" # Clear the screen
+ print "\e[0;0H" # Move the cursor to 0, 0
+ print "\n [ \e[1;35mSolving maze...\e[0m ]\n\n" # Print some nice graphics
+ print "\e[s" # Save the cursor position
+ end
+
while @stack.last != @end_pos
step()
+
+ if ENV["DEBUG"] == "visual"
+ print "\e[u" # Restore the cursor position
+ print @maze.to_s(" ", @stack)
+ print "\n\n"
+ puts " Stack size: #{@stack.length}"
+ end
+ end
+
+ if ENV["DEBUG"] == "visual"
+ print "\e[?1049l" # Restore the state of the terminal
end
end
@@ -29,9 +48,11 @@ class MazeSolver
if neighbors.empty?
@stack.pop()
+ puts "Popping to #{stack.last}" if ENV["DEBUG"] == "log"
else
randomNeighbor = neighbors.sample
@stack.push(randomNeighbor)
+ puts "Pushing to #{stack.last}" if ENV["DEBUG"] == "log"
@visitedTiles[randomNeighbor.x][randomNeighbor.y] = true
end
end