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

[Solved] Help with Summits Gate

#1

My code for summits gate used to work, and it is very good, but recently it got me stuck where I used to be able to make it through. I get all the way to right before the warlocks, bu then everyone stops moving.

My code:


def findSkeletons(enemies):
    skeletons = hero.findByType("skeleton")
    skeleton = hero.findNearest(skeletons)
    return skeleton
def lowestHealthPaladin():
       
    lowestHealth = 99999
    lowestFriend = None
    friends = self.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
        lowestFriend = friend
    return lowestFriend
    
def notdoor(friend):    
    enemies=self.findEnemies()
    maxdistance=0
    target=None
    for enemy in enemies:
        distance= friend.distanceTo(enemy)
        if distance < maxdistance and enemy.type is not "door":
            maxdistance=distance
            focus=enemy
    if focus:       
        self.say(focus)       
        return focus       
    else:    
        return False
        
def itempeasant(peasant):
    item=peasant.findNearest(self.findItems())
    if item:
        return item
    else:    
        return False
        
def pickUpitem():    
    for peasant in self.findByType("pesant",self.findFriends()):
        while itempeasant(peasant):
            item=itempeasant(peasant)
            self.command(peasant, "attack", item.pos)
    
# Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
waiting={"x":7,"y":26}
waiting2={"x":7,"y":47}
points=[{"x":96,"y":34},{"x":248,"y":34},{"x":280,"y":34},{"x":248,"y":34}]
Up=False
while True:
    catapult = self.findByType("catapult", self.findEnemies())
    tower = self.findByType("tower", self.findEnemies())
    
    
    nb_catapult=len(catapult)    
    nb_tower=len(tower)
    #Command Troop
    friends=self.findFriends()
    i=1
    for foo,friend in enumerate(friends):    
        
        if nb_catapult > 0:
            index=i % nb_catapult
            target=catapult[index]
            if friend.type is "soldier":
                i+=1
        elif friend.pos.x > 240:            
            target=notdoor(friend)          
        elif friend.pos.x < 85 or self.pos.x > 110 :    
            target=friend.findNearest(self.findEnemies())
            target2=self.findNearest(self.findEnemies())
            if not target and target2:
                target=target2
        
            
        else:    
            target=False
            target2=False
        
               
        if friend.type is "paladin":
            mostHurt=lowestHealthPaladin()
            if self.now() > 75 and self.now() < 80:
                self.command(friend, "move", {"x":180,"y":9})
            elif len(catapult) > 0 and Up:
                self.command(friend, "move", waiting)
                Up=False
            elif len(catapult) > 0 and not Up:
                self.command(friend, "move", waiting2)
                Up=True                
            elif friend.pos.x < 94 and friend.pos.x < self.pos.x-5 and self.pos.x < 340:
                self.command(friend, "move", {"x":friend.pos.x+1,"y":34})    
            elif mostHurt and friend.canCast("heal"):
                self.command(friend, "cast", "heal", self)
            elif friend.pos.x < self.pos.x -25 and self.pos.x > 140:    
                self.command(friend, "move", {"x":self.pos.x-20,"y":self.pos.y})    
            elif friend.pos.x > 240:     
                self.command(friend, "attack", target)
            else:     
                self.command(friend, "shield")
        
        
        if friend.type is "archer":
            mostHurt=lowestHealthPaladin()
            warlock=self.findNearest(self.findByType("warlock"))
            if warlock:
                target=warlock
            if self.now() > 75 and friend.pos.x < 175:
                self.command(friend, "move", {"x":180,"y":9})
            elif len(catapult) > 0 and Up:
                self.command(friend, "move", waiting)
                Up=False
            elif len(catapult) > 0 and not Up:
                self.command(friend, "move", waiting2)
                Up=True        
            elif friend.pos.x < self.pos.x -20 and self.pos.x > 140:    
                self.command(friend, "move", {"x":self.pos.x-7,"y":self.pos.y})     
            elif friend.pos.x < 75 and target and friend.pos.x < self.pos.x:
                self.command(friend, "attack", target)
            elif target and friend.pos.x > 247:   
                self.command(friend, "attack", target)        
            elif target and self.pos.x > 118  and friend.pos.x < self.pos.x:  
                self.command(friend, "attack", target)
            elif friend.pos.x > 247 and target :
                self.command(friend, "attack", target)               
            else:                  
                self.command(friend, "defend", {"x":self.pos.x-15,"y":self.pos.y-5})
        
        if friend.type is "soldier":
            if len(catapult) > 0:
                if friend.pos.x < 97 and i > 3:
                    self.command(friend, "move",  {"x":97,"y":34}) 
                elif target:
                    self.command(friend, "attack", target)
                else:    
                    self.command(friend, "move",  {"x":97,"y":34}) 
            elif friend.pos.x < 95 and friend.pos.x > self.pos.x :    
                self.command(friend, "move",  {"x":75,"y":34})
            elif target and self.now() > 90:    
                self.command(friend, "attack",  target)
                
    
    #Command Hero    
    enemy=self.findNearest(self.findEnemies())    
    warlock=self.findNearest(self.findByType("warlock"))
    cheiftain = hero.findNearest(hero.findByType("cheiftain"))
    items = hero.findItems()
    item = hero.findNearest(items)
    skeleton = findSkeletons(hero.findEnemies)
    gem = hero.findNearest(hero.findByType("gem"))
    if len(catapult) < 1:
        if self.pos.x < 130:
            self.move({"x":self.pos.x+1,"y":32})
        elif nb_tower > 0:    
            self.shield()
        elif self.pos.x < 240:    
            self.move(points[1])
        
        elif warlock and hero.canCast("chain-lightning", warlock) or hero.isReady("bash"):    
            if warlock:
                
                if hero.isReady("bash"):
                    hero.bash(warlock)
                else:
                    self.cast("chain-lightning", warlock)
        elif skeleton:
            hero.attack(skeleton)
        elif gem:
            hero.move(gem.pos)
        elif self.pos.x < 275:
            self.move(points[2])
        elif enemy and enemy.type == cheiftain and (hero.canCast("chain-lightning", enemy) or hero.isReady("bash")):
            if hero.canCast("chain-lightning", enemy):
                
                hero.cast("chain-lightning", enemy)
            else:
                hero.bash(enemy)
        else:                
            self.shield()
            
        
        if self.gold >= self.costOf("archer") and (self.pos.x < 94 or nb_tower < 1) and self.now() < 120:    
            self.summon("archer")



