Zoo Keeper - code freezing/looping/crashing (Python) (Solved)

Apologies, but I’m going to dump my full code here. I can’t tell what’s happening - I’m freezing before the first 4 are summoned. [Update: I reloaded the level completely, recoded it (in some slightly different ways) and won. Sigh. Still no clue what went wrong with the below.

# Protect the cage.
# Put a soldier at each X.
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}

# 1. Collect 80 gold.
while self.gold < 80:
    coin = self.findNearest(self.findByType("coin"))
    if coin:
        self.move(coin.pos)
# 2. Build 4 soldiers.
countX = 0
while countX < 4:
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    countX = countX + 1

# 3. Send your soldiers into position.
loop:
    friends = self.findByType("soldier", self.findFriends())
    PtCounter = 0
    counter = 0
    while counter < len(friends):
        point = points[PtCounter]
        friend = friends[counter]
        self.command(friend,"move",point)
        counter = counter + 1
        PtCounter = PtCounter + 1
        if PtCounter > 3:
            PtCounter = 0
    counter = 0
    friends = self.findByType("soldier", self.findFriends())
    while counter < len(friends):
        friend = friends[counter]
        enemy = friend.findNearestEnemy()
        if enemy:
            if enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            # Command friend to attack.
                self.command(friend, "attack", enemy)
    coinCount = self.gold
    while coinCount = self.gold:
        coin = self.findNearest(self.findbyType("coin")
        if coin:
            self.move(coin.pos)
        else:
            coinCount = coinCount - 1
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")

Sigh … now it is happening on noble sacrifice. Code below. I’m being told it is either slow or has an infinite loop. $!#@ if I can see it.

[Ugh - disregard. There was a single while loop that was hanging. :frowning: ]

For anyone interested:

This sounds like a predestined HEL (Hard Execution Limit).

while self.gold < 80:
    coin = #blabla
    if coin:
        self.move(coin.pos)

And if there is no coin? Then this loops repeats infinitely often until 300000 Executions are hit (the current HEL). Then you’re code will abort as it is assumed it will never finish.

Wait, what are you supposed to do about it???