我被分配了在Java中创建迷宫求解器的任务。 这是作业:
Write an application that finds a path through a maze.
The maze should be read from a file. A sample maze is shown below.
O O O O O X O
X X O X O O X
O X O O X X X
X X X O O X O
X X X X O O X
O O O O O O O
X X O X X X O
字符“X”表示墙或阻挡位置,字符“O”表示打开位置。 您可以假设迷宫的入口始终位于右下角,出口始终位于左上角。 您的程序应将其输出发送到文件。 如果找到路径,则输出文件应包含路径。 如果未找到路径,则应将消息发送到该文件。 请注意,迷宫可能有多个解决方案路径,但在本练习中,您只需要找到一个解决方案,而不是所有解决方案。
您的程序应该使用堆栈来记录它正在探索的路径,并在它到达阻塞位置时回溯。
在编写代码之前,请务必编写完整的算法。 随意创建任何其他类,以帮助您完成任务。
Here's my Algorithm:
1)Initialize array list to hold maze
2)Read text file holding maze in format
o x x x x o
o o x o x x
o o o o o x
x x x x o o
3)Create variables to hold numbers of columns and rows
3)While text file has next line
A. Read next line
B. Tokenize line
C. Create a temporary ArrayList
D. While there are tokens
i. Get token
ii. create a Point
iii. add point to temp ArrayList
iv. increment maximum number of columns
E. Add temp to maze arraylist, increment max rows
F. initialize a hold of points as max rows - 1
G. Create a start point with x values as maximum number of rows - 1, and y values as maximum number of columns - 1
H. Create stack of points and push starting location
I. While f