Hunt the wumpus 《Python代码》,, 1 from ra
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
<From wikipedia>
HunttheWumpus是一个很重要的早期电脑游戏。他是基于一个简单的隐藏/搜索的形式,有一个神秘的怪兽(Wumpus),潜行在房间的网络中。玩家可以使用基于命令行的文字界面,通过输入指令来在房间中移动,或者沿着几个相邻的房间中的弯曲的路径射箭。其中有20个房间,每个房间与另外三个相连接,排列像一个dodecahedron的顶点(或者是一个icosahedron的面)。可能的危险有:,超级蝙蝠(它会把玩家扔到任意的位置)和Wumpus。当玩家从提示中推断出Wumpus所在的房间而不进入,并向房间内射入一支箭来杀死他。然而,如果射错了房间就会惊动Wumpus,他就会吞噬玩家。
游戏最初由Gregory Yob使用BASIC编写。
该游戏的一个简化版也变成了一个人工智能领域中的描述(一种计算机程序)概念的经典例子。(人工智能常用来模拟玩家的角色)
今天学的第一个小游戏代码,你看到里面的小错误了么?
加油!To be a pythoner.
Hunt the wumpus 《Python代码》
相关内容
- 【人生苦短,我学Python】个人学习笔记——设置pip和
- Python核心编程(第二版) 第五章习题答案,python第五章
- Python科学计算》(张若愚)PDF版,,链接:https:/
- 【python+selenium自动化】使用pytest+allure2完成自动化测试
- python3----练习题(爬取电影天堂资源),, 1 import
- cygwin使用Windows下的python,,在cygwin下使用
- pyenv和virtualenv管理python的版本(多个版本同时用),
- 用python + hadoop streaming 编写分布式程序(三) -- 自定义
- python3.7安装Scrapy,,环境:windows
- python webdriver 测试框架-数据驱动DDT的例子,webdriverddt
评论关闭