Implementing the Binary Tree Algorithm
Explore how to implement the Binary Tree algorithm for maze generation by iterating over grid cells to carve passages toward the north or east. Learn to link cells randomly and set up code that integrates maze creation and visualization.
We'll cover the following...
We'll cover the following...
Implementing the Binary Tree algorithm on the Grid
Let’s start with the Binary Tree algorithm. It works simply by visiting each cell in the grid and choosing to carve a passage either toward the north or east.
The following code does just that. We’re going to put it in its own class so that we can easily reuse this code whenever we want. We've saved it to a file named binary_tree.rb, and made sure it’s in the same directory as the cell.rb ...