Ace Of Coders Tips?

UPDATED Code


def buildArmy():
    buildOrder = ["archer", "soldier"]
    type = buildOrder[len(self.built) % len(buildOrder)]
    # update needed
    if calc("arrow-tower") == 1 and self.gold >= self.costOf(type):
        hero.buildXY(type, hero.pos.x, hero.pos.y)

def calc(TowerType):
    num = hero.built
    a = 0
    for tower in num:
        if tower.type == TowerType:
            a+=1
        
            
    return a


def commandArmy():
    #update needed
    
    friends = self.built
    enemies = self.findEnemies()
    points = self.getControlPoints()
    points2 = self.getControlPointsMap()
    for i, friend in enumerate(friends):
        point = points[i % len(points)]
        
        if point.name == "farCorner":
            point = self.getControlPointsMap()['center']
        elif point.team is self.team and friend.distanceTo(point.pos) > 10:
            point = self.getControlPointsMap()['center']
        """
        elif point.name == "center" and point.team is self.team:
            point = self.getControlPointsMap()["farA"]
        """
        if hero.now() < 120 or hero.health < 2000:
            hero.command(friend, "attack", friend.findNearestEnemy())
        else:
            hero.command(friend, "defend", point.pos)

def controlTower():
    friends = hero.findFriends()
    a = hero.findNearest(hero.findByType("artillery",friends))
    #hero.command(a, "attackPos", {"x":106, "y":48})
    enemy_artillery = hero.findNearest(hero.findByType("artillery",hero.findEnemies()))
    if a:
        if not enemy_artillery:
            hero.command(a, "attackPos", {"x":106, "y":48})

def Center(target):
    return target.distanceTo({"x":60,"y":50})

def controlHero(): 
    enemies = hero.findEnemies()
    pointsMap = hero.getControlPointsMap()
    center = pointsMap['center']
    enemy_artillery = hero.findNearest(hero.findByType("artillery", enemies))
    enemy_arrow_tower = hero.findByType("arrow-tower", enemies)
    enemy = hero.findNearestEnemy()
    
    want = ["artillery", "arrow-tower"]
    
    while hero.pos.x <= 50 or hero.pos.y <= 50:
        hero.moveXY(hero.pos.x + 2, hero.pos.y + 2)
    
    if calc("artillery") == 0:
        hero.buildXY("artillery", hero.pos.x-5, hero.pos.y-5)
    
    if calc("arrow-tower") == 0:
        hero.buildXY("arrow-tower", hero.pos.x+5, hero.pos.y+5)
    
    
    for enemy in enemies:
        #PLACE WHAT YOU WANT THE HERO TO GO OUTSIDE OF CENTER TO DESTROY/ANNHILATE INTO DUST/SMITHEREENS
        if enemy.type == "artillery":
            if Center(enemy) >= 32:
                hero.throw(enemy)
            else:
                hero.attack(enemy)
                    
        if enemy.type == "arrow-tower":
            if Center(enemy) < 32:
                hero.attack(enemy)
    
    while hero.pos.x >= 76 and hero.pos.y >= 76:
        hero.moveXY(hero.pos.x - 2, hero.pos.y - 2)
    
    if enemy and hero.isReady("stomp") and hero.distanceTo(enemy) < 15:
        hero.stomp()
        
        

def earlygame():
    points = hero.getControlPoints()
    
    #archer
    for i in range(3):
        hero.buildXY("archer", hero.pos.x+2,hero.pos.y+2)
    friends = hero.built
    
    go = ["nearA", "nearB", "center"]
    for index,friend in enumerate(friends):
        point = points[index]
        if point.name in go:
            hero.command(friend, "defend", point.pos)
    # tower
    enemys = hero.findEnemies()
    hero.buildXY("artillery", hero.pos.x-5, hero.pos.y-5)
    
 
while True:
    if hero.time < 1:
        earlygame()
    else:
        controlHero()
        buildArmy()
        commandArmy()
        controlTower()

THE LAST CODE for me this was for a comp (ONLY HAD TWO WEEKS)

def buildArmy(missiles):
    #missiles = array/list
    for i in missiles:
        if hero.distanceTo(i.targetPos) < 10:
            continue
    type = "archer"
    enemies = hero.findEnemies()
    enemyar =  [i for i in hero.findByType("artillery",enemies) if hero.distanceTo(i) < 65]
    if calc("arrow-tower") <= 0 and hero.distanceTo(pointsmap.center.pos) < 10:
        type = "arrow-tower"
    
    if calc("artillery") <= 0 or len(enemyar) >= 1:
        type = "artillery"
    
    if self.gold >= self.costOf(type):
        hero.buildXY(type, hero.pos.x, hero.pos.y)


def calc(TowerType):
    num = hero.built
    a = 0
    for tower in num:
        if tower.type == TowerType:
            a+=1
        
    return a
 

