Volcano fighters (python)

# Complete the paladin rectangle to protect the village.

# This function finds the left-most unit.
def findMostLeft(units):
    if len(units) == 0:
        return None
    mostLeft = units[0]
    for unit in units:
        if unit.pos.x < mostLeft.pos.x:
            mostLeft = unit
    return mostLeft

# This function finds the bottom-most unit:
def findMostBottom(units):
    if len(units) == 0:
        return None
    mostBottom = units[0]
    for unit in units:
        if unit.pos.y < mostBottom.pos.y:
            mostBottom = unit
    return mostBottom

paladins = hero.findByType("paladin")
# Find the top left paladin with findMostLeft function:
topleftpaladin = findMostLeft(paladins)
# Find the bottom right paladin with findMostBottom function:
toprightpaladin = findMostLeft(paladins)

# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
# Move to the {X, Y} point from the previous step:
hero.move(x, y)
# Continue to shield while the volcano is erupting:
while true:

Please explain what the error is.

You aren’t defining x or y. To define X, it would look something like this:

x = hero.distanceTo(enemy)

Hope that helps!

EDIT 1: Oh, also some of your code is different from the comments, so fix that too.


hero.move(x, y)

x and y is not defined.
??? topleftpaladin.pos.x
??? toprightpaladin.pos.y

what to add there?

x = topleftpaladin.pos.x

I think you should be able to figure out the y.