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 ...
随机推荐
- Word实用教程——五分钟教你如何在任意页开始添加页码
最近在写一篇论文,但是在排版上遇到一点小问题,就是要加入页码,而且页码是从目录的下一页开始计数,于是我就在网上找如何在任意页添加页码.后来辗转终于搞定,真心觉得这一个小功能让微软做的如此的麻烦,真是活 ...
- Flink KAFKA
https://data-artisans.com/blog/kafka-flink-a-practical-how-to https://github.com/dataArtisans/kafka- ...
- 36氪首发 | 「myShape」完成千万级人民币 Pre-A轮融资,推出 AI 智能健身私教
无需任何可穿戴设备. 36氪获悉,myShape(原Shapejoy)已于近期完成千万级人民币的Pre-A轮融资,由天奇阿米巴领投,远洋集团.七熹资本以及老股东跟投.过去 myShape 曾获得元迅资 ...
- 高级数据库及一步一步搭建versant数据库
总的来说,高级数据库课程分为分布式数据库和面向对象数据库两块.分布式数据库介绍了分布式数据库的方方面面,包括数据库系统的设计.查询处理优化.事务管理和恢复.并发控制.可靠性.安全性与目录管理等.面向对 ...
- Window 分布式 学习2----好文收藏
概述 我们在上一篇Windows平台分布式架构实践 - 负载均衡中讨论了Windows平台下通过NLB(Network Load Balancer) 来实现网站的负载均衡,并且通过压力测试演示了它的效 ...
- kindeditor自定义插件插入视频代码
kindeditor自定义插件插入视频代码 1.添加插件js 目录:/kindeditor/plugins/diy_video/diy_video.js KindEditor.plugin('diy_ ...
- C#学习笔记(25)——用刻盘器批量从U盘删除添加文件
说明(2017-11-17 14:46:05): 1. 因为经常要从U盘里面删除版本,然后添加版本,每次都要几个人手动复制粘贴,费时费力,就花了一下午时间写了个程序,自动删除和添加版本. 2. Dri ...
- [转]BigDecimal不整除异常
通过BigDecimal的divide方法进行除法时当不整除,出现无限循环小数时,就会抛异常的 异 常 :java.lang.ArithmeticException: Non-terminatin ...
- [转]java中参数" ..."的用法和意思
原文地址:https://blog.csdn.net/lycit/article/details/78809625 如这个jdbc中封装的绑定参数的方法: /** * 绑定参数 * @param ps ...
- # Writing your-first Django-app-part 5 -test
确认bug 写test测试暴露bug 修复bug 更多测试例子 测试一个view The Django test client测试客户端. 提升DemoAppPoll/views.py 测试我们的vi ...