Ok now I really need help! The level is Summit's Gate

Here is 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("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")

It say’s code never finished or has infinite loop!

@Lydia_Song and/or @JoPro_8000???

Oh jeez, uhh, whats your armor and strategy right now?

what do you mean strategy???

here is my armor:

You’ll want to equip flags, I find flags quite useful in these levels.
Mind telling me what is your strategy right now?

what do you mean strategy?

Like what is your plan to pass this level

ummm kill the ogre???

Uhh more specifically?

my plan is to keep on attacking and spawning archer’s when I have enough gold to survive through the level.

Hi Lydia, everything is Ok, the solution is simple and the code is copied from the net

2 Likes

How do you know that?

Copy and paste a small part of the code into google and see if a github code pops up

1 Like

The first two sites that pop up are from the discourse, the third one is from GitHub.

Yep thats how you know

don’t copy code from internet.From my experience, it works only 60% of the time.I was copying it when I started to play CoCo, but then I found out it is trash(code).

2 Likes

Plus it’s cheating. And that is always bad.

I know but I’m was stuck for almost a week

I’ve seen people who’ve been stuck for months.

1 Like