本文共 3047 字,大约阅读时间需要 10 分钟。
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 wei_Y 于 2014-11-24 19:53 编辑
2008121223547917.jpg (56.62 KB, 下载次数: 3)
2014-11-17 19:22 上传
其实木有上面那么高端啦。。只是数字版。。
规则:
迷宫没有墙壁,但是每条边的路被坑包围。如果一个玩家掉在坑里的话,他们就丢失了。迷宫是用矩阵来表示(含有列表的列表): 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 上传
嘻嘻,能不能写粗来呢,各位试试吧。
我写的太菜了不贴上来丢人了。
大神写的:
游客,如果您要查看本帖隐藏内容请回复
转载地址:http://mreav.baihongyu.com/