Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim determination - I'm Determined!

def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.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() 
    if paladin:
        lowPaladin = lowestHealthPaladin()
        if lowPaladin:
            self.command(paladin, "cast", "heal", lowPaladin)
        else:
            enemy = paladin.findNearest(hero.findEnemies)
            if enemy:
                hero.command(paladin, "shield")
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    

def commandFriends():
    # Command your friends.
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            commandPeasant(friend)
        elif friend.type == "griffin-rider":
            commandGriffin(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)
def commandGriffin(griffin):
    enemy = griffin.findNearest(griffin.findEnemies())
    self.command(griffin, "attack", enemy)
    
def commandPeasant(peasant):
    coin = peasant.findNearest(peasant.findItems())
    self.command(peasant, "move", coin.pos)
while True:
    
    commandFriends()
    # Summon griffin riders!
    if hero.gold > 50:
        self.summon("griffin-rider")

There is no error, it’s just that my troops always get beaten by the ogres.

The first problem I see is…what if the paladin is unable to cast heal?

def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.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() 
    if paladin:
        enemies = hero.findEnemies()
        lowPaladin = lowestHealthPaladin()
        shaman = hero.findByType("warlock")
        if lowPaladin:
            if paladin.canCast("heal"):
                self.command(paladin, "cast", "heal", lowPaladin)
        elif shaman[0]:
            hero.command(paladin, "attack", shaman[0])
        else:
            enemy = paladin.findNearest(enemies)
            if enemy:
                hero.command(paladin, "attack", enemy)
    # Paladins can also shield: command(paladin, "shield")
    

def commandFriends():
    # Command your friends.
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            commandPeasant(friend)
        elif friend.type == "griffin-rider":
            commandGriffin(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)
def commandGriffin(griffin):
    enemy = griffin.findNearest(griffin.findEnemies())
    shaman = hero.findByType("warlock")
    if shaman[0]:
        hero.command(griffin, "attack", shaman[0])
    else:
        self.command(griffin, "attack", enemy)
    
def commandPeasant(peasant):
    coin = peasant.findNearest(peasant.findItems())
    self.command(peasant, "move", coin.pos)
while True:
    
    commandFriends()
    # Summon griffin riders!
    if hero.gold > 50:
        self.summon("griffin-rider")
still isn't working...

Rather than test for a paladin, test to see if the current paladin is ready to cast heal. If he is, then heal lowest. Else if not ready, but he is below a certain health (I used 200), then shield. Finally, if none of the above, then attack.

Also, you are using a mix of hero and self…self is a very old method and really should be replaced with hero. I read on one of the topics that hero is faster and more stable, too.

My paladins are lasting longer, but not for a whole minute yet.

ok, good! How about targeting the warlock specifically…see if the griffon-rider sees one, attack it if yes, or attack nearest if not.

Ok, that worked! Thanks for the help!

1 Like