Hunt the wumpus 《Python代码》,, 1 from ra


 1 from random import choice 2  3 cave_numbers = range(1,21) 4 wumpus_location = choice(cave_numbers) 5 player_location = choice(cave_numbers) 6 while player_location == wumpus_location: 7     player_location = choice(cave_numbers) 8  9 print "Welcome to Hunt the Wumpus!"10 print "You can see", len(caves), "caves"11 print "To play, just type the number"12 print "of the cave you wish to enter next"13 14 while 1:15     print "You are in cave", player_location16     if (player_location == wumpus_location - 1 or17         player_location == wumpus_location + 1):18         print "I smell a wumpus!"19 20     print "Which cave next?"21     player_input = raw_input(">")22     if (not player_input.isdigit() or 23         int(player_input) not in cave_numbers):24         print player_input, "is not a cave that I can see!"25 26     else:27         player_location = int(player_input)28         if player_location == wumpus_location:29             print "Aargh! You got eaten by a wumpus!"30             break

bubuko.com,布布扣

<From wikipedia>

HunttheWumpus是一个很重要的早期电脑游戏。他是基于一个简单的隐藏/搜索的形式,有一个神秘的怪兽(Wumpus),潜行在房间的网络中。玩家可以使用基于命令行的文字界面,通过输入指令来在房间中移动,或者沿着几个相邻的房间中的弯曲的路径射箭。其中有20个房间,每个房间与另外三个相连接,排列像一个dodecahedron的顶点(或者是一个icosahedron的面)。可能的危险有:,超级蝙蝠(它会把玩家扔到任意的位置)和Wumpus。当玩家从提示中推断出Wumpus所在的房间而不进入,并向房间内射入一支箭来杀死他。然而,如果射错了房间就会惊动Wumpus,他就会吞噬玩家。

游戏最初由Gregory Yob使用BASIC编写。

该游戏的一个简化版也变成了一个人工智能领域中的描述(一种计算机程序)概念的经典例子。(人工智能常用来模拟玩家的角色)

今天学的第一个小游戏代码,你看到里面的小错误了么?

加油!To be a pythoner.

Hunt the wumpus 《Python代码》

评论关闭