Hi,

I have to create a maze in C++.

// Below is the problem Statement

Let's use a simple case of a w=4 (columns) by h=3 (rows) maze to illustrate the maze-generation algorithm.

We will start with 4 × 3 = 12 closed rooms, arranged in a 4 by 3 grid:

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

The rows are numbered 1 through h and the columns are numbered 1 through w.

Between adjoining rooms, there is either a removable vertical wall or a removable horizontal wall. There are a total of (w-1) × h removable vertical walls and w × (h-1) removable horizontal walls. Let's number these removable walls in sequencial order from top to bottom and from left to right within a row (i.e., row-major order). Some of the removable wall numbers are depicted below.

+-+-+-+-+
| 0 1 2 |
+3+4+5+6+
| 7 8 9 |
+-+-+-+-+
| | | | |
+-+-+-+-+

//Please Suggest how should I start creating the maze.How do I save the walls in the maze??

2
Contributors
1
3
Views
8 Years
Discussion Span
Last Post by Lerner

Always start with a plan on paper that you write out with pen/pencil. For example, in this case you might try something like this:

Determine mazeHeight
Determine mazeWidth
Use an array of type char to represent the removeable walls.
Using dynamic memory and the formulas you described declare the memory needed to store the information regarding the walls and assign each element a default value.
Determine which walls will be present and which will be absent (randomly remove or place a random number of removable walls.
Use the index of the array to access the walls
Declare a room class
Each room has 4 walls, some or all of which may be removable.
Determine which type of walls each cell has, where.
Declare a display function to show each cells walls.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.