The Trials Help!

oh!! Thanks for the help!

I can get past the first round of combat and collect all the mushroom and every thing but can’t get to the next trial here is my code
loop {
var flag = this.findFlag();
var enemy = this.findNearestEnemy();
if (flag) {
this.pickUpFlag(flag);
this.cast(“summon-undead”);
} else if (enemy) {
this.cast(“drain-life”, enemy);
}
}
can someone telll me what I am doing wrong

Why are you not just simply attacking instead of throwing complicated spells?

Hi, i am success this level using loop break and wait :wink:

I beat it, but I have 1100 + health. I’m using the Great Sword, Enameled Dragonplate and the Steel Striker, and I beat it first try. Here’s my code.

while (true){
var enemy = hero.findNearestEnemy();
var item = hero.findNearestItem();

    if (enemy) {
        if (hero.isReady("bash")) {
            hero.bash(enemy);
        } else {
            hero.attack(enemy);
        }
    } else if (item) {
        hero.moveXY(item.pos.x, item.pos.y);
    }

var flag = hero.findFlag();
if(flag){
    hero.pickUpFlag(flag);
}

}

This is a dead topic from 2015. Please do not reply as this will bump this up to the front page

1 Like

Also please do not give out the code. It makes it easier for a person to just get the code. and pass the level without learning anything. Codecombat is a learning game. Read the FAQ before further posting!!

help! i can’t solve this!!!
here is my code:

enemy_types = {}
enemy_types[‘oasis-guardian’] = {‘danger’: 10, ‘focus’: 315}
enemy_types[‘shaman’] = {‘danger’: 10, ‘focus’: 10}
enemy_types[‘warlock’] = {‘danger’: 10, ‘focus’: 10}
enemy_types[‘arrow-tower’] = {‘danger’: 10, ‘focus’: 10}
enemy_types[‘burl’] = {‘danger’: 10, ‘focus’: 5}
enemy_types[‘witch’] = {‘danger’: 8, ‘focus’: 10}
enemy_types[‘brawler’] = {‘danger’: 7, ‘focus’: 10}
enemy_types[‘ogre’] = {‘danger’: 5, ‘focus’: 10}
enemy_types[‘chieftain’] = {‘danger’: 6, ‘focus’: 10}
enemy_types[‘fangrider’] = {‘danger’: 4, ‘focus’: 22}
enemy_types[‘skeleton’] = {‘danger’: 5, ‘focus’: 22}
enemy_types[‘scout’] = {‘danger’: 4, ‘focus’: 22}
enemy_types[‘thrower’] = {‘danger’: 3, ‘focus’: 22}
enemy_types[‘munchkin’] = {‘danger’: 2, ‘focus’: 15}

if hero.team == ‘humans’:
team = ‘humans’
else:
team = ‘ogres’

def findTarget():
danger = 0
enemy_return = None
for type in enemy_types.keys():
if enemy_types[type] and enemy_types[type].danger > danger:
enemy = hero.findNearest(hero.findByType(type))
if enemy and enemy.team != team and hero.distanceTo(enemy) < enemy_types[type].focus:
enemy_return = enemy
danger = enemy_types[type].danger
if enemy_return is None:
enemy_return = hero.findNearestEnemy()
return enemy_return

summonTypes = [ ‘paladin’, ‘paladin’, ‘paladin’, ‘griffin-rider’, ‘griffin-rider’]

def moveTo(position, fast=True):
if (hero.isReady(“jump”) and hero.distanceTo(position) > 10 and fast):
hero.jumpTo(position)
else:
hero.move(position)

def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)

def commandTroops():
for friend in hero.findFriends():
if friend.type == ‘paladin’:
CommandPaladin(friend)
elif friend.type == ‘soldier’ or friend.type == ‘archer’ or friend.type == ‘griffin-rider’:
CommandSoldier(friend)
elif friend.type == ‘peasant’:
CommandPeasant(friend)

def CommandSoldier(soldier):
hero.command(soldier, “defend”, hero)

def CommandPeasant(soldier):
item = soldier.findNearestItem()
if item:
hero.command(soldier, “move”, item.pos)

def CommandPaladin(paladin):
lowestFriend = lowestHealthFriend()
if (paladin.canCast(“heal”) and hero.health < hero.maxHealth / 5):
hero.command(paladin, “cast”, “heal”, self)
elif lowestFriend and lowestFriend.health < lowestFriend.maxHealth / 3:
hero.command(paladin, “cast”, “heal”, lowestFriend)
else:
hero.command(paladin, “defend”, hero)

def lowestHealthFriend():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for f in friends:
if f.health < lowestHealth and f.health < f.maxHealth:
lowestHealth = f.health
lowestFriend = f
return lowestFriend

def attack(target):
if not target:
target = findTarget()
if target:
if (hero.distanceTo(target) > 50):
moveTo(target.pos)
elif hero.isReady(“chain-lightning”):
hero.cast(“chain-lightning”, target)
elif hero.isReady(“bash”):
hero.bash(target)
else:
hero.attack(target)

enemyHero = [e for e in self.findEnemies() if e.id in [“Hero Placeholder”, “Hero Placeholder 1”]][0]

while True:
summonTroops()
commandTroops()
e = hero.findNearestEnemy()
item = hero.findNearestItem()
if e and hero.distanceTo(e) < 50:
attack(e)
elif item:
moveTo(item.pos)
elif hero.now() < 80:
moveTo({“x”:110, “y”:23})
elif hero.now() < 145:
moveTo({“x”:37, “y”:129})
elif hero.now() < 190:
moveTo({“x”:116, “y”:116})
else:
moveTo({“x”:96, “y”:63})

how do you make your code look normal???

when you post your code click this icon and follow the instruction
the icon
image