Displaying a Maze on the Console
Learn the code in Ruby to display a maze on the terminal.
We'll cover the following
Introducing ASCII art
ASCII art is not necessarily the fanciest way, nor the prettiest, but it is often the most convenient way to display our mazes. We nearly always have easy access to a terminal, and we don’t need to worry about bringing out any external libraries or APIs. In short, it’s perfect for what we need just now. Let’s walk through one possible way to approach drawing our mazes using only four different characters: space (“ ”) for cells and passages, pipe (“|”) for vertical walls, hyphen (“-”) for horizontal walls, and plus (“+”) to draw corners. An example of a small maze drawn using these characters is given below:
Get hands-on with 1400+ tech skills courses.