Someone please help me with python on summit's gate!

Can I see your equipment please?

Okay. Here’s a list:
Secondary: Deflector
Primary: RuneSword
Lens: Enchanted Lenses
Sense Stone: Quartz Sense Stone
Gloves: Emperor’s Gloves
WristWatch: Simple WristWatch
Boots: Boots Of Leaping
Ring One: None
Ring Two: Ring of Flowers
Boss Star: Boss Star 3
Flags: Basic Flags
Book: Book 5
Hero: Tharin Thunderfist

1 Like

what armor do u use?

OH! All enameled dragonplate (helmet and chest plate)

1 Like

Rune sword is pretty bad in this level. Can you afford sword of the temple guard or the sword of the forgotten?

No. My gems are in the hundreds right now.

You should play some replayable levels.

actually, that’s a good idea! I’ll go do that! If anyone finds the problem, please tell me. Thanks!

1 Like

you attack the tower when strategy == 1
But you also attack the door when strategy == 1 right after your code to attack the tower

while True:
    armyAttack()
    enemy = hero.findNearestEnemy()
    door = hero.findNearest(hero.findByType("door"))
    if enemy and enemy.type != "door" and enemy.health > 0:
        if strategy == 0 or strategy == 1: <-------- # if strategy equal 0 or 1
            door = hero.findNearest(hero.findByType("door")) # find the door, and attack it
            if door:
                while door.health > 0:
                    hero.attack(door)
        if strategy == 2:
            pass#Will fill this in later
        strategy += 1

Decided to replay this level to simplify my code :slight_smile:

Oh! Thanks! I’ll probably just put a ‘continue’ and an else statement, to make sure I attack all actual enemies before the door.

Everything in room one works out, but my hero attacks the door right after defeating the first tower in room two. Here’s my code, it might just be a bug:

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

def findLowestFriend():
    friends = hero.findFriends()
    lowestFriend = None
    lowestHealth = 9999999999999999999999999999999999999999999999999999999999999999999999999999999
    for friend in friends:
        if friend.type == "paladin":
            if friend.health/friend.maxHealth < lowestHealth and friend.health < friend.maxHealth:
                lowestFriend = friend
                lowestHealth = friend.health/friend.maxHealth
    if not lowestFriend:
        for friend in friends:
            if friend.health/friend.maxHealth < lowestHealth and friend.health < friend.maxHealth:
                lowestFriend = friend
                lowestHealth = friend.health/friend.maxHealth
        if lowestHealth > hero.health/hero.maxHealth:
            lowestFriend = hero
    if lowestFriend:
        return lowestFriend
    else:
        return None

def commandPaladin(paladin):
    if strategy == 0:
        needsHeal = findLowestFriend()
        if needsHeal:
            if needsHeal == paladin:
                hero.command(paladin, "shield")
            elif paladin.canCast("heal", needsHeal):
                hero.command(paladin, "cast", "heal", needsHeal)
            else:
                target = paladin.findNearest(hero.findByType("catapult"))
                if target:
                    hero.command(paladin, "attack", target)
                else:
                    target = paladin.findNearestEnemy()
                    if target and target.type != "door":
                        if paladin.distanceTo(target) <= 5:
                            hero.command(paladin, "shield")
                        hero.command(paladin, "attack", target)
        else:
            target = paladin.findNearest(hero.findByType("catapult"))
            if target:
                hero.command(paladin, "attack", target)
            else:
                target = paladin.findNearestEnemy()
                if target and target.type != "door":
                    if paladin.distanceTo(target) <= 5:
                        hero.command(paladin, "shield")
                    hero.command(paladin, "attack", target)
    if strategy == 1:
        needsHeal = findLowestFriend()
        if needsHeal:
            if needsHeal == paladin:
                hero.command(paladin, "shield")
            elif paladin.canCast("heal", needsHeal):
                hero.command(paladin, "cast", "heal", needsHeal)
            else:
                target = paladin.findNearest(hero.findByType("tower"))
                if target:
                    hero.command(paladin, "attack", target)
                else:
                    target = paladin.findNearestEnemy
                    if target and target.type != "door":
                        if paladin.distanceTo(target) <= 5:
                            hero.command(paladin, "shield")
                        hero.command(paladin, "attack", target)
        else:
            target = paladin.findNearest(hero.findByType("tower"))
            if target:
                hero.command(paladin, "attack", target)
            else:
                target = paladin.findNearestEnemy
                if target and target.type != "door":
                    if paladin.distanceTo(target) <= 5:
                        hero.command(paladin, "shield")
                    hero.command(paladin, "attack", target)
    if strategy == 2:
        needsHeal = findLowestFriend()
        if needsHeal:
            if needsHeal == paladin:
                hero.command(paladin, "shield")
            elif paladin.canCast("heal", needsHeal):
                hero.command(paladin, "cast", "heal", needsHeal)
            else:
                target = paladin.findNearestEnemy()
                if target and target.type != "door":
                    if paladin.distanceTo(target) <= 5:
                        hero.command(paladin, "shield")
                    hero.command(paladin, "attack", target)
        else:
            target = paladin.findNearestEnemy()
            if target and target.type != "door":
                if paladin.distanceTo(target) <= 5:
                    hero.command(paladin, "shield")
                hero.command(paladin, "attack", target)

