CodeCombat森林关卡Python代码
地牢关卡过完,接下来是边缘的森林!
1,森林保卫战
hero.moveUp()
hero.buildXY("fence", 40, 52)
hero.moveDown()
hero.moveDown()
hero.buildXY("fence", 40, 20)
2,羊肠小道
# It's the first point of the path.
hero.moveXY(36, 59)
# Move at the next points of the path.
hero.moveXY(37, 13)
# Build a fence to stop the ogre.
hero.moveXY(79,18)
hero.moveXY(73,61)
hero.moveXY(79,18)
3,丛林里的隔间
hero.moveXY(19, 33)
enemy = hero.findNearestEnemy()
# 条件判断式将会检查该变数是否参考到一个ogre
if enemy:
hero.attack(enemy)
hero.attack(enemy) hero.moveXY(49, 51)
enemy = hero.findNearestEnemy()
if enemy:
# 在这里撰写攻击敌人指令
hero.attack(enemy)
hero.attack(enemy)
# pass没有特别的意思,只是用来协助结束条件判断式,写不写都可以
pass hero.moveXY(58, 14)
enemy = hero.findNearestEnemy()
# 使用条件判断式来确认敌人是否存在
if enemy:
# 如果敌人存在就攻击他
hero.attack(enemy)
hero.attack(enemy)
4,if-stravaganza
while True:
enemy = hero.findNearestEnemy()
# 使用一个 “if” 语句去检查是否有敌人存在:
if enemy:
# 攻击敌人如果它存在的话
hero.attack(enemy)
hero.attack(enemy)
5,背靠背
while True:
enemy = hero.findNearestEnemy()
if enemy:
# 亦或主动出击...
hero.attack(enemy)
hero.attack(enemy)
else:
# 亦或回到你的阵地防守。
hero.say(" 我看不到敌人")
hero.moveXY(40, 34)
pass
6,森林劈裂者
hero.moveXY(23, 23)
while True:
enemy = hero.findNearestEnemy()
if hero.isReady("cleave"):
# “Cleave”掉敌人!
hero.cleave(enemy)
pass
else:
# 否则(如果“cleave”还没准备好),就用你的普通攻击
hero.attack(enemy)
pass
7,边远地区的对峙
while True:
# 使用 ‘isReady’ 中的一个 “if-statement” 的语句来检查 “cleave”
if hero.isReady("cleave"):
# 劈斩!
enemy = hero.findNearestEnemy()
hero.cleave(enemy)
# 或者,如果 cleave 还没准备好的话:
else:
# 说一点什么来吓走曼切堪食人魔
hero.say(" 快滚吧!刀剑无眼 ! ")
pass
8,测距仪
enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)
enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
# 将distance2变数作为参数,传入say()方法
hero.say(distance2)
# 测量并说出剩余敌人与英雄间的距离
# 不要向你的友军进行射击!
enemy3 = "Charles"
enemy4 = "Gorgnub"
distance4 = hero.distanceTo(enemy4)
hero.say(distance4)
9,保护农民
while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance < 10:
# 如果他们与农民太近,就攻击他们
hero.attack(enemy)
pass
# 否则的话,呆在农民旁边!
hero.moveXY(40, 37)
10,疯狂的食人魔
# 地上另一个让英雄打开的宝箱!
# 攻击宝箱以打开它
# 有些食人魔可不会呆呆地站着挨打!
# 当食人魔离你太近时,你得学着保护你自己
while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if hero.isReady("cleave"):
# 首先,定期使用旋风斩(cleave)当技能就绪的时候:
hero.cleave(enemy)
pass
elif distance < 5:
# 攻击靠近并离你最近的食人魔
hero.attack(enemy)
pass
else:
# 否则,试着打破宝箱看看:
hero.attack("Chest")
pass
11,跃火林中
# 在这关,别碰恶魔石!往其他方向移动避开它们!
while True:
evilstone = hero.findNearestItem()
if evilstone:
pos = evilstone.pos
if pos.x == 34:
# 如果恶魔石在左边,走到右边。
hero.moveXY(46, 22)
pass
else:
# 如果恶魔石在右边,走到左边。
hero.moveXY(34, 22)
pass
else:
# If there's no evilstone, go to the middle.
hero.moveXY(40, 22)
pass
12,Village Rover
# This defines a function called findAndAttackEnemy
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy) # This code is not part of the function.
while True:
# Now you can patrol the village using findAndAttackEnemy
hero.moveXY(35, 34)
findAndAttackEnemy() # Now move to the right entrance.
hero.moveXY(60, 31)
# Use findAndAttackEnemy
findAndAttackEnemy()
13,Backwoods Fork
# This function has a parameter.
# 参数是一种给函数传递信息的方式。
def checkAndAttack(target):
# The 'target' parameter is just a variable!
# 它包含了函数调用时的参数。
if target:
hero.attack(target)
hero.moveXY(43, 34) while True:
hero.moveXY(58, 52)
topEnemy = hero.findNearestEnemy()
checkAndAttack(topEnemy) # 移动到底部的X标记处。
hero.moveXY(58, 16)
# 创建名为 bottomEnemy 的变量,寻找最近敌人。
bottomEnemy = hero.findNearestEnemy()
# 使用 checkAndAttack 函数,并包括 bottomEnemy 变量。
checkAndAttack(bottomEnemy)
14,Leave it to Cleaver
# This shows how to define a function called cleaveWhenClose
# The function defines a parameter called target
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
hero.cleave(enemy)
# else, just attack target!
hero.attack(enemy) # This code is not part of the function.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)
15,友人和敌人
# 农民和士兵聚集在森林。
# 命令农民战斗,苦工远离! while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + friend.id + "!")
# 寻找最近的敌人,然后让他们滚蛋
enemy = hero.findNearestEnemy()
if enemy:
hero.say("Scram," + enemy.id + "!")
16,巫师之门
# Move to Laszlo and get his secret number.
hero.moveXY(30, 13)
las = hero.findNearestFriend().getSecret() # 向 Laszlo 的数字中加7就能得到 Erzsebet的号码
# Move to Erzsebet and say her magic number.
erz = las + 7
hero.moveXY(17, 26)
hero.say(erz) # 将 Erzsebet 的数字除以 4 得到 Simoyi 的数字。
# Go to Simonyi and tell him his number.
sim = erz / 4
hero.moveXY(30, 39)
hero.say(sim) # 将 Simonyi 的数字乘以 Laszlo 的数字得到 Agata 的数字。
# Go to Agata and tell her her number.
Aga = sim * las
hero.moveXY(43, 26)
hero.say(Aga)
17,金币屑
# 跟随硬币的轨迹来到红色 X 标记的出口 while True:
# 这能找到最近的敌人。
item = hero.findNearestItem()
if item:
# 这将物品的 pos,就是坐标,存储在变量中。
itemPosition = item.pos
# 将物品的 X 和 Y 坐标放进变量。
itemX = itemPosition.x
itemY = itemPosition.y
# Now, use moveXY to move to itemX and itemY:
hero.moveXY(itemX, itemY)
18,Blind Distance
# 你的任务是告诉他兽人的距离。 # 这个函数寻找最近的敌人,并返回距离。
# If there is no enemy, the function returns 0.
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 0
if enemy:
result = hero.distanceTo(enemy)
return result while True:
# Call nearestEnemyDistance() and
# save the result in the variable enemyDistance.
enemyDistance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if enemyDistance:
# Say the value of enemyDistance variable.
hero.say(enemyDistance)
可选关卡1:竞技场
# 在决斗中击败敌人的英雄!
while True:
# 在一个循环中找到并攻击敌人
# 当你完成的时候,提交到多人天梯系统中!
enemy = hero.findNearestEnemy()
hero.attack(enemy)
if len(hero.findNearestEnemy()) > 5:
hero.shield()
else:
hero.attack(enemy)
CodeCombat森林关卡Python代码的更多相关文章
- CodeCombat地牢关卡Python代码
最近迷上了玩CodeCombat,特将地牢关卡的Python代码整理如下,供有兴趣的人学习交流探讨 1,Kithgard地牢 hero.moveRight() hero.moveDown() hero ...
- codecombat之地牢关卡Python代码
1.地牢 # 向宝石进发. # 小心撞墙! # 在下面输入你的代码. self.moveRight() self.moveDown() self.moveRight() 2.深藏的宝石 # 利用你的移 ...
- 随机森林入门攻略(内含R、Python代码)
随机森林入门攻略(内含R.Python代码) 简介 近年来,随机森林模型在界内的关注度与受欢迎程度有着显著的提升,这多半归功于它可以快速地被应用到几乎任何的数据科学问题中去,从而使人们能够高效快捷地获 ...
- XGBoost参数调优完全指南(附Python代码)
XGBoost参数调优完全指南(附Python代码):http://www.2cto.com/kf/201607/528771.html https://www.zhihu.com/question/ ...
- 机器学习完整过程案例分布解析,python代码解析
所谓学习问题,是指观察由n个样本组成的集合,并依据这些数据来预測未知数据的性质. 学习任务(一个二分类问题): 区分一个普通的互联网检索Query是否具有某个垂直领域的意图.如果如今有一个O2O领域的 ...
- Python和多线程(multi-threading)。这是个好主意码?列举一些让Python代码以并行方式运行的方法。
Python并不支持真正意义上的多线程.Python中提供了多线程包,但是如果你想通过多线程提高代码的速度,使用多线程包并不是个好主意.Python中有一个被称为Global Interpreter ...
- python面试题之多线程好吗?列举一些让Python代码以并行方式运行的方法
答案 Python并不支持真正意义上的多线程.Python中提供了多线程包,但是如果你想通过多线程提高代码的速度,使用多线程包并不是个好主意.Python中有一个被称为Global Interpret ...
- 梯度下降法的python代码实现(多元线性回归)
梯度下降法的python代码实现(多元线性回归最小化损失函数) 1.梯度下降法主要用来最小化损失函数,是一种比较常用的最优化方法,其具体包含了以下两种不同的方式:批量梯度下降法(沿着梯度变化最快的方向 ...
- 可爱的豆子——使用Beans思想让Python代码更易维护
title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...
随机推荐
- 菜鸟学SSH(五)——Struts2上传文件
上传文件在一个系统当中是一个很常用的功能,也是一个比较重要的功能.今天我们就一起来学习一下Struts2如何上传文件. 今天讲的上传文件的方式有三种: 1,以字节为单位传输文件: 2,Struts2封 ...
- prometheus-dashboard-to-grafana
https://prometheus.io/docs/visualization/grafana/ https://www.digitalocean.com/community/tutorials/h ...
- PCA,SVD
PCA的数学原理 https://www.zhihu.com/question/34143886/answer/196294308 奇异值分解的揭秘(二):降维与奇异向量的意义 奇异值分解的揭秘(一) ...
- 关于angular的$resource中的isArray属性问题
在之前的文章中讲到了在使用$resource的时候,有一个isArray属性. 这个属性在两个地方有提到: 1. angular学习笔记(二十八)-$http(6)-使用ngResource模块构建R ...
- 每日英语:Got 5 Minutes? 'Flash Fiction' Catches On
Chinese author Lao Ma has a simple approach to his short stories: In the face of life, everything is ...
- linux centOS6 nexus 开启自动启动
sudo ln -s /opt/nexus-2.6.4/nexus-2.6.4-02/bin/nexus /etc/init.d/nexus 使用 service nexus status/star ...
- ElasticSearch5.3安装head插件及连接ElasticSearch
1. 安装插件head # 去github上下载head git clone git://github.com/mobz/elasticsearch-head.git # 由于head基于nodejs ...
- How To Set Up SSH Keys
How To Set Up SSH Keys.https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
- 纯CSS3悬停图标旋转导航动画代码
分享一款纯CSS3悬停图标旋转导航动画代码.这是一款鼠标移到图标上动画旋转显示导航菜单.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id="x_con ...
- Bootstrap+Angularjs自制弹框
指令 directive('bsPopup', function ($parse) { return { require: 'ngModel', restrict: 'A', link: functi ...