Grim determination HELP SOS

here is my code please help:

summonTypes = ['griffin-rider']


def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)



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):
    if (paladin.canCast("heal")):
        target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)
    elif (paladin.health < 200):
        hero.command(paladin, "shield")
    else:
        target = paladin.findNearestEnemy()
        if (target):
            hero.command(paladin, "attack", target)


def commandPeasant(peasant):
    item = peasant.findNearestItem()
    if item:
        hero.command(peasant, 'move', item.pos)


def commandGriffin(griffin):
    target = hero.findNearest(hero.findByType('warlock'))
    if not target:
        target = griffin.findNearestEnemy()
    if (target):
        hero.command(griffin, "attack", target)


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


while True:
    commandFriends()

@AnSeDra help sos help

Try to not attack the warlock at all, so check for each command attack the target and only attack if it is not a warlock.

Andrei

1 Like

I don’t get what you mean

Try to not attack the warlock, so command the paladin to attack their nearest enemy only if it is not the warlock, else shield (the same attack tactic for the riders but without the shirld part).

Andrei

Gtg, I will let someone else to help you.

Andrei

Where are you summoning your griffins?
Danny

Here @Deadpool198.

Andrei

But where are you actually summoning them?
You have to call a function for it to happen.
Danny

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.

help plz im stuck here is my current 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):
    enemyMissiles = hero.findEnemyMissiles()
    missile = hero.findNearest(enemyMissiles)
    # Heal the paladin with the lowest health using 
    enemy = hero.findNearestEnemy()
    if lowestHealthPaladin():
        if paladin.canCast("heal", lowestHealthPaladin()):
            hero.command(paladin, "cast", "heal", 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!
    
    if enemy:
        hero.command(paladin, "attack", enemy)
    pass
def commandPeasant(friend):
    item = friend.findNearestItem()
    if item:
        hero.command(friend, "move", item.pos)
    pass
def commandGriffin(friend):
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type=="warlock":
        hero.command(friend, "attack", enemy)
    else:
        hero.command(friend, "defend", friend.pos)
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)
            pass
while True:
    commandFriends()
    enemy = hero.findNearestEnemy()
    # Summon griffin riders!
    if hero.gold>=hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")

the issue is that the riders and eveyone else dies so the enmies get through after some pushing me back (no error)

So everything works well? Including the paladins casting heal? That section looks a bit fishy to me… But if it works, it works.
You could try commanding the griffins to attack specific enemies so that you have an advantage.

1 Like

is this code possible to win if i hit submit a couple of times? cause there are no errors?

You do still need to complete the objectives.
So you may need to change your code tactics.
Danny

2 Likes

like what and how would i so that?

and i dont know if that does work there is just no error anywhere at all… @Deadpool198

Deadpool is right to doubt that your paladins are being healed.
To solve this level, your soldiers need to be able to move, defend, attack, heal, shield depending on their health, their location and their foes.How this is done is explained in previous topics about the same level, use the search engine.
Example of how the level can be passed. Can be done without the fifth paladin and without any losses, but it’s funnier this way.


To create animated gifs I use Peek under Linux and ScreenToGif under Windows.

2 Likes

so then how would i make sure my paladin’s are getting healed?

nvm i figured it out yay! :partying_face: thanks for helping me @Deadpool198 and @xython

1 Like