def commandGriffin(griffin):
    if strategy == 0:
        target = griffin.findNearest(hero.findByType("catapult"))
        if target:
            hero.command(griffin, "attack", target)
        else:
            target = griffin.findNearestEnemy()
            if target and target.type != "door":
                hero.command(griffin, "attack", target)
    if strategy == 1:
        target = griffin.findNearest(hero.findByType("tower"))
        if target:
            hero.command(griffin, "attack", target)
        else:
            target = griffin.findNearestEnemy()
            if target and target.type != "door":
                hero.command(griffin, "attack", target)
    if strategy == 2:
        target = griffin.findNearestEnemy()
        if target and target.type != "door":
            hero.command(griffin, "attack", target)

def commandSoldier(soldier):
    if strategy == 0:
        target = soldier.findNearest(hero.findByType("catapult"))
        if target:
            hero.command(soldier, "attack", target)
        else:
            target = soldier.findNearestEnemy()
            if target and target.type != "door":
                hero.command(soldier, "attack", target)
    if strategy == 1:
        target = soldier.findNearest(hero.findByType("tower"))
        if target:
            hero.command(soldier, "attack", target)
        else:
            target = soldier.findNearestEnemy()
            if target and target.type != "door":
                hero.command(soldier, "attack", target)
    if strategy == 2:
        target = soldier.findNearestEnemy()
        if target and target.type != "door":
            hero.command(soldier, "attack", target)

def commandArcher(archer):
    if strategy == 0 or strategy == 1:
        hero.command(archer, "defend", hero.pos)
    if strategy == 2:
        target = archer.findNearestEnemy()
        if target and target.type != "door":
            hero.command(archer, "attack", target)

def heroToBattle():
    if strategy == 0:
        enemy = hero.findNearest(hero.findByType("catapult"))
        if enemy:
            if hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
            hero.shield()
        else:
            enemy = hero.findNearestEnemy()
            if enemy:
                if hero.canCast("chain-lightning", enemy):
                    hero.cast("chain-lightning", enemy)
                elif hero.isReady("bash"):
                    hero.bash(enemy)
                else:
                    hero.attack(enemy)
                hero.shield()
    if strategy == 1:
        enemy = hero.findNearest(hero.findByType("tower"))
        if enemy:
            if hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
            hero.shield()
        else:
            enemy = hero.findNearestEnemy()
            if enemy and enemy.type != "door":
                if hero.canCast("chain-lightning", enemy):
                    hero.cast("chain-lightning", enemy)
                elif hero.isReady("bash"):
                    hero.bash(enemy)
                else:
                    hero.attack(enemy)
                hero.shield()
    if strategy == 2:
        enemy = hero.findNearestEnemy()
        if enemy and enemy.type != "door":
            if hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
            hero.shield()

def armyAttack():
    summonGriffin()
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        if friend.type == "griffin-rider":
            commandGriffin(friend)
        if friend.type == "soldier":
            commandSoldier(friend)
        if friend.type == "archer":
            commandArcher(friend)
    heroToBattle()

strategy = 0
while True:
    armyAttack()
    enemy = hero.findNearestEnemy()
    door = hero.findNearest(hero.findByType("door"))
    if enemy and enemy.type != "door" and enemy.health > 0:
        continue
    if strategy == 0 or strategy == 1:
        door = hero.findNearest(hero.findByType("door"))
        if door:
            while door.health > 0:
                hero.attack(door)
    if strategy == 2:
        pass# still haven't figured this out
    strategy += 1

your strategy variable increment everytime the loop finishes
so when your strategy = 2 or more the hero will attack the nearest enemy
ignoring everything

wait, shouldn’t the ‘continue’ make sure that all non-door enemies are defeated before moving on? the part after that is supposed to end the current room, and then increment ‘strategy’, because now another strategy must be used.

Continue statement is just used to stop the code at some point in a loop and write the output of this point. It will then go to the next line. so the loop is still going on.

you need to use strategy as a condition
to make it simpler:

if there is no enemy and strategy == 0:
strategy += 1

if strategy == 1:
find the door
kill the door
if there is no door and strategy == 1:
move somehere
strategy += 1

if strategy == 2:
find the towers
kill the tower

if there is no tower and strategy == 2:
strategy += 1

ect

So I should just increment within the if statements for the strategy? I’ll try it…

Actually, wouldn’t this work?:

while true:
    armyAttack()
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type != "door":
        pass
    else:
        if strategy == 0 or strategy == 1:#where I should just kill the door
            door = hero.findNearest(hero.findByType("door"))
            if door and door.health > 0:
                while door.health > 0:
                    hero.attack(door)
            strategy += 1
        if strategy == 2:
            #do stuff in here(collect gems, then kill door)
            strategy += 1
        if strategy == 3:
            # if there's anything I need to do in here, I do it here.        

also, etc.

Okay. My hero is STILL attacking the door before the 2nd tower! AND he doesn’t even GO for that tower afterwords! I’ll try what you suggested, it probably would help.

OH! I figured it out. I wrote my code thinking that if the nearest enemy was a door, there were no more enemies. So, when the closest enemy was a door, when the tower was still there, my hero treated the situation like he had already defeated the tower! All I have to do is say that the enemy shouldn’t be door, while labeling the nearest door as door, so that all of my allies are bound to attack the actual enemies first!

Should I bring my allies with me to fight the warlocks?