Kelvintaph crusader


#1

I look in the forum and now I can win the part with me but not the part with my allies.
Can you help me?
here is a part of my code :

loop:
    friends = self.findFriends()
    
    for friend in friends:
        enemy=friend.findNearest(friend.findEnemies())
        witch=self.findByType("witch",friend.findEnemies())
        if witch and witch.health>0:
            self.command(friend, "attack", witch)
        else:
            self.command(friend, "attack", enemy)

#2
witch=self.findByType("witch",friend.findEnemies())[0]

Now I can kill the witch but my allies don’t do anything when they have kill the witch


#3

Is there a bug in the level?


#4

I have nearly kill one of the 4 others ennemies

friend=hero.findFriends()[0]
witch=self.findByType("witch",friend.findEnemies())[0]
nb=0
loop:
    friends = self.findFriends()
    
    for friend in friends:
        enemy=friend.findNearest(friend.findEnemies())
        if witch and self.now()<2.7 and witch.health>0 and nb<4:
            self.command(friend, "attack", witch)
            enemy=friend.findNearest(friend.findEnemies())
            nb+=1
        if self.now()>3:
            friend.say("help")
            enemy=friend.findNEarestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)

please help :disappointed_relieved:


#5

command your units individually
archers
soldiers
paladin

for first stage
archers + paladin - witch
soldiers - ogres

after witch is dead
all attack nearest target

paladin must heal only self


#6

Thanks I will try it now


#7
friends=hero.findFriends()
witch=self.findByType("witch",friends[0].findEnemies())[0]
for friend in friends:
    if friend.type=="paladin" or friend.type=="archer":
        while witch.health>0:
            hero.command(friend,"attack",witch)
    elif friend.type=="soldier":
        ogre=self.findByType("ogre",friend.findEnemies())[0]
        
        hero.command(friend,"attack",ogre)
nb=0
loop:
    friends = self.findFriends()
    
    for friend in friends:
        if friend.tyep=="paladin":
            if friend.canCast("heal"):
                self.command(friend,"cast","heal",friend)
        enemy=friend.findNearestEnemy()
        if enemy:
            hero.command(friend,"attack",enemy)

This is my new code but nothing is working. : "Code never finsihIt’s either really slow or has an infinity loop"
Please help :slight_smile:


#8

Your hero must do something each cycle
if you use loop with condition

check this part cycle by cycle
it is for sure do
not what you want

if friend.type=="paladin" or friend.type=="archer":
        while witch.health>0:
            hero.command(friend,"attack",witch)
    elif friend.type=="soldier":
        ogre=self.findByType("ogre",friend.findEnemies())[0]

paladin must avoid overheal self

check

if friend.tyep=="paladin":

#9

I have seen this bugs.

while True:
    hero.debug("ok")
    friends = self.findFriends()
    for friend in friends:
        witch=self.findByType("witch",friends[0].findEnemies())[0]
        if friend.type=="paladin":
            if friend.canCast("heal"):
                n=friend.findNearest(friends)
                self.command(friend,"cast","heal",n)
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            elif friend.type=="soldier":
                ogre=self.findByType("ogre",friend.findEnemies())
                if ogre:
                    self.command(friend,"attack",friend.findNearest(ogre))
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)

I have try it but I can’t win!! And when the witch dies, the heroes are attacking the dead witch and I lost!
Please help :smile:


#10

paladin’s heal for paladin only
heal only if paladin lose more hp than heal restore to him
heal power is ~150

in each cycle will be executed only last command

place healing at the end or add some if else
So only 1 command for unit in cycle

with suggested modification your code work good enough for me

add how are your testing
where is code for hero
or you hero just stand still?)


#11

I can do the part with the hero


#12

I have do what you say but it is the same

while True:
    hero.debug("ok")
    friends = self.findFriends()
    for friend in friends:
        witch=self.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            elif friend.type=="soldier":
                ogre=self.findByType("ogre",friend.findEnemies())
                if ogre:
                    self.command(friend,"attack",friend.findNearest(ogre))
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<friend.maxHealth-150:
                    self.command(friend,"cast","heal",friend)

I don’t understand where I must place the healing
Please help :sweat:


#13

in each loop cycle will be executed only last command to your unit

loop:
self.command(friend,"attack",friend.findNearest(ogre))
self.command(friend,"cast","heal",friend)
hero.command(friend,"attack",witch)

will be executed
hero.command(friend,“attack”,witch)
only


#14

Yes than what is the problem with my code?


#15

your paladin start healing only after witch is dead

add same block to the witch stage
at the end
so healing will be executed in any case


#16

I don’t know what is happening, but my paladin is not healing

while True:
    hero.debug("ok")
    friends = self.findFriends()
    for friend in friends:
        witch=self.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            elif friend.type=="soldier":
                ogre=self.findByType("ogre",friend.findEnemies())
                if ogre:
                    self.command(friend,"attack",friend.findNearest(ogre))
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    self.command(friend,"cast","heal",friend)
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    self.command(friend,"cast","heal",friend)

With this code nothing is changing. You say that it is a good code for your interpreter? :disappointed_relieved:
Help!! :disappointed:


#17

your code work good enouth for me
the only thing you can add
is some trick
like
``
hero.cast( “chain-lightning”, “Trogdor” )

i can only suggest problem in your hero part 
if you hero just stand still do nothing 
i have no idea what is wrong

#18

Can you give me your code?


#19

Here is my entire code :

while True:
    hero.debug("ok")
    friends = self.findFriends()
    for friend in friends:
        witch=self.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            elif friend.type=="soldier":
                ogre=self.findByType("ogre",friend.findEnemies())
                if ogre:
                    self.command(friend,"attack",ogre[0])
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    self.command(friend,"cast","heal",friend)
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    self.command(friend,"cast","heal",friend)
    
    enemy = self.findNearest(self.findEnemies())
    if "Trogdor":
        hero.cast( "chain-lightning", "Trogdor" )
    else:
        hero.cast( "chain-lightning", "Rusty" )
    self.moveXY(69,15)
    self.moveXY(37,16)
    for i in range(3):
        enemy = self.findNearest(self.findByType("catapult"))
        if enemy:
            self.attack(enemy)
            
    self.moveXY(37,16)
    self.moveXY(78,14)

Now you can help me? :slight_smile:


#20

your

self.moveXY(69,15)
self.moveXY(37,16)

is block action
command chain is blocked
while they executed

recode to the move