Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

How is the environment of your inner world?

Answered: 1 week ago