# Almost Perfect Minefield Help

My hero isn’t going to the nearest corrected position, and also when I’m jumping my peasants are getting pushed.

My loops are supposed to go column by column, but it seems that it’s not happening.

``````# Escape from the minefield.
# You need to pass the marked line. (x = 72).

trapDistance = 6
trapRange = 2

def findNearestHazard(gridPos):
position = Vector(gridPos.x, gridPos.y)
nearestDist = 9999
nearestHazard = None
for hazard in hero.findHazards():
dist = hazard.distanceTo(position)
if hazard.distanceTo(position) < nearestDist:
nearestHazard = hazard
nearestDist = dist
return nearestHazard

# Jump, Jump, JUMP!!!

allPositions = []
while True:
for x in range(4, 64, trapDistance):
for y in range(4, 64, trapDistance):
position = Vector(x, y)
hazard = findNearestHazard(position)
if hazard and hazard.distanceTo(position) > 1:
allPositions.append(position)
if hero.pos.x > 52:
hero.jumpTo(Vector(80, hero.pos.y))
elif allPositions and allPositions[-1] is not None:
hero.jumpTo(allPositions[-1])
``````

someone pls help me on this

the distance between the safe spots is 12, also you can go diagonally as well, the loops are happening, just you’re not doing it right, what I recommend you do is make an array of every position without a mine, and keep finding the nearest one that you haven’t visited yet

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.