This is a program that generates random mazes and solves it for you!
Clone this repository and open main.exe
. This should execute without any problem on most machines. If there is any problem, you need to build the source (main.c
) on your own. [See the instructions for building ]
Clone this repository and open make.bat
. This will build your project.
If you prefer an IDE like Visual Studio
or Code::Blocks
then you need to link to libgdi32
.
For Code::Blocks
do the following-
(!) Create a new empty project.
(!) Create a new file with .c
extension
(!) Copy everything from my main.c
to your file
(!) Go to Project
->Build Options
->Linker Settings
-> Add
(See the above image)
(!) When the prompt appears type gdi32
and then confirm with Ok
(See the above image)
Now the project should build just fine
I have used recursive backtracking to generate the maze (see the recursive implementation
of Maze Generation)
And to solve the maze this program runs a Depth first search
The rendering is done with the Win32 API
(1) How to see the solution?
When a maze is generated press SPACE
and this should generate a solution. After that you can press SPACE
again and a new random maze will be generated for you.
(2) I want a bigger / smaller maze!
You need to change the source file and build your project again. [See the instructions for building ]
There are two lines you need to change. Go to the CONSTANTS
section of main.c
. You will see two define statements defining col
and row
. This two constants represent number of columns and rows. Change them to your liking. [It is recommended that you set them to the same value. eg. #define col 30
and #define row 30
]
(3) When I press SPACE
the program crashes
This can happen if you have changed the column and rows to some odd number. This program assumes that the destinition of the maze is the [row-2][col-2]
. In your case this cell is a wall. You can fix this by setting the column and rows (See the above FAQ) to some even number or change the destinion cell from the solveMaze
function. [You can always create an issue in this repository]
(4) I want bigger/smaller screen resolution
You need to alter the source code and build your project again.[See the instructions for building ]
There are two lines you need to change. Go to the CONSTANTS
section of main.c
. You will see two define statements defining WIDTH
and HEIGHT
. This two constants represent the screen resolution. Change them to your liking. [It is recommended to make them integer multiple of col
and row
]
(5) I dont see the entire maze when I run the program
This is because the title bar and (/or) the border of the window is taking more space than I expected. You need to change the padding of the height and (/or) the width of the screen.
In the CONSTANTS
section of the code you will find WIDTH_Padding
and HEIGHT_Padding
. Change them to your liking.