# Complete the paladin rectangle to protect the village.
paladins = hero.findByType("paladin")
# 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
# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
if len(units) == 0:
return None
mostTop = units[0]
units = findMostLeft(units)
for unit in units:
if unit.pos.y > mostTop.pos.y:
mostTop = unit
topLeft = mostTop
return topLeft
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
if len(units) == 0:
return None
mostRight = units[0]
findMostBottom(units)
for unit in units:
if unit.pos.x > mostRight.pos.x:
mostRight = unit
bottomRight = mostRight
return bottomRight
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
if paladins:
coordX = findTopLeft(paladins).pos.x
coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while true:
hero.shield()
# Complete the paladin rectangle to protect the village.
paladins = hero.findByType("paladin")
# 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
# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
if len(units) == 0:
return None
mostTop = units[0]
units = findMostLeft(units)
for unit in units:
if unit.pos.y > mostTop.pos.y:
mostTop = unit
topLeft = mostTop
return topLeft
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
if len(units) == 0:
return None
mostRight = units[0]
findMostBottom(units)
for unit in units:
if unit.pos.x > mostRight.pos.x:
mostRight = unit
bottomRight = mostRight
return bottomRight
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
if paladins:
coordX = findTopLeft(paladins).pos.x
coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while true:
hero.shield()
there is an error (dosent say what line) that says: "TypeError: Need an object what is wrong @AnSeDra@dedreous@Deadpool198 are any of u able to help?
There is no need to create a new function (findTopLeft), as you’ve already done that work. Instead, define a new variable as equal to the existing function.
Same goes for ‘findBottomRight’.
Delete the ‘if paladins:’ line, then correct your two coord statements.
# Complete the paladin rectangle to protect the village.
paladins = hero.findByType("paladin")
# 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
# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
if len(units) == 0:
return None
mostTop = units[0]
units = findMostLeft(units)
for unit in units:
if unit.pos.y > mostTop.pos.y:
mostTop = unit
topLeft = mostTop
return topLeft
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
if len(units) == 0:
return None
mostRight = units[0]
findMostBottom(units)
for unit in units:
if unit.pos.x > mostRight.pos.x:
mostRight = unit
bottomRight = mostRight
return bottomRight
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
coordX = findTopLeft(paladins).pos.x
coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while True:
hero.shield()