def commandArmy():
    friends = self.built
    enemies = self.findEnemies()
    enemyhero = hero.findByType("goliath")[0]
    archers = hero.findByType("archer",enemies)
    artillery = hero.findByType("artillery",enemies)
    towers = hero.findByType("arrow-tower",enemies)
    soldiers = hero.findByType("soldier",enemies)
    points = hero.getControlPoints()
    
    for i, friend in enumerate(friends):
        if hero.health < 1500 or enemyhero < 750:
            hero.attack(friend,"attack",enemyhero)
            continue
        
        if i < 2 and friend.type == "archer":
            targets = [enemyArtillery,archer,soldier,tower,enemyhero]
            for target in targets:
                if not target:
                    continue
                elif friend.distanceTo(target) <= 25:
                    hero.command(friend, "attack", target)
                else:
                    hero.command(friend, "move", points[i+1].pos)
            continue
        
        tower = friend.findNearest(towers)
        enemyArtillery = friend.findNearest(artillery)
        archer = hero.findNearest(archers)
        soldier = hero.findNearest(soldiers)
        
        if friend.type == "artillery":
            targets = [enemyArtillery,tower,archer, soldier,enemyhero]
            for target in targets:
                if not target:
                    continue
                elif friend.distanceTo(target) <= 65:
                    hero.command(friend, "attack", target)
                    break
            continue
        if friend.type == "arrow-tower":
            targets = [enemyArtillery, archer, soldier, tower, enemyhero]
            for target in targets:
                if not target:
                    continue
                elif friend.distanceTo(target) <= 30:
                    hero.command(friend, "attack", target)
                    break
            continue

def controlHero():
    enemies = self.findEnemies()
    nearestEnemy = self.findNearest(enemies)
    tower = self.findNearest(self.findByType("arrow-tower", enemies))
    if not nearestEnemy: 
        continue
    Around = self.findNearest(self.findByType("archer", enemies))
    if not Around or self.distanceTo(Around) > self.throwRange:
        Around = self.findNearest(self.findByType("artillery", enemies))
    if not Around or self.distanceTo(Around) > self.throwRange:
        Around = self.findNearest(self.findByType("arrow-tower", enemies))
    if Around and self.distanceTo(Around) < 25 and self.isReady("throw") and Around.health >= 30:
        self.throw(Around)
    elif tower and self.distanceTo(tower) < 30 and tower.distanceTo(centerPos) < 30:
        self.attack(tower)
    elif self.isReady("stomp") and self.distanceTo(nearestEnemy) < 5:
        self.stomp(nearestEnemy)
    elif self.distanceTo(centerPos) < 1 and self.distanceTo(nearestEnemy) < 5:
        self.attack(nearestEnemy)
    else:
        self.move(centerPos)


# start strategy

points = hero.getControlPoints()
pointsmap = hero.getControlPointsMap()

hero.buildXY("archer", hero.pos.x, hero.pos.y)
hero.command(hero.built[0], "move", pointsmap.nearB.pos)
hero.buildXY("archer", hero.pos.x, hero.pos.y)
hero.command(hero.built[1], "move", pointsmap.nearA.pos)
centerPos = hero.getControlPointsMap().center.pos



while True:
    enemymissiles = [i for i in hero.findEnemyMissiles() if i.type == "shell" or  i.type == "boulder"]
    
    buildArmy(enemymissiles)
    controlHero()
    commandArmy()

:slight_smile:
am also in the competition

here’s my code to consult OvO

# 三分鐘內擊敗對手
points = hero.getControlPoints()
moveOrderX = [56, 59, 61, 59, 56, 52, 50, 52]
moveOrderY = [17, 15, 11, 7, 6, 7, 11, 15]

def buildArmy():
    # 你的英雄可以召喚和命令盟友的軍隊
    if hero.health >= 3000:
        buildOrder = ["archer", "archer", "archer", "soldier", "soldier", "soldier", "artillery", "artillery"]
    else:
        buildOrder = ["artillery", "soldier", "soldier", "soldier", "soldier", "soldier"]
    type = buildOrder[len(hero.built) % len(buildOrder)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
    
def commandArmy():
    mh = 0
    badGuy = None
    points = hero.getControlPoints()
    enemies = hero.findEnemies()
    nearestEnemy = hero.findNearest(enemies)
    for i, enemy in enumerate(enemies):
        if enemy.health > mh:
            mh = enemy.health
            badGuy = enemy
    friends = hero.built
    enemies = hero.findEnemies()
    points = hero.getControlPoints()
    for i, friend in enumerate(friends):
        if friend.health <= 0 or friend.type == "arrow-tower":
            continue
        # 命令你的軍隊奪取控制點
        # 明智的選擇你的控制點!
        elif friend.type == "artillery":
            hero.command(friend, "attack", badGuy)
        elif friend.type == "archer":
            if i <= 10 and hero.health >= 5000:
                hero.command(friend, "defend", points[i % 2 + 1].pos)
            else:
                if friend.distanceTo(friend.findNearest(enemies)):
                    hero.command(friend, "move", {"x" : friend.findNearest(enemies).pos.x - 30, "y" : friend.findNearest(enemies).pos.y - 30})
                hero.command(friend, "attack", badGuy)
        elif friend.type == "soldier":
            if i <= 10 and hero.health >= 5000:
                hero.command(friend, "defend", points[i % 2 + 1].pos)
            else:
                hero.command(friend, "attack", badGuy)

    
def controlHero():
    mh = 0
    badGuy = None
    points = hero.getControlPoints()
    enemies = hero.findEnemies()
    nearestEnemy = hero.findNearest(enemies)
    for i, enemy in enumerate(enemies):
        if enemy.maxHealth > mh:
            mh = enemy.maxHealth
            badGuy = enemy
    shouldAttack = hero.health < 6000
    # 用你的英雄技能來改變局勢。
    if shouldAttack:
        if hero.distanceTo(badGuy) <= 15:
            hero.stomp()
        else:
            pass
        for i in range(20):
            hero.attack(badGuy)

while True:
    buildArmy()
    commandArmy()
    controlHero()

hopes it can help u

wait wait are u the no.72 guy?
just a guess

Nah the results ain’t published

It’s a code quest comp

It’s finished it’s done i can finally rest

yes yes i’m inside
the 94th guy
just tentative

but mine is over 20 chars must burn