码迷,mamicode.com
首页 > 编程语言 > 详细

Hunt the wumpus 《Python代码》

时间:2014-10-10 15:18:43      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   使用   ar   strong   

 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_location
16     if (player_location == wumpus_location - 1 or
17         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>

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

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

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

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

     加油!To be a pythoner.

Hunt the wumpus 《Python代码》

标签:style   blog   http   color   io   os   使用   ar   strong   

原文地址:http://www.cnblogs.com/kgddx/p/4015758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!