Counting Dead Ends
Explore how to identify and count dead ends in maze grids using the deadends method. Understand the differences in dead-end frequency between Hunt-and-Kill and Recursive Backtracker algorithms. Learn to automate multiple runs to analyze average dead ends and their impact on maze complexity and structure.
We'll cover the following...
We'll cover the following...
Introducing the deadends method
Let’s see how the frequency of dead ends compares between algorithms. We’ll add a method to our Grid class that collects all of the dead-end cells in the entire grid—those with links to only one other cell—and returns them as a list. Then, we can print the size of that list to tell us how many dead ends there are.
Let's modify grid.rb by adding the following code.