博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python迷宫起点终点所有路径_通向终点的路不止一条!python迷宫。
阅读量:5253 次
发布时间:2019-06-14

本文共 3047 字,大约阅读时间需要 10 分钟。

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

本帖最后由 wei_Y 于 2014-11-24 19:53 编辑

2008121223547917.jpg (56.62 KB, 下载次数: 3)

2014-11-17 19:22 上传

20080925104600202.gif其实木有上面那么高端啦。。只是数字版。。

规则:

迷宫没有墙壁,但是每条边的路被坑包围。如果一个玩家掉在坑里的话,他们就丢失了。迷宫是用矩阵来表示(含有列表的列表): 1是坑,0的路径的一部分。 迷宫的大小是12×12,外界都是坑。玩家在点(1,1)开始。出口是在点(10,10)。 你需要找到通过迷宫的路径。 玩家只能通过四个方向移动 南(下 [1,0]),北(上 [-1,0]), 东(右[0,1]),西(左[0,-1])。这条路线被描述成由不同的字符组成的字符串:“S”=南,“N”=北,“E”=东,和“W”=西。复制代码

迷宫:

One:

360截图20141117195541691.jpg (12.09 KB, 下载次数: 0)

2014-11-17 19:55 上传

[[1,1,1,1,1,1,1,1,1,1,1,1],

[1,0,0,0,0,0,0,0,0,0,0,1],

[1,0,1,1,1,1,1,1,0,1,1,1],

[1,0,1,0,0,0,0,0,0,0,0,1],

[1,0,1,0,1,1,1,1,1,1,0,1],

[1,0,1,0,1,0,0,0,0,0,0,1],

[1,0,0,0,1,1,0,1,1,1,0,1],

[1,0,1,0,0,0,0,1,0,1,1,1],

[1,0,1,1,0,1,0,0,0,0,0,1],

[1,0,1,0,0,1,1,1,1,1,0,1],

[1,0,0,0,1,1,0,0,0,0,0,1],

[1,1,1,1,1,1,1,1,1,1,1,1],

]

Two:

360截图20141117195840922.jpg (11.23 KB, 下载次数: 0)

2014-11-17 19:58 上传

[

[1,1,1,1,1,1,1,1,1,1,1,1],

[1,0,1,0,0,0,1,0,0,0,0,1],

[1,0,1,0,1,0,1,0,1,1,0,1],

[1,0,1,0,1,0,1,0,1,0,0,1],

[1,0,1,0,1,0,1,0,1,0,1,1],

[1,0,1,0,1,0,1,0,1,0,0,1],

[1,0,1,0,1,0,1,0,1,1,0,1],

[1,0,1,0,1,0,1,0,1,0,0,1],

[1,0,1,0,1,0,1,0,1,0,1,1],

[1,0,1,0,1,0,1,0,1,0,0,1],

[1,0,0,0,1,0,0,0,1,1,0,1],

[1,1,1,1,1,1,1,1,1,1,1,1],

]

three:

360截图20141117200007714.jpg (12.67 KB, 下载次数: 0)

2014-11-17 20:00 上传

[

[1,1,1,1,1,1,1,1,1,1,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,0,1],

[1,1,1,1,1,1,1,1,1,1,1,1],

]

Four:

360截图20141117200155873.jpg (11.79 KB, 下载次数: 0)

2014-11-17 20:02 上传

[

[1,1,1,1,1,1,1,1,1,1,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,0,1],

[1,1,1,1,1,1,1,1,1,1,1,1],

]

Five:

360截图20141117200440791.jpg (13.82 KB, 下载次数: 0)

2014-11-17 20:05 上传

[

[1,1,1,1,1,1,1,1,1,1,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,1,1],

[1,0,0,0,1,0,0,0,1,0,0,1],

[1,0,1,0,0,0,1,0,0,0,0,1],

[1,1,1,1,1,1,1,1,1,1,1,1],

]

测试代码:

def check_route(func, labyrinth):

MOVE = {"S": (1, 0), "N": (-1, 0), "W": (0, -1), "E": (0, 1)}

#copy maze

route = func([row[:] for row in labyrinth])

pos = (1, 1)

goal = (10, 10)

for i, d in enumerate(route):

move = MOVE.get(d, None)

if not move:

print("Wrong symbol in route")

return False

pos = pos[0] + move[0], pos[1] + move[1]

if pos == goal:

return True

if labyrinth[pos[0]][pos[1]] == 1:

print("Player in the pit")

return False

print("Player did not reach exit")

return False复制代码

带上写的函数和迷宫列表:

360截图20141117200620783.jpg (14.2 KB, 下载次数: 0)

2014-11-17 20:06 上传

嘻嘻,能不能写粗来呢,各位试试吧。

我写的太菜了不贴上来丢人了。

cf8f84d26594a938903de7c710d691c5.gif

大神写的:

游客,如果您要查看本帖隐藏内容请回复

转载地址:http://mreav.baihongyu.com/

你可能感兴趣的文章
IOC容器
查看>>
Windows 2003全面优化
查看>>
URAL 1002 Phone Numbers(KMP+最短路orDP)
查看>>
web_day4_css_宽度
查看>>
electron入门心得
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
Spring3.0 AOP 具体解释
查看>>
我的Hook学习笔记
查看>>
EasyUI DataGrid 中字段 formatter 格式化不起作用
查看>>
海量数据存储
查看>>
js中的try/catch
查看>>
[导入]玫瑰丝巾!
查看>>
自动从网站上面下载文件 .NET把网站图片保存到本地
查看>>
【识记】 域名备案
查看>>
STL uva 11991
查看>>
MY SQL的下载和安装
查看>>
自定义OffMeshLink跳跃曲线
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
学习Redux之分析Redux核心代码分析
查看>>