# 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:
findMostLeft()
# Find the bottom right paladin with findMostBottom function:
findMostBottom()
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
x = findMostLeft.pos.x
y = findMostBottom.pos.y
# Move to the {X, Y} point from the previous step:
hero.move({x, y})
# Continue to shield while the volcano is erupting:
while True:
hero.shield()
Here, add a variable with mostLeft and mostBottom. Then change x = findMostLeft.pos.x to x = mostLeft.pos.x and change y = findMostBottom.pos.y to y = mostBottom.pos.y.
# 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:
mostLeft = findMostLeft(paladins)
# Find the bottom right paladin with findMostBottom function:
mostBottom = findMostBottom(paladins)
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
x = mostLeft.pos.x
y = mostBottom.pos.y
# Move to the {X, Y} point from the previous step:
hero.move({x, y})
# Continue to shield while the volcano is erupting:
while True:
hero.shield()
I think this is the problem. In python the things with the {} are called sets. If you look at the correct usage with move:
hero.move({"x": 56, "y": 44})
The x and the y are in brackets and the actual values go after them. So if your x and y variables are the values (like 56 and 44) where will you put them? You should have double xs and ys, two with brackets and two without.
Danny