My hero summons the four soldiers and they move to the points but they dont attack and the ogres then kill one and attack the crate and then the yeti is summoned also i want to summon more than four soldiers so that i have more men to defend the crate so how do i do that heres my code
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}
while self.gold <=80:
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
for i in range(4):
self.summon("soldier")
loop:
friends = self.findFriends()
for j in range(len(friends)):
point = points[j]
friend = friends[j]
enemy = friend.findNearestEnemy()
if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
self.command(friend, "attack", enemy)
if friend:
self.command(friend, "move", point)
When you run your code, your code will command your friends to atack an eneny that meets the requirements. However, you then check for a friend. If there is, theb that friend will move to the point, overriding the attack command. Don’t use a separate if-statement; just use an else-block.
while True:
coin = hero.findNearest(hero.findItems())
if hero.gold <=80:
if coin:
hero.move(coin.pos)
2. Build 4 soldiers.
for i in range(4):
hero.summon(“soldier”)
3. Send your soldiers into position.
while True:
friends = hero.findFriends()
for j in range(len(friends)):
point = points[j]
friend = friends[j]
enemy = friend.findNearestEnemy()
if enemy and enemy.team == “ogres” and friend.distanceTo(enemy) < 5:
# Command friend to attack.
hero.command(friend, “attack”, enemy)
pass
else:
hero.command(friend, “move”, point.pos)
# Command friend to move to point.
pass