Grid Minefield Help!

Hi I need help for this level

# The ogre formation is marching at the village.
# We have 90 seconds to build a minefield.
# We'll use their strict formation against them.

# Use nested loops to build the grid minefield.
# First iterate x coordinates from 12 to 60 with step 8.
for x in range(12, 12 + 8 * 6, 8):
    # For each x iterate y cordinates from 12 to 68 with step 8.
    for y in range(12, 12 + 8 * 7, 8):
        # For each point build "fire-trap" there.
        hero.buildXY("fire-trap", x, y)
        pass
    # After each column, it's better to move right to avoid own traps.
    hero.moveXY(hero.pos.x + 8, hero.pos.y)

# Now wait and watch the coming ogres.
# When they are near (about 20 metres from the hero) blow mines with your hero.
# Just move at the nearest mine when it's the time.
enemy = hero.findNearest(hero.findEnemies())
if enemy and hero.distanceTo(enemy) <= 20:
    hero.move


# Now wait and watch the coming ogres.
# When they are near (about 20 metres from the hero) blow mines with your hero.
# Just move at the nearest mine when it's the time.
if hero.time >= 90:
    hero.moveXY(54, 53)

link = https://codecombat.com/play/level/grid-minefield?

this would make a array I used findNearestEnemy

where are you going to move to

you donèt need this

and wrap this in a while true loop

2 Likes

Because it’s hero.findNearest() it does actually return a single enemy. It’s the same as hero.findNearestEnemy().
As you said the only problem is the lack of looping around one of your last two sections. It doesn’t matter which one you use, but it needs to be looped otherwise it will only run once, and its conditions will not be fulfilled so you won’t move anywhere.

2 Likes

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