Help on Mixed Units tactics python


#1

Hi, I need help on Mixed Units tactics in python. Here is my code:

# Practice using modulo to loop over an array

# Choose the mix and order of units you want to summon by populating this array:
summonTypes = ["soldier", "soldier", "soldier", "soldier", "archer", "archer", "archer", "archer"]
def summonTroops():
    # Use % to wrap around the summonTypes array based on len(self.built)
    #type = summonTypes[???]
    type = summonTypes[len(self.built) % len(summonTypes)]
def collectCoins():
    coin = hero.findNearest(hero.findEnemies())
    if coin:
        hero.move(coin.pos)
        
def commandTroops():
    friend = hero.findNearest(hero.findFriends())
    enemy = hero.findNearest(hero.findEnemies())
    if enemy and friend.type is not "palisade":
        if friend:
            hero.command(friend, "attack", enemy)
        
while True:
    summonTroops()
    collectCoins()
    commandTroops()

#2

@Awsomedude1

In your summonTroops you should be actually summoning a troop.

use:
hero.summon()


In your **commandTroops** I don't see a loop iterating through all of the troops to command them to attack. You only command the closest troop.

#3

In your summonTroops you should either do something with the chosen type of unit or return it so that the other part of your code can do something with it.

Your collectCoins has some issues - have a close look at it.