Question: Needed in c++ using for, while, or do-while loops, and if/switch statements The algorithm you are going to create will generate an maze based on

Needed in c++ using for, while, or do-while loops, and if/switch statements

The algorithm you are going to create will generate an maze based on a couple input parameters which will be read from the console.

A maze consists of a set of cells each of which can have up to four walls (though, ultimately, at most a cell will have is three). To create a maze, start by assuming all walls are in place and then, going left-to-right and up-to-down, for each cell randomly choose to remove the south or the west wall. Some cells the choice is predetermined; e.g., the cells along the west side of the maze all have south exits since the west wall is fixed.

For example, we might start with the following

+-+-+-+ | | | | +-+-+-+ | | | | +-+-+-+ | | | | +-+-+-+ 

The first cell cannot have an exit to the west so we remove the south exit.

+-+-+-+ | | | | + +-+-+ | | | | +-+-+-+ | | | | +-+-+-+ 

In the next cell we randomly choose the west or south exit. Suppose it's west. We now have

+-+-+-+ | | | + +-+-+ | | | | +-+-+-+ | | | | +-+-+-+ 

Next, we might remove the south wall. So,

+-+-+-+ | | | + +-+ + | | | | +-+-+-+ | | | | +-+-+-+ 

If we keep going, we might get something that looks like

+-+-+-+ | | | + +-+ + | | | + + +-+ | | +-+-+-+ 

In the end, there will always be a corridor along the west and south walls. This type of maze has the property that every cell can be reached from every other cell along a single path. I recommend trying this on a piece of graph paper using a coin to decide which exit to include. This might make it easier to conceptualize.

APP DETAILS

You may assume that the maze if 5x5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!