Think ahead python

Not sure why this isn’t working can someone help. It doesn’t show any error message.

# This function finds the pair of units
# with the minimum distance between them.
def findNearestPair(units):
    minDistance = 9001
    nearestPair = ["Nobody", "Nobody"]
    # You need to check and compare all pairs of units.
    # Iterate all units with indexes "i" from 0 to "len(units)".
    for i in range(len(units)):
        # Iterate all units again with indexes "j".
        for j in range(len(units)):
            # If "i" is equal to "j", then skip (continue).
            if i == j:
                continue
            i = units[i]
            j = units[j]
            # Find the distance between the i-th and j-th units.
            d = i.distanceTo(j)
            # If the distance less than 'minDistance':
            if d < minDistance:
                minDistance = d
                # Reassign 'nearestPair' to the id's
                # of the current pair of units.
                nearestPair = [i.id, j.id]
    return nearestPair


while True:
    soldiers = hero.findByType("soldier")
    # We know when the cannon shoots.
    if hero.time % 8 == 5:
        # Find which pair of soldiers in danger and protect them.
        pairOfNames = findNearestPair(soldiers)
        # Say the soldier's names and wizards will protect them.
        hero.say(pairOfNames[0] + " " + pairOfNames[1])

You could try hero.now() in place of hero.time? Sorry if I’m completely wrong, that’s just my best guess.

Or try this [units[i].id, units[j].id] in place of what you have now

Still the same. (20 chars)

Oh well. I’m not sure what else needs to be fixed.