Grim Determination ,Please Help:)


#1

I get stuck for a few days ,but just can’t get through it.

Let me thanks for your kindly help first.


What I want to do(strategy,but I’m not sure if I’ll win) is:
1.Let Paladin move a little bit forward(ensure they’ll not too close to the bomb) and shield, if warlock appear, then attack warlock ; if one of them injured,(health <400),heal the lowesthealthpaladin.
2.summon griffin-rider and command them move to point {“x”:68,“y”:38}, if warlock ,attack ; if not warlock ,attack nearest enemy.

But what it work is:
1.paladin can shield and heal, but when warlock shows , them didn’t attack warlock.
2.first griffin-rider attack the ground(not enemy),second griffin attack the nearest enemy,but when warlock shows up, they didn’t attack him first.


here is my code:

# Your goal is to protect Reynaldo
# Find the paladin with the lowest health.
def lowestHealthPaladin():
    lowestHealth = 400
    lowestFriend = None 
    for friend in self.findFriends():
        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!
    for friend in self.findFriends():
        if friend.type != "paladin":
            continue
        enemy = friend.findNearest(friend.findEnemies())
        lowestFriend = lowestHealthPaladin()
        if lowestFriend :
            self.command(paladin, "cast", "heal", lowestFriend)
        elif not lowestFriend :
            if enemy and enemy.type == "warlock":
                self.command(friend, "attack", enemy)
            else:
                self.command(paladin, "shield" )

pass
def commandGriffin():
    for friend in self.findFriends():
        if friend.type != "griffin-rider":
            continue
        enemy = friend.findNearest(self.findEnemies())
        warlock = friend.findNearest(self.findByType("warlock"))
        if warlock:
            self.command(friend, "attack", warlock)
        elif not warlock:
            self.command(friend, "attack", enemy)        

def  commandPeasant():
    for friend in self.findFriends():
        if friend.type !=  "peasant" :
            continue
        coin = friend.findNearest(friend.findItems())
        if coin and coin.value >=1 :
            self.command(friend,  "move" , coin.pos)
        
        


def commandFriends():
    # Command your friends.
    friends = self.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)




#outside loop, make sure they won't keep moving forward
friends = self.findByType("paladin")
for friendIndex ,friend in enumerate(friends):
    if friend.pos.x >75:
        continue
    if friend.pos.x <75:    
        self.command(friend, "move", {"x":friend.pos.x+10,"y":friend.pos.y-2})
             
loop:
    if self.now() >2:      #time for paladin to move
        commandFriends()
    # Summon griffin riders!
    if  self.gold >= self.costOf("griffin-rider"):
        self.summon("griffin-rider")
        for friend in self.findFriends():
            if friend.type == "griffin-rider":
                self.command(friend, "move", {"x":68,"y":38})
                commandGriffin()   #if I don't add this code ,they will just stand and do nothing
            else:
                commandFriends()

#2

I passes that level recently.
Strategy was:
Commanded paladins first to heal damaged paladin then to attack nearest enemy.
Griffin-riders were attacking nearest enemy.
Peasants were collecting coins in optimized way! That was the key. Split the field in two, each peasant get nearest coin in its field. Income was greatly increased. Bunch of griffins killed all in their path :slightly_smiling:


#3

Wow ,thanks for you suggestion !!
I’ll try to fix my code and try it again !

CoR ,thank you very much~


#4

Yes!!! I just passed that level!!!

I make the lowerestfriend shield and the other paladin heal and attack.
if there are not lowerestfriend ,that attack nearest enemy~

the other strategy just like yours~ :slightly_smiling:


#5

Yup, attack the nearest is moving paladins toward enemy and away from minefield :slight_smile:


#6

Another strategy is making the paladin tanks, then telling griffins to defend at some point behind the paladins, taking out enemies and not really getting damaged.