How can I not use flags?


#1

Level: Summit’s gate

So my computer lags a lot, so most of the times, I can’t get past the 2nd one. How can I automate it?

def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    if self.health < 1200:
        lowestFriend = self;
        
    return lowestFriend
    
def commandFriends():
    # Command your friends.
    nearestEnemy = self.findNearest(self.findEnemies())
    friends = self.findFriends()
    blackFlag = self.findFlag("black")
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        elif blackFlag:
            self.command(friend, "attack", nearestEnemy)
        else:
            self.command(friend, "defend", self.pos)

def commandPaladin(paladin):
    # Heal the paladin with the lowest health using lowestHealthPaladin()
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    
    lowestFriend = lowestHealthPaladin()
    healingThreshold = 0.8 * paladin.maxHealth
    warlocks = self.findByType('warlock')
    nearestWarlock = paladin.findNearest(warlocks)
    nearestEnemy = paladin.findNearest(self.findEnemies())
    if lowestFriend and paladin.canCast('heal') and lowestFriend.health < healingThreshold:
        self.command(paladin, 'cast', 'heal', lowestFriend)    
        
    else:        
        self.command(paladin, 'defend', self.pos)
        
self.attack("Catapult 1")
self.attack("Catapult")

loop:
    commandFriends()
    enemy = self.findNearest(self.findEnemies())
    flag = self.findFlag()
    if flag:
        if flag.color is "green":
            self.pickUpFlag(flag)
        else if flag.color is "black":
            self.attack(enemy)
            self.pickUpFlag(flag)
        if flag.color is "violet":
            while self.costOf("archer") < self.gold:
                self.summon("archer")
            self.pickUpFlag(flag)

#2

do flag = self.findFlag('green')
or flag1 = self.findFlag('black')


#3

This code puts an “autoflag” every 5 seconds for your character to move to

flags=[ {'x':10,'y':20},{'x':20,'y':20},{'x':30,'y':10}]

autoflagpos= None;
flag_number=0
flag_time=0
def generateFlag():
     if self.now() > (flag_time+5):
          autoflagpos=flags[flag_number]
          flag_number+=1
          flag_time=self.now()
# yeah, it will error once it reaches the end of the flag list. 
#But you can fix that :) 

loop:
    generateFlag()
    if autoflagpos:
           self.moveXY(autoflag.pos.x,autoflag.pos.y)
           autoflagpos=None
#end loop

In your level you have to decide when you need to put the flag:

  • when all the catapults are dead:
    if len(catapults) == 0:
  • when an enemy is killed:
    if enemy.health < 0:
  • when time passed:
if self.now() > 30 and not flagraised30:
       autoflagpos= ....
       flagraised30= True
  • when you are past a certain point
if self.pos.x > 50 and not flagraised50:
      autoflagpos = ...
      flagraised50= True

And so on …

The flagraised variables are to make sure you only set the flag once.
Initially, you set flagraised varibles to False. When you set the flag the corresponding variable will become True so you will never enter that if again and you will never set that flag again.