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

Help with summit's gate python

#1

I have been trying to finish summit’s gate for a long time. At first I thought it was my health so got better armor but now I think it is my code.

def commandArchers():
    for archer in self.findByType("archer", self.findFriends()):
        nearestEnemy = archer.findNearestEnemy()
        if nearestEnemy:
            self.command(archer, "attack", nearestEnemy)

def commandSoldiers():
    for soldier in self.findByType("soldier", self.findFriends()):
        nearestEnemy = soldier.findNearestEnemy()
        if nearestEnemy:
            self.command(soldier, "attack", nearestEnemy)         

def commandGriffins():
    for griffin in self.findByType("griffin-rider", self.findFriends()):
        enemies = griffin.findEnemies()
        nearestEnemy = self.findNearest(enemies)
        if nearestEnemy:
            self.command(griffin, "attack", nearestEnemy)
        else:
            self.command(griffin, "defend", self)

def weakestFriend():
    weakestFriend = None
    weakestHealth = 999
    for friend in self.findFriends():
        if friend.health < friend.maxHealth and friend.health < weakestHealth:
            weakestHealth = friend.health
            weakestFriend = friend
    if weakestFriend:
        return weakestFriend
            
def commandPaladins():
    for paladin in self.findByType("paladin", self.findFriends()):
        if paladin.canCast("heal", self):
            if self.health < 600:
                self.command(paladin, "cast", "heal", self)
            else:
                weakestFriend2 = weakestFriend()
                if weakestFriend2:
                    self.command(paladin, "cast", "heal", weakestFriend2)
        else:
            self.command(paladin, "move", {'x': self.pos.x - 4, 'y': self.pos.y})

def summonGriffin():
    if self.gold >= self.costOf("griffin-rider"):
        self.summon("griffin-rider")

def moveForward():
    targetPos = {'x': 328, 'y': 35}
    self.move(targetPos)

def pickTarget():
    enemies = self.findEnemies()
    target = None
    minDistance = 9999
    for enemy in enemies:
        if enemy.type != "door":
            if enemy.type is "catapult":
                target = enemy
                break
            elif enemy.type is "warlock":
                target = enemy
                break
            elif enemy.type is "witch":
                target = enemy
                break
            elif enemy.type is "chieftain":
                target = enemy
                break
            else:
                if self.distanceTo(enemy) < minDistance:
                    minDistance = self.distanceTo(enemy)
                    target = enemy
    if target:
        return target

       
def commandHero():
    target = pickTarget()
    if target:
        while target.health > 0:
            if self.isReady("bash") and target.health > 116:
                self.bash(target)
            else:
                self.attack(target)
                moveForward()
    else:
        moveForward()
        

while True:
    summonGriffin()
    commandArchers()
    commandSoldiers()
    commandGriffins()
    commandPaladins()
    commandHero()

Please help.

#2

Command the paladins to heal the hero when needed.

#3

Thanks I passed!:smile:

1 Like