here is my code
def commandArchers():
for archer in self.findByType(âarcherâ, self.findFriends()):
nearestEnemy = archer.findNearestEnemy()
if nearestEnemy:
self.command(archer, âattackâ, nearestEnemy)
else:
hero.command(archer, âdefendâ, hero)
def commandSoldiers():
for soldier in self.findByType(âsoldierâ, self.findFriends()):
nearestEnemy = soldier.findNearestEnemy()
if nearestEnemy:
self.command(soldier, âattackâ, nearestEnemy)
else:
hero.command(soldier, âdefendâ, hero)
def summonGriffins():
if hero.gold > hero.costOf(âgriffin-riderâ):
hero.summon(âgriffin-riderâ)
def pick():
item = hero.findNearestItem()
flag = hero.findFlag()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if flag:
hero.pickUpFlag(flag)
def commandGriffins():
for griffin in self.findByType(âgriffin-riderâ, self.findFriends()):
enemies = griffin.findEnemies()
nearestEnemy = self.findNearest(enemies)
if nearestEnemy:
self.command(griffin, âattackâ, nearestEnemy)
else:
self.command(griffin, âdefendâ, self)
def weakestFriend():
weakestFriend = None
weakestHealth = 999
for friend in self.findFriends():
if friend.health < friend.maxHealth and friend.health < weakestHealth:
weakestHealth = friend.health
weakestFriend = friend
if weakestFriend:
return weakestFriend
def commandPaladins():
for paladin in self.findByType(âpaladinâ, self.findFriends()):
if paladin.canCast(âhealâ, self):
if self.health < 3000:
self.command(paladin, âcastâ, âhealâ, self)
else:
weakestFriend2 = weakestFriend()
if weakestFriend2:
self.command(paladin, âcastâ, âhealâ, weakestFriend2)
else:
hero.command(paladin, âdefendâ, hero)
def summonGriffin():
if self.gold >= self.costOf(âgriffin-riderâ):
self.summon(âgriffin-riderâ)
def moveForward():
targetPos = {âxâ: 328, âyâ: 35}
self.move(targetPos)
def pickTarget():
enemies = self.findEnemies()
target = None
minDistance = 9999
for enemy in enemies:
if enemy.type is not âdoorâ:
if enemy.type is âcatapultâ:
target = enemy
break
elif enemy.type is âwarlockâ:
target = enemy
break
elif enemy.type is âwitchâ:
target = enemy
break
elif enemy.type is âchieftainâ:
target = enemy
break
else:
if self.distanceTo(enemy) < minDistance:
minDistance = self.distanceTo(enemy)
target = enemy
if target:
return target
def commandHero():
target = pickTarget()
if target:
while target.health > 0:
if hero.canCast(âchain-lightningâ, target):
hero.cast(âchain-lightningâ, target)
if hero.isReady(âstompâ):
hero.stomp()
elif hero.isReady(âthrowâ):
hero.throw(target)
else:
self.attack(target)
hero.shield()
else:
moveForward()
def attackCatapults():
catapults = self.findByType(âcatapultâ)
if len(catapults):
for catapult in catapults:
while catapult.health > 0:
self.attack(catapult)
while True:
pick()
summonGriffins()
commandPaladins()
commandArchers()
commandSoldiers()
commandGriffins()
pickTarget()
commandHero()
attackCatapults()