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

[SOLVED] Summit's Gate help! [Python]

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
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 = 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()

I need some help about this, my soldier didn’t walk to the catapult and it’s error :frowning: can someone help me please?

When you use hero.findByType() you get an array which doesn’t give you the pos you need.

catapult = hero.findByType("catapult") # returns an array
# add a .findNearest before to isolate the closest catapult to the friend
catapult = friend.findNearest(hero.findByType("catapult"))

1 Like

Thanks that’s work!, but

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

It’s error the paladin didn’t heal me

I found it!

if paladin.canCast("heal") and hero.health <= 1000:
            hero.command(paladin, "cast" "heal", hero)

I forgot to put the “,”

what do you forgot friend

here is 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)
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()

Please do not post requests for assistance in more than one location. You will not receive assistance any faster by doing so. Also, please read the following to learn how to properly post your code.