hunt the wumpus游戏用python 编译编译不能运行,哪里有错误

1 from random import choice
3 cave_numbers = range(1,21)
4 wumpus_location = choice(cave_numbers)
5 player_location = choice(cave_numbers)
6 while player_location == wumpus_location:
player_location = choice(cave_numbers)
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"
14 while 1:
print "You are in cave", player_location
if (player_location == wumpus_location - 1 or
player_location == wumpus_location + 1):
print "I smell a wumpus!"
print "Which cave next?"
player_input = raw_input("&")
if (not player_input.isdigit() or
int(player_input) not in cave_numbers):
print player_input, "is not a cave that I can see!"
player_location = int(player_input)
if player_location == wumpus_location:
print "Aargh! You got eaten by a wumpus!"
&From wikipedia&
&&&& Hunt&the&Wumpus是一个很重要的早期。他是基于一个简单的隐藏/搜索的形式,有一个神秘的怪兽(Wumpus),潜行在房间的网络中。玩家可以使用基于的文字界面,通过输入指令来在房间中移动,或者沿着几个相邻的房间中的弯曲的路径射箭。其中有20个房间,每个房间与另外三个相连接,排列像一个的顶点(或者是一个的面)。可能的危险有:,超级蝙蝠(它会把玩家扔到任意的位置)和Wumpus。当玩家从提示中推断出Wumpus所在的房间而不进入,并向房间内射入一支箭来杀死他。然而,如果射错了房间就会惊动Wumpus,他就会吞噬玩家。
游戏最初由使用编写。
该游戏的一个简化版也变成了一个领域中的描述(一种计算机程序)概念的经典例子。(人工智能常用来模拟玩家的角色)
&&&& 今天学的第一个小游戏代码,你看到里面的小错误了么?
&&&& 加油!To be a pythoner.
阅读(...) 评论()用Python编写IOS工程的自动编译脚本
折腾了一周,终于用语言写好了项目工程的自动编译脚本,虽然最终脚本只有200多行代码,但中间遇到的一些问题还是折磨了我一番, 好了, 现在把过程记录下来, 以便加深自己的印象, 也可供需要的人参考.
我写这个脚本是要做到下面几个目标:
1.每次编译都从服务器更新最新代码;
2.每次编译要自动修改info.plist里的
3.每次编译都要编译出debug版和可供发布的distribution版, debug供测试人员使用, 测试通过后直接使用对应的distribution版本提交到App S
4.编译出的包上传到服务器, 并通过邮件通知相关人员, 邮件内容是安装包的地址, 如果编译失败, 邮件内容是失败信息.
二. 开发环境
我是在Mac下用Python开发的, 其实直接用shell脚本也行, 我是为了操作一些文件更方便, 编辑器用的Sublime text 2.
三. 前提条件
开发证书和发布证书请先安装好, 工程配置里添加Distribution项(复制Release), 并配置好对应的发布证书.
四. check out工程代码.
代码管理我用的是svn, 下载代码其实就是用Python执行shell命令, 代码如下:
def svnCheckout(self):
print "svn checkout start"
os.system('rm -frd %s'%codeDir)
os.system('mkdir %s'%codeDir)
os.system('svn checkout %s --username %s --password %s --non-interactive %s'\
%(svnPath,svnUserName,svnPassword,codeDir))
if os.path.exists('%s/YourProject'%codeDir) == False:
msg = 'checkout code failed'
self.buildSucceed = False
self.buildErrorDescription.append(msg)
return False
os.chdir(LifeSearchBuild.codeDir)
return True
需要导入os模块, os.system()方法是执行shell命令的, 代码中, codeDir变量是check out代码后存放的本地目录, buildErrorDescription是我定义的一个列表, 用来记录错误的信息的, 供后面发送邮件使用(编译失败时).
五. 修改bundle version
其实这一步是为了Distribution版, 因为提交到App Store的包, bundle version必须是递增的一个数, bundle version在工程的info.plist文件里, 操作plist, 可以直接用Mac自带的PlistBuddy, 代码如下:
def modifyBundleVersion(self,newBundleVersion):
os.system('/usr/libexec/PlistBuddy -c "Set:CFBundleVersion %s" %s'%(newBundleVersion,infoPlistFilePath))
其中infoPlistFilePath是你check out代码后工程里info.plist文件的路径. newBundleVersion需要你自己定义一个规则, 保证和上次编译的包的version是递增的就行, 编译完成后也需要持久化到本地, 以便下次做递增计算.
六. 编译工程
有了代码后, 就开始用xcodebuild命令来编译工程, 编译debug版的代码如下:
def build_debug(self):
print "build debug start"
os.system('rm -frd build')
os.system('xcodebuild clean -configuration Debug')
os.system('xcodebuild -configuration Debug')
if os.path.exists('build/Debug-iphoneos/YourProject.app'):
debugIpaName = 'debug_%s_%s.ipa'%(currAppVersion,self.buildVersion)
os.system('mkdir Payload')
os.system('cp -r ./build/Debug-iphoneos/YourProject.app ./Payload/')
os.system('zip -r %s Payload'%debugIpaName)
os.system('rm -frd build')
os.system('rm -frd Payload')
self.ipaNameList.append(debugIpaName)
self.buildSucceed = False
self.buildErrorDescription.append('build debug ipa failed')
说明:app生成后需要放进一个Payload文件夹, 然后压缩成zip, 然后改后缀为ipa, Distribution的不用, 发布时直接用zip包提交.
代码中ipaNameList是我定义的一个列表, 用来保存编好的包名字的, 以便后续上传服务器时使用.
七. 上传到服务器
我用到了ftp命令, 代码如下:
def uploadToFTP(self):
if len(self.ipaNameList) == 0:
self.buildSucceed = False
print "no ipas to upload"
os.system('''
ftp -niv %s << EOF
user %s %s
mkdir %s/%s
EOF'''%(ftpAddress,
ftpUserName,
ftpPassword,
currAppVersion,
self.buildVersion,
currAppVersion,
self.buildVersion,
' '.join(self.ipaNameList)))
其实大家不用细看这段代码, 这是我项目里直接拷贝过来的, 只要大家能用ftp命令上传到自己的服务器就行了.
八. 邮件通知
发邮件用到了smtplib, 我的邮件内容需是html&#26684;式的, 我就不直接拷贝我项目里的代码了, 写个例子代码如下:
smtp = smtplib.SMTP('')
smtp.login(emailSenderUserName, emailSenderPassword)
msg = MIMEMultipart()
msg['To'] = ";".join(emailAddressList)
msg['From'] = emailSender
msg['Subject']= "test mail"
text = "build successful"
body = MIMEText("%s"%text,_subtype='html',_charset='utf-8')
msg.attach(body)
smtp.sendmail(msg['From'], emailAddressList, msg.as_string())
smtp.quit()
九. dailybuild
编译脚本弄好后, 可以手动运行编译, 也可以添加计划任务来每日定时编译, 这就用到了crontab, 如果你想每天早上8点运行自动编译脚本, 则编辑crontab如下:
0 8 * * * python build.py >buildLog.txt
buildLog.txt文件用来记录日志.
注意!!用crontab的时候, 证书的问题折磨了我整整一天, 因为在crontab, 证书无法读取到, 导致签名失败, 上网查了大量的文章, 好像跟crontab无法读取到用户化境变量有关, 不过, 最终我的解决办法倒是很简单, 就是打开钥匙串, 把证书从"登录"里拷贝到""里就可以了.
ok, 完了, 希望对大家有帮助.
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'SublimeText 2编译python出错的解决方法(The system cannot find the file specified)
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了SublimeText 2编译python报The system cannot find the file specified错误的解决方法,大家参考使用吧
[Error 2] The system cannot find the file specified
解决方法:1.环境变量path添加:C:\Python32\Tools\SD:\Python32;D:\Program Files\Sublime Text2;2.Python.sublime-build内容修改原内容:
代码如下:{&&&& "cmd": ["python", "-u", "$file"],&&&& "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",&&&& "selector": "source.python"&}
修改为(路径为安装文件夹):
代码如下:{&"cmd": ["C:/Python26/python.exe", "-u", "$file"],&"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",&"selector": "source.python"}
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 wumpus 的文章

 

随机推荐