java迷宫算法栈_java - 用Java创建迷宫求解算法 - 堆栈内存溢出

我被分配了在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值