please tell me what I can do here!

my gear:
boots of leaping
kithsteel blade
emperor’s gloves
gilt wristwatch
caltrop belt
programmication IV
thronprick
twilight glasses
sapphire sense stone
wooden strand
advanced flags
Boss star III
Engraved Obsidian helmet
Obsidian Breastplate
Deflector

I use Sir Tharin Thunderfist and have 1553 gems

#2

How long ago did you write this? I’m not used to seeing self commands. A few details that I noticed are below.
I see that peasant is spelled incorrectly in pickUpitem()

for peasant in self.findByType("pesant",self.findFriends()):

Also missing the quotations and misspelled chieftain on two different lines in Command Hero. (I recall seeing some post about correcting the Chieftain spelling, your code may have been written before the change)

cheiftain = hero.findNearest(hero.findByType("cheiftain")) #misspelled
## several lines further down
elif enemy and enemy.type == cheiftain # misspelled and missing quotations
#3

This is from several years ago (at least 2+ years ago)
thanks for the spelling errors, I will fix those, but it is unlikely that those will help with where my hero gets stuck

#4

With the notdoor(friend) function I noticed that you start out with target=None and then switch to focus=enemy. Since you are not resetting the focus variable, it may be carrying over and and being returned even though it isn’t what you want.

        elif friend.pos.x > 240:            
            target=notdoor(friend) 
def notdoor(friend):    
    enemies=self.findEnemies()
    maxdistance=0
    target=None
    for enemy in enemies:
        distance= friend.distanceTo(enemy)
        if distance < maxdistance and enemy.type is not "door":
            maxdistance=distance
            focus=enemy
    if focus:       
        self.say(focus)   
        return focus       
    else:    
        return False
#5

I fixed the spelling and equipped the sword of forgotten, also I removed the

,{"x":248,"y":34}

from the

points=[{"x":96,"y":34},{"x":248,"y":34},{"x":280,"y":34},{"x":248,"y":34}]

Now I get fairly far but am receiving the error “TypeError: Statement execution limit reached” on line 12

#6

Please show us the section with line 12 in your code. I don’t want to guess based on your previous code. Is the section below the actual indentation? The third line should be indented one more time to be in the if statement. It is also not a bad idea to have an if statement before the return, just to make sure there is something to return.

        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
        lowestFriend = friend
#7

Actually I fixed it by doing something later on in the code (something about changing the thing points[2] into points[3])

It just happened because I had too much code or it was too confusing or something

#8

Is still not solved, the “statement execution limit reached” still happens

#9

I’m afraid I’ve run into this problem too, in cavern survival, and there doesn’t seem to be a way to fix it except making your code quicker and completing the level quicker.
Sorry, it’s really annoying.
:lion: :lion: :lion:

#10

with my current code:


def findSkeletons(enemies):
    skeletons = hero.findByType("skeleton")
    skeleton = hero.findNearest(skeletons)
    return skeleton
def lowestHealthPaladin():
       
    lowestHealth = 99999
    lowestFriend = None
    friends = self.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend
    
def notdoor(friend):    
    enemies=self.findEnemies()
    maxdistance=0
    target=None
    for enemy in enemies:
        distance= friend.distanceTo(enemy)
        if distance < maxdistance and enemy.type is not "door":
            maxdistance=distance
            focus=enemy
    if focus:       
        self.say(focus)       
        return focus       
    else:    
        return False
        
def itempeasant(peasant):
    item=peasant.findNearest(self.findItems())
    if item:
        return item
    else:    
        return False
        
def pickUpitem():    
    for peasant in self.findByType("peasant",self.findFriends()):
        while itempeasant(peasant):
            item=itempeasant(peasant)
            self.command(peasant, "attack", item.pos)
    
# Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
waiting={"x":7,"y":26}
waiting2={"x":7,"y":47}
points=[{"x":96,"y":34},{"x":278,"y":34},{"x":280,"y":34}]
Up=False
while True:
    catapult = self.findByType("catapult", self.findEnemies())
    tower = self.findByType("tower", self.findEnemies())
    
    
    nb_catapult=len(catapult)    
    nb_tower=len(tower)
    #Command Troop
    friends=self.findFriends()
    i=1
    for foo,friend in enumerate(friends):    
        
        if nb_catapult > 0:
            index=i % nb_catapult
            target=catapult[index]
            if friend.type is "soldier":
                i+=1
        elif friend.pos.x > 240:            
            target=notdoor(friend)          
        elif friend.pos.x < 85 or self.pos.x > 110 :    
            target=friend.findNearest(self.findEnemies())
            target2=self.findNearest(self.findEnemies())
            if not target and target2:
                target=target2
        
            
        else:    
            target=False
            target2=False
        
               
        if friend.type is "paladin":
            mostHurt=lowestHealthPaladin()
            if self.now() > 75 and self.now() < 80:
                self.command(friend, "move", {"x":180,"y":9})
            elif len(catapult) > 0 and Up:
                self.command(friend, "move", waiting)
                Up=False
            elif len(catapult) > 0 and not Up:
                self.command(friend, "move", waiting2)
                Up=True                
            elif friend.pos.x < 94 and friend.pos.x < self.pos.x-5 and self.pos.x < 340:
                self.command(friend, "move", {"x":friend.pos.x+1,"y":34})    
            elif mostHurt and friend.canCast("heal"):
                self.command(friend, "cast", "heal", self)
            elif friend.pos.x < self.pos.x -25 and self.pos.x > 140:    
                self.command(friend, "move", {"x":self.pos.x-20,"y":self.pos.y})    
            elif friend.pos.x > 240:     
                self.command(friend, "attack", target)
            else:     
                self.command(friend, "shield")
        
        
        if friend.type is "archer":
            mostHurt=lowestHealthPaladin()
            warlock=self.findNearest(self.findByType("warlock"))
            if warlock:
                target=warlock
            if self.now() > 75 and friend.pos.x < 175:
                self.command(friend, "move", {"x":180,"y":9})
            elif len(catapult) > 0 and Up:
                self.command(friend, "move", waiting)
                Up=False
            elif len(catapult) > 0 and not Up:
                self.command(friend, "move", waiting2)
                Up=True        
            elif friend.pos.x < self.pos.x -20 and self.pos.x > 140:    
                self.command(friend, "move", {"x":self.pos.x-7,"y":self.pos.y})     
            elif friend.pos.x < 75 and target and friend.pos.x < self.pos.x:
                self.command(friend, "attack", target)
            elif target and friend.pos.x > 247:   
                self.command(friend, "attack", target)        
            elif target and self.pos.x > 118  and friend.pos.x < self.pos.x:  
                self.command(friend, "attack", target)
            elif friend.pos.x > 247 and target :
                self.command(friend, "attack", target)               
            else:                  
                self.command(friend, "defend", {"x":self.pos.x-15,"y":self.pos.y-5})
        
        if friend.type is "soldier":
            if len(catapult) > 0:
                if friend.pos.x < 97 and i > 3:
                    self.command(friend, "move",  {"x":97,"y":34}) 
                elif target:
                    self.command(friend, "attack", target)
                else:    
                    self.command(friend, "move",  {"x":97,"y":34}) 
            elif friend.pos.x < 95 and friend.pos.x > self.pos.x :    
                self.command(friend, "move",  {"x":75,"y":34})
            elif target and self.now() > 90:    
                self.command(friend, "attack",  target)
                
    
    #Command Hero    
    enemy=self.findNearest(self.findEnemies())    
    warlock=self.findNearest(self.findByType("warlock"))
    chieftain = hero.findNearest(hero.findByType("chieftain"))
    items = hero.findItems()
    item = hero.findNearest(items)
    skeleton = findSkeletons(hero.findEnemies)
    gem = hero.findNearestItem()
    
    if len(catapult) < 1:
        if self.pos.x < 130:
            self.move({"x":self.pos.x+1,"y":32})
        elif nb_tower > 0:    
            self.shield()
        elif self.pos.x < 240:    
            self.move(points[1])
        
        elif warlock and hero.canCast("chain-lightning", warlock) or hero.isReady("bash"):    
            if warlock:
                
                if hero.isReady("bash"):
                    hero.bash(warlock)
                else:
                    self.cast("chain-lightning", warlock)
        elif skeleton:
            hero.attack(skeleton)
        elif gem:
            hero.move(gem.pos)
        elif self.pos.x < 275:
            self.move(points[3])
        elif chieftain and (hero.canCast("chain-lightning", chieftain) or hero.isReady("bash")):
            if hero.canCast("chain-lightning", chieftain):
                
                hero.cast("chain-lightning", chieftain)
            else:
                hero.bash(chieftain)
        else:                
            self.shield()
            
        
        if self.gold >= self.costOf("archer") and (self.pos.x < 94 or nb_tower < 1) and self.now() < 120:    
            self.summon("archer")



I get all the way to the warlocks, kill them, and then I start to collect the gems but my hero pauses when the chieftain appears.

#11

Didn’t run the code but:

def findSkeletons(enemies):
    skeletons = hero.findByType("skeleton")
    skeleton = hero.findNearest(skeletons)
    return skeleton

You never use enemies in the function and you are calling it with

skeleton = findSkeletons(hero.findEnemies)

Delete the function parameter - your will save a number of executions…

#12

Don’t forget that arrays start at 0 and you deleted points[3]? Change it back to 2 and you might start moving again.

points=[{"x":96,"y":34},{"x":278,"y":34},{"x":280,"y":34}] # deleted fourth point
# but telling hero to move there 
elif self.pos.x < 275:
            self.move(points[3]) # change to 2
#13

I actually changed it to points[1] and changed point one to 278, 34

#14

now that I fixed that stuff it is simply telling me that my code is “too slow or has an infinite loop”

#15

Found it!! :nerd_face:

I switched the points[3] to points[2] and the change below.

The combination of “and” with “or” in the same line can mess it up if you don’t have it set up correctly. I see you made a nice adjustment for the chieftain that makes it work. Copy that for the warlock and you are good to go.

elif warlock and hero.canCast("chain-lightning", warlock) or hero.isReady("bash"):
elif chieftain and (hero.canCast("chain-lightning", chieftain) or hero.isReady("bash")):

#16

If I can give badges I will grant this to :
badge

#17

It’s possible to grant it using SQL, but it’s waaaaaaay too risky.

#18

Thank you SO much!

Will try later, can’t now, but I think that is what it needs!

#19

@Ninja_Taco Just to make sure, I ran your whole code with that modification and it passed using Tharin. I may have better armor, but it should get you to the last fight with the chieftain.

@xython I greatly appreciate the support! :smiley:

I’ve found that I learn more when I’m troubleshooting/debugging code than I do actually writing it. It forces you to really understand every line of code. Also, you learn a lot of different ways to write code when you analyze someone else’s code. CodeCombat provides multiple avenues to enhance your coding knowledge and skill. I’m more than happy to take advantage of every opportunity they offer while helping others along the way.

#20

I think that putting the extra tab in the

        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
        lowestFriend = friend

at the lowestFriend = friend made my paladins inable to heal me during the beam towers
Apparently removing the tab worked, now my paladins heal me, but now the code “is too slow or has an infinite loop”
My hero freezes at
X: 147 Y: 32