In the toil and trouble level i have been having problems succeeding. i Have tried two methods and neither work.
the first is to tell them to attack nearest enemy
# Ogre Witches have some unpleasant surprises ready for you.
# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
archers = hero.findByType("archer")
for archer in archers:
aenemy = archer.findNearestEnemy()
hero.command(archer, "attack", aenemy)
soldiers = hero.findByType("soldier")
for soldier in soldiers:
Senemy = soldier.findNearestEnemy()
hero.command(soldier, "attack", Senemy)
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
chooseTarget()
pass
the second is to have the soldier attack the witches
this has the desired effect but 2 problems
1 the ogers kill the soldiers before they get to the witches
2 it is really slow
# Ogre Witches have some unpleasant surprises ready for you.
# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
archers = hero.findByType("archer")
for archer in archers:
aenemy = archer.findNearestEnemy()
hero.command(archer, "attack", aenemy)
soldiers = hero.findByType("soldier")
for soldier in soldiers:
Senemys = soldier.findEnemies()
for senemy in Senemys:
if senemy.type == "witch":
hero.command(soldier, "attack", senemy)
done = 1
if done == 0:
senemy2 = soldier.findNearestEnemy()
hero.command(soldier, "attack", senemy2)
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
chooseTarget()
pass
here is the code adapted to your idea
the soldiers attack witches
and the archers attack ogres or if no ogres defend a point in the middle
# Ogre Witches have some unpleasant surprises ready for you.
# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
archers = hero.findByType("archer")
for archer in archers:
aenemy = archer.findNearestEnemy()
if aenemy.type == "ogre":
hero.command(archer, "attack", aenemy)
else:
hero.command(archer, "defend", {'x':39,'y':39})
soldiers = hero.findByType("soldier")
for soldier in soldiers:
Senemys = soldier.findEnemies()
for senemy in Senemys:
if senemy.type == "witch":
hero.command(soldier, "attack", senemy)
done = 1
if done == 0:
senemy2 = soldier.findNearestEnemy()
hero.command(soldier, "attack", senemy2)
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
chooseTarget()
pass
i did that the archers kill throwers than try to kill ogres meanwhile the soldiers go for the witches are kill by the ogres and then the witches kill archers
if friend and friend.type is "soldier" and enemy and witch and witch.health > 0:
hero.command(friend, "attack", witch)
if friend and friend.type is "archer" and enemy:
self.command(friend, "attack", enemy)