# Form the rectangle of units around the peasant.
# You need 2 archers and 2 soldiers.
# This function can be helpful.
def summonAndSend(type, x, y):
hero.summon(type)
unit = hero.built[len(hero.built)-1]
hero.command(unit, "move", {"x": x, "y": y})
# The rectangle should be formed around the peasant.
centerUnit = hero.findNearest(hero.findFriends())
# It's the center of the rectangle.
center = centerUnit.pos
# Also you need the height and width.
rectWidth = centerUnit.rectWidth
rectHeight = centerUnit.rectHeight
# First "soldier" to the left bottom corner of the rectangle.
leftBottomX = center.x - rectWidth / 2
leftBottomY = center.y - rectHeight / 2
summonAndSend("soldier", leftBottomX, leftBottomY)
# An "archer" to the left top corner.
leftTopX = center.x - rectWidth / 2
leftTopY = center.y + rectHeight / 2
summonAndSend("archer", leftTopX, leftTopY)
# Summon and send a "soldier" to the right top corner.
rightTopX = center.x - rectWidth / 2
rightTopY = center.y - rectHeight / 2
summonAndSend("soldier", rightTopX, rightTopY)
# Summon and send an "archer" to the right bottom corner.
rightBottomX = center.x - rectWidth / 2
rightBottomY = center.y - rectHeight / 2
summonAndSend("archer", rightBottomX, rightBottomY)
# Now hide or fight.
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
dont understand whats wrong, no error at all just dosent work
Your code looks good, except, have you tried the other hint provided in the final comment?
# Now hide or fight.
You’ve already tried fighting…
But my soldiers dont form right the archers are good but my soldiers both of them go to bottom left
Aha…sneaky. Lines 29 & 30 and 33 & 34…your addition and subtraction is a little off.
Omg im so close just about to solve it!
# Form the rectangle of units around the peasant.
# You need 2 archers and 2 soldiers.
# This function can be helpful.
def summonAndSend(type, x, y):
hero.summon(type)
unit = hero.built[len(hero.built)-1]
hero.command(unit, "move", {"x": x, "y": y})
# The rectangle should be formed around the peasant.
centerUnit = hero.findNearest(hero.findFriends())
# It's the center of the rectangle.
center = centerUnit.pos
# Also you need the height and width.
rectWidth = centerUnit.rectWidth
rectHeight = centerUnit.rectHeight
# First "soldier" to the left bottom corner of the rectangle.
leftBottomX = center.x - rectWidth / 2
leftBottomY = center.y - rectHeight / 2
summonAndSend("soldier", leftBottomX, leftBottomY)
# An "archer" to the left top corner.
leftTopX = center.x - rectWidth / 2
leftTopY = center.y + rectHeight / 2
summonAndSend("archer", leftTopX, leftTopY)
# Summon and send a "soldier" to the right top corner.
rightTopX = center.x - rectWidth / -2
rightTopY = center.y - rectHeight / -2
summonAndSend("soldier", rightTopX, rightTopY)
# Summon and send an "archer" to the right bottom corner.
rightBottomX = center.x - rectWidth / -2
rightBottomY = center.y - rectHeight / 2
summonAndSend("archer", rightBottomX, rightBottomY)
# Now hide or fight.
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
the code works each soldier and archer goes to its place… BUT either the big human dies or i die what can i do
There are different levels of difficulty when you hit the submit button. Try to submit a few times and you might get a seed that works.
Otherwise, you need to get better armor and weapons to give your hero a better chance. Also, consider retreating if you heroes health starts to get low.