current position:Home>Maze game, maze initialization, specify the entrance or exit position, and print the maze.

Maze game, maze initialization, specify the entrance or exit position, and print the maze.

2022-02-02 23:02:00 CSDN Q & A

The phenomenon and background of the problem Randomly generate one 6x10 The size of the maze grid , And print... In the command line window . Practice requirements : As shown in the figure below , The square represents the wall , Blank means you can pass . A circle around the maze is a wall , The second on the left of the first line is the entrance , The penultimate in the last line is the exit , The first 25 That's ok 29 Listed as randomly generated .
Operation results and error reporting contents
My solution ideas and tried methods My thinking is limited to generating a two-dimensional array
What I want to achieve



Refer to the answer 1:

Randomly generated mazes ? Simply put, use depth first search . It's probably to assume that there are walls inside the maze , Only part of the grid is separated by the wall . All you have to do is use deep search to break through these walls to the end , You can use the stack to do backtracking ,dfs You can choose a direction at random , Then mark the way you've walked , Just don't repeat it , The end result is a maze . Of course , utilize dfs To solve the problem , Finally, the main path of the maze will be more obvious , It's easy to walk . More complex mazes can be understood Prim Algorithm




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022301585634.html

Random recommended