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)
self.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 = self.findEnemies()
bestTarget =
# Figure out which enemy has the most health, and set bestTarget to be that 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):
closest = archer.findNearest(self.findEnemies)
if archerTarget:
self.command(archer, "attack", archerTarget)
elif closest:
self.command(archer, "attack", nearest)
archerTarget = None
loop:
# If archerTarget is dead 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 = self.findFriends()
soldiers = self.findByType("soldier")
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
commandArcher(friends)
commandSoldier(friends)
but i don’t know how to find the enemy with the most health
please help
thank in advance
# 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!
###def summons:
#if self.gold >= self.costOf("soldier"):
#self.summon("soldier")
# 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)
self.findFriends()
self.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 = self.findEnemies()
bestTarget = enemies
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
if enemies.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 bestTarget:
self.command(archer, "attack", bestTarget)
elif nearest:
self.command(archer, "attack", nearest)
archerTarget = None
loop:
# If archerTarget is dead 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 = self.findFriends()
soldiers = self.findByType("soldier")
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
commandSoldier()
commandArcher()