求助Library Tactician~~~~~~~~~~~~
codecombat吧
全部回复
仅看楼主
level 1
A_佚名_A 楼主
士兵老是会被杀死,不知道是啥原因,大家有过的吗~~~~~~~~~~~~~~
代码如下:
# Hushbaum has been ambushed by ogres!
# She is busy healing her soldiers, you should command them to fight!
# The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!
# Soldiers spread out in a circle and defend.
def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, "defend", defendPos);
# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
for i in range(len(enemies)):
enemy = enemies[i]
if enemy.health > mostHealth:
mostHealth = enemy.health
bestTarget = enemy
# Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
hero.command(archer, "attack", archerTarget)
elif nearest:
hero.command(archer, "attack", nearest)
archerTarget = None
while True:
# If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()
friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
archers = hero.findByType("archer")
findHealing()
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
for j in range(len(archers)):
archer = archers[j]
commandArcher(archer)
2018年04月10日 09点04分 1
level 1
A_佚名_A 楼主
人品爆发,两天没过,刚发完这代码就过了~~~~~~~~~~~汗
PS:
findHealing() 这个是调试用的代码漏删了。
这关有随机性,能不能过靠脸了~~~~~~~~
2018年04月10日 09点04分 2
level 1
每次一半就挂了
2018年04月26日 05点04分 3
1