Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Python minesweeper - character keeps moving back to the same spot


Hi! Just started Code Combat a couple days ago and it’s awesome! I’m having trouble with a couple levels though and I’m not sure what I’m doing wrong.

In the level minesweeper you have to move to an item (gold) and set off the mines, but for me the character moves to the first gold piece then stops. When I run this the code gets stuck on line 18 and just keeps moving back to that same spot, rather than finding a new item. I’ve even tried adding a moveXY command after to help the character find the next gold piece, but it holds onto that first set of coordinates and moves back.

Any advice?

# Lead the peasants and healer through the minefield.
# Move to the coins to trigger the fire traps.
# The mines are randomized, so use findItems.
# Move back 10m and ask for a "heal" if your health is low.

item = self.findNearest(self.findItems())
healthlow = < self.maxHealth / 3
healthhigh = > self.maxHealth / 3
x = self.pos.x
y = self.pos.y

    if item:
        itemPos = item.pos
        itemx = itemPos.x
        itemy = itemPos.y
    elif healthlow:
        self.say("One heal please!")


Figured it out, I didn’t realize all the items listed at the top had to be inside the loop.