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

I need help with summits Gate

@Deadpool198
Can you help me with this. Here’s my code

def commandArchers():
for archer in self.findByType(“archer”, self.findFriends()):
nearestEnemy = archer.findNearestEnemy()
if nearestEnemy:
self.command(archer, “attack”, nearestEnemy)
else:
hero.command(archer, “defend”, hero)

def commandSoldiers():
for soldier in self.findByType(“soldier”, self.findFriends()):
nearestEnemy = soldier.findNearestEnemy()
if nearestEnemy:
self.command(soldier, “attack”, nearestEnemy)
else:
hero.command(soldier, “defend”, hero)
def summonGriffins():
if hero.gold > hero.costOf(“griffin-rider”):
hero.summon(“griffin-rider”)
def pick():
item = hero.findNearestItem()
flag = hero.findFlag()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if flag:
hero.pickUpFlag(flag)
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 < 3000:
self.command(paladin, “cast”, “heal”, self)
else:
weakestFriend2 = weakestFriend()
if weakestFriend2:
self.command(paladin, “cast”, “heal”, weakestFriend2)
else:
hero.command(paladin, “defend”, hero)

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 is not “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 hero.canCast(“chain-lightning”, target):
hero.cast(“chain-lightning”, target)
if hero.isReady(“stomp”):
hero.stomp()
elif hero.isReady(“throw”):
hero.throw(target)
elif hero.isReady(“bash”):
hero.bash(target)
else:
self.attack(target)
hero.shield()
else:
    moveForward()

def attackCatapults():
catapults = self.findByType(“catapult”)
if len(catapults):
for catapult in catapults:
while catapult.health > 0:
self.attack(catapult)
while True:
pick()
summonGriffins()
commandPaladins()
commandArchers()
commandSoldiers()
commandGriffins()
pickTarget()
commandHero()
attackCatapults()

Unfortunately I am not @Deadpool198, but i know that he would ask that that you show the indentations. Please make sure that you format your code correctly.

yeah im doing that on the game right now i noticed it ill post the new code after.

Alright, thanks @lundyundy!

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
def commandArchers():
    for archer in self.findByType('archer', self.findFriends()):
        nearestEnemy = archer.findNearestEnemy()
    if nearestEnemy:
        self.command(archer, 'attack', nearestEnemy)
    else:
        hero.command(archer, 'defend', hero)
    
    def commandSoldiers():
        for soldier in self.findByType('soldier', self.findFriends()):
            nearestEnemy = soldier.findNearestEnemy()
    if nearestEnemy:
        self.command(soldier, 'attack', nearestEnemy)
    else:
        hero.command(soldier, 'defend', hero)
def summonGriffins():
    if hero.gold > hero.costOf('griffin-rider'):
        hero.summon('griffin-rider')
def pick():
    item = hero.findNearestItem()
    flag = hero.findFlag()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    if flag:
        hero.pickUpFlag(flag)
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 < 3000:
                self.command(paladin, 'cast', 'heal', hero)
    else:
        weakestFriend2 = weakestFriend()
    if weakestFriend2:
        self.command(paladin, 'cast', 'heal', weakestFriend2)
    else:
        hero.command(paladin, 'defend', hero)

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 is not 'door':
            if enemy.type is 'catapult':
                target = enemy
        elif enemy.type is 'warlock':
            target = enemy
        elif enemy.type is 'witch':
            target = enemy
        elif enemy.type is 'chieftain':
            target = enemy
        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 hero.canCast('chain-lightning', target):
                hero.cast('chain-lightning', target)
            if hero.isReady('stomp'):
                hero.stomp()
            elif hero.isReady('throw'):
                hero.throw(target)
            elif hero.isReady('bash'):
                hero.bash(target)
            else:
                self.attack(target)
                hero.shield()

def attackCatapults():
    catapults = self.findByType('catapult')
    if len(catapults):
        for catapult in catapults:
            while catapult.health > 0:
                self.attack(catapult)
    while True:
        pick()
        summonGriffins()
        commandPaladins()
        commandArchers()
        commandSoldiers()
        commandGriffins()
        pickTarget()
        commandHero()
        attackCatapults()

I think that’s right can you still help @TheBredMeister i really need to beat this level

literally no one on my side moves

hmmmm… I got some other stuff going on,let me call @dedreous he knows what he’s doing.

I changed it to this

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

def commandArcher(archer):
    for friend in hero.findByType("archer"):
        tower = hero.findByType("tower")
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)

def commandSoldier(soldier):
    friends = hero.findFriends()
    for friend in hero.findByType("soldier"):
        catapult = friend.findNearest(hero.findByType("catapult"))
        if catapult:
            hero.command(friend, "move", {'x': catapult.pos.x, 'y': catapult.pos.y})

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin, "cast" "heal", hero)
    elif enemy:
        hero.command(paladin, "attack", enemy)

def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        if friend.type == "archer":
            commandArcher(friend)
        if friend.type == "soldier":
            commandSoldier(friend)

while True:
    commandFriends()
    attack()

oh alrighty then cya later

ummmmmmmmmmmmmmmm? anyone there?

I am not on summits gate yet, but maybe I can help.

ok what should i fix

can anyone help or no

what do you think i should do @abc

You should summon your soldiers, archers, and paladins like you did, but I think maybe the problem is your while true loop:

while True: commandFriends() 
attack()

This is because even though you used the same for loop in the function, you should use it again like this:

While True:
friends = hero.findFriends()
    for friend in friends:
        commandFriends() 
    attack()

Also what character are you using. Certain characters could help in this level, like rangers

ok thank you @abc i will try that and im using Alejandro

My code isnt running before it even loaded the level it said i had in infinite loop detected

my people dont even m ove what the heck is wrong :rage: :rage: :rage: :rage: :rage: :rage: