Here’s the link for the level.
And this is my code.
# Your goal is to protect Reynaldo
# Find the paladin with the lowest health.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
if friend.type != "paladin":
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
# Paladins can also shield: command(paladin, "shield")
# And don't forget, they can attack, too!
inNeed = lowestHealthPaladin()
if inNeed and paladin.canCast('heal'):
hero.command(paladin, 'cast', 'heal', inNeed)
enemy = paladin.findNearestEnemy()
if enemy:
hero.command(paladin, 'attack', enemy)
else:
hero.command(paladin, 'shield')
pass
def findBestVOD(man, bunch, exclu):
bestCoin = None
bestVOD = 0
for i in bunch:
distance = man.distanceTo(i)
if i in exclu:
continue
elif i.value / distance > bestVOD:
bestCoin = i
bestVOD = i.value / distance
return bestCoin
def commandPeasant(p, excluded):
items = hero.findItems()
if items:
target = findBestVOD(p, items, excluded)
excluded.append(target)
hero.command(p, 'move', target.pos)
def commandGriffin(g):
hero.command(g, 'defend', {'x':86, 'y':38})
def commandFriends(ex):
# Command your friends.
friends = hero.findFriends()
for friend in friends:
if friend.type == "peasant":
#commandPeasant(friend)
commandPeasant(friend, ex)
pass
elif friend.type == "griffin-rider":
#commandGriffin(friend)
commandGriffin(friend)
pass
elif friend.type == "paladin":
commandPaladin(friend)
while True:
claimed = []
commandFriends(claimed)
# Summon griffin riders!
if hero.gold > hero.costOf('griffin-rider'):
hero.summon('griffin-rider')
First of all, my paladins never cast healing.
Not even once.
Here’s the same code part from the above.
def commandPaladin(paladin):
inNeed = lowestHealthPaladin()
if inNeed and paladin.canCast('heal'):
hero.command(paladin, 'cast', 'heal', inNeed)
enemy = paladin.findNearestEnemy()
if enemy:
hero.command(paladin, 'attack', enemy)
else:
hero.command(paladin, 'shield')
pass
I’m not sure but the second if condition, for checking whether there’s an enemy or not, is disturbing the first if, I guess. But shouldn’t they be executed separately since they are not related?
Secondly, I have no idea what to do to control my griffin riders.
I did notice that I should kill the enemy casters first.
So I tried this below.
def commandGriffin(g):
priorTarget = hero.findNearest(hero.findByType("warlock"))
if priorTarget:
while priorTarget.health > 0:
hero.command(g, 'attack', priorTarget)
else:
hero.command(g, 'defend', {'x':86, 'y':38})
Then, once the first born griffin rider gets to the defending point, they just stuck in an infinite loop.