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 + " " + pairOfNames)