作业帮 > 综合 > 作业

一道关于C++,解决迷宫的题目,希望能提供详细的解释,我将所有分都压上了,

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/03 00:16:54
一道关于C++,解决迷宫的题目,希望能提供详细的解释,我将所有分都压上了,
(Maze Traversal) The grid of hashes (#) and dots (.) in Fig.1 is a two-dimensional array representation of a maze.In the two-dimensional array,the hashes represent the walls of the maze and the dots represent squares in the possible paths through the maze.Moves can be made only to a location in the array that contains a dot.
# # # # # # # # # # # #
# ...# ......#
..# .# .# # # # .#
# # # .# ....# .#
# ....# # # .# ..
# # # # .# .# .# .#
# ..# .# .# .# .#
# # .# .# .# .# .#
# ........# .#
# # # # # # .# # # .#
# ......# ...#
# # # # # # # # # # # #
Fig.1 Two-dimensional array representation of a maze.
There is a simple algorithm for walking through a maze that guarantees finding the exit (assuming that there is an exit).If there is not an exit,you will arrive at the starting location again.Place your right hand on the wall to your right and begin walking forward.Never remove your hand from the wall.If the maze turns to the right,you follow the wall to the right.As long as you do not remove your hand from the wall,eventually you will arrive at the exit of the maze.There may be a shorter path than the one you have taken,but you are guaranteed to get out of the maze if you follow the algorithm.
Write recursive function mazeTraverse to walk through the maze.The function should receive arguments that include a 12-by-12 character array representing the maze and the starting location of the maze.As mazeTraverse attempts to locate the exit from the maze,it should place the character X in each square in the path.The function should display the maze after each move,so the user can watch as the maze is solved.
(Generating Mazes Randomly) Write a function mazeGenerator that takes as an argument a two-dimensional 12-by-12 character array and randomly produces a maze.The function should also provide the starting and ending locations of the maze.Try your function mazeTraverse from Exercise 1,using several randomly generated mazes.
(Mazes of Any Size) Generalize functions mazeTraverse and mazeGenerator of Exercise 1 and Exercise 2 to process mazes of any width and height.
一共三个问题,时间不多了,加急,希望大虾们帮帮忙
1.定义一个二维数组(MxN)表示一个迷宫,数组的元素为“#”或“.“#”表示迷宫里的墙,“.”表示可以通行的过道。从入口进入迷宫后,只能沿着“.”所代表的位置移动。定义一个递归函数mazeTraverse,用于实现走迷宫。该函数的形参应该包括表示迷宫的二维数组和迷宫的入口。函数中用字符‘X’表示已走过的路径,并输出每向前移动一步后迷宫的状态。
走迷宫的一个简单算法总能走到出口(如果有),如果没有出口,则会回到起始点。算法具体表述如下:将右手放在右边的墙上并开始前进,手不离墙,最终总能走到出口。当然,可能还有更短的路径,但上述路径总能走到出口。)
2.定义一个函数 mazeGenerator,用于生成任意大小的迷宫(即数组的宽度和高度由用户输入),要求生成的迷宫至少有一个不同于入口的出口。
一道关于C++,解决迷宫的题目,希望能提供详细的解释,我将所有分都压上了,
用栈