This guide explains what the program will generate, how you should interact with it, and how to understand the maze grid that appears on your screen. You should read this before running and testing your DFS implementation.
When you run the program, it will:
- Ask you for maze dimensions
N M. - Generate a random N×M matrix filled with 0s and 1s.
- Randomly choose:
- S (the entrance)
- E (the exit)
- Print the entire maze to the screen.
- After you implement DFS, the program will either:
- Print the full path from S to E, if one exists
- Or print “No path exists.”
When the program starts, you will see:
Enter maze dimensions N M:
You must enter two integers, for example:
5 5
This creates a 5×5 maze.
You may choose any size you want, but smaller grids (5×5, 6×6, 8×8) are easier for debugging.
After you enter dimensions, the program prints something like:
Maze:
0 0 0 0 0
0 0 1 0 1
1 1 0 0 0
0 0 0 0 E
0 1 S 0 0
| Symbol | Meaning |
|---|---|
0 |
Open path, DFS can move here |
1 |
Wall, DFS cannot move here |
S |
Entrance (Start position for DFS) |
E |
Exit (Goal position) |
- Walls block DFS.
- DFS may move only up, right, down, or left.
- There is exactly one S and one E, always on the boundary.
Here is a small example where DFS can reach the exit:
Maze:
S 0 1
0 0 1
1 0 E
One valid path is:
(0,0) → (0,1) → (1,1) → (2,1) → (2,2)
Your DFS, if implemented correctly, will print something like:
Path from entrance to exit:
(0,0)
(0,1)
(1,1)
(2,1)
(2,2)
Here is a maze that cannot reach the exit:
Maze:
S 1 1
1 0 1
1 0 E
In this case:
- The entrance is blocked in by walls.
- DFS will explore open cells but never reach E.
Your output should be:
No path exists.
Once you complete your DFS and run the program, you will see:
- The maze printed.
- Debug messages (if you choose to add them).
- A final result:
Path from entrance to exit:
(r1, c1)
(r2, c2)
...
(exit_r, exit_c)
No path exists.
You now know:
- What to type as input
- What the maze symbols mean
- How to interpret the printed matrix
- What valid DFS output looks like
- What failure output looks like
Use this guide while writing and testing your DFS.