Python: mixed unit tactics

How do I not target the palisades?

# Practice using modulo to loop over an array
# Choose the mix and order of units you want to summon by populating this array:
defendPoints = [{"x": 40, "y": 46},{"x": 40, "y": 42},{"x": 40, "y": 28},{"x": 40, "y": 24}]
summonTypes = ["soldier", "soldier", "soldier", "soldier","archer", "archer", "archer", "archer"]
def getGold():
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
def commandTroops():
    friends = hero.findFriends(unit.type == "soldier",unit.type == "archer")
    for i in range(len(friends)):
        friend = friends[i]
        defendPoint = defendPoints[i%len(defendPoints)]
        
        hero.command(friend, "defend", defendPoint)
while True:
    getGold()
    summonTroops()
    commandTroops()

you if enemy and enemy.type != "palisade" is all you need?

no, hero.attack enemy… nevermind, it should work. If it’s the friends, just friend.findNearestEnemy and not hero.

yeah but put that in the for-loop. Then it should work.

Yeah instead of defend do

friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy and friend.type != "palisade"
hero.command(friend, "attack" enemy)

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.