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

Grim Determination [Help]

# 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):
    canHeal = paladin.canCast("heal")
    lowest_friend = lowestHealthPaladin()
    if lowest_friend:
        if lowest_friend.health < 550:
            hero.command(paladin, "cast", "heal", lowest_friend)
    if paladin.health < 100:
        hero.command(paladin, "shield")
    #elif contains_warlock():
    #    target = paladin.findNearest(hero.findByType("warlock"))
    #    hero.command(paladin, "attack", target)
    else:
        target = paladin.findNearest(paladin.findEnemies())
        if target:
            hero.command(paladin, "attack", target)
    pass

def contains_warlock():
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "warlock":
            return True
    return False

def commandPeasant(friend):
    coins = hero.findItems()
    if len(coins) > 3:
        best_value = 0
        for coin in coins:
            value = coin.value / friend.distanceTo(coin)
            if value > best_value:
                best_value = value
                best_coin = coin
        hero.command(friend, "move", best_coin.pos)

def commandGriffin(friend):
    if contains_warlock():
        target = friend.findNearest(hero.findByType("warlock"))
    else:
        target = friend.findNearest(friend.findEnemies())
    if target:
        hero.command(friend, "attack", target)

def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            commandPeasant(friend)
            pass
        elif friend.type == "griffin-rider":
            commandGriffin(friend)
            pass
        elif friend.type == "paladin":
            commandPaladin(friend)

while True:
    commandFriends()
    # Summon griffin riders!
    if hero.gold > hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")

No errors, seems like I’m covering all aspects. I’ve tried both focusing warlocks and not focusing them, neither work.

Hi @EzDzQzR,
welcome to the CodeCombat discourse.
Sorry for keeping you waiting, and also for my disappointing answer to your problem: I’m afraid there’s not really anything concrete I can do to help you with this level. There’s not right answer. Except one thing: make the griffin-riders and friends return to a central point if there isn’t an enemy. I think that might help.
If that doesn’t work, maybe look at other topics talking about this level, they might give you some inspiration.
-Danny