Jenny's method - stacking while true loops: Summit Gate

Reading @jka2706

and following the path given in Restless dead - it's restless - #18 by xython

As a tip for any level without a default code:
1. Make a plan and break it into pieces
2.Choose a free hero (for complex ones you have more opportunities for mistakes)
3.Solve the problem step by step

I tried to complete Summit gate without casualties.
I have Twilight glasses so i ran this code:

var es = hero.findEnemies();
for (var i = es.length; --i > -1;){
    var e = es[i]; 
    console.log("e#" + i + " " + e.type + " " + e.id + ": " + e.health + e.pos );
}  
// console output: 
// e#30 door Sanctum Gate: 600{x: 288.00, y: 32.75, z: 4.00} 
// e#29 door Inner Gate: 300{x: 158.00, y: 32.75, z: 4.00} 
// e#28 door Outer Gate: 300{x: 100.00, y: 33.25, z: 4.00}
// e#19 catapult Catapult 1: 140{x: 92.18, y: 6.84, z: 1.00}
// e#0 catapult Catapult: 140{x: 92.10, y: 60.30, z: 1.00}
// + many enemies
  • So my first goal was to:
  • Destroy the catapults
  • Defeat the enemies , but without destroying the door
  • Summon archers
  • Heal the hero
    As a break condition i use the fact there are 3 enemies remaining, The Outer , The Inner and The Sanctum gates

/Click on the gifs to see animation/

This was my first while(true) loop:

  • Destroy Outer Gate

  • Destroy the beam towers

  • Defeat the enemies , but without destroying the door

  • Heal the hero

  • Break condition: 2 gates remaining
    Second loop:

  • Destroy Inner Gate

  • Command the warriors between The Inner and The Sanctum Gate to defeat the nearby enemies

  • All paladins , archers and the hero to gather at some point without attacking the warlocks

  • Break condition: 1 gate and 2 warlocks remaining, all units ready to fight at predefined positions
    Third loop:

  • Defeat all enemies

  • Collect coins

  • Hide archers and paladins

  • Heal hero

  • Break condition: 1 gate remaining
    fourth loop - no animation available , cannot squeeze video to 4MB, only pictures:



Fifth loop : pass the level

I checked the solutions in the Leader Board for 2 days to see how the recent users have completed the level. So my findings are:
From 18 successful submissions:
2 users have solved the level without flags.
2 users have solved the level with flags.
1 level doesn’t work
1 level fails with Infinite Loop Detected
12 users have the same code stolen from internet
No Comment

9 Likes

how do you stop warlocks from spawning?

Nice to be name checked in the title, but I don’t think I should get any credit.

Thanks for the post @xython, it’s a lovely structure, and I always learn stuff from the things that you write.

Interesting stats for how people complete the level. Too many questions, but perhaps your ‘No comment’ is wisest.

J.

3 Likes

what is wrong with my code this is the code:

# Vecht je weg in het Binnenste Heiligdom van het ogre-opperhoofd, en versla haar. 
while True:
    paladins = []
    enemy = hero.findNearestEnemy()
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin": 
            paladins.append(paladin)
    for enemy in enemies:
        if enemy.type == "catapult":
            while enemy.health > 0:
                hero.attack(enemy)
        friends = hero.findFriends()
        for friend in friends:
            e = friend.findNearestEnemy()
            if e:
                hero.command(friend, "attack", e)
    fire = hero.findNearestEnemy()
    if fire:
        while fire.health > 0:
            hero.attack(fire)
        if fire.type == "tower":
            pass
        if hero.pos.x > 160:
            hero.moveXY(175, 35)
            hero.moveXY(175, 8)
            hero.moveXY(245, 14)
            hero.moveXY(245, 35 )
            while hero.health < hero.maxHealth:
                hero.moveXY(245, 35)
                if hero.gold > hero.costOf("griffin-rider"):
                    hero.summon("griffin-rider")
                paladin = hero.findByType("paladin")
                for paladin in paladins:
                    if paladin:
                        if paladin.canCast("heal",paladin):
                            hero.command(paladin, "cast", "heal", hero)
            if hero.maxHealth <= hero.health:
                if fire:
                    hero.moveXY(277, 34)
                    hero.moveXY(277, 5)
                    DJ = hero.findNearestEnemy()
                    if DJ:
                        while DJ.health > 0:
                            hero.attack(DJ)
                        hero.moveXY(277, 48)
                        lie = hero.findNearestEnemy()
                        if lie:
                            while lie.health > 0:
                                hero.attack(lie)
                        while True:
                            paladins = hero.findByType("paladin")
                            for paladin in paladins:
                                if paladin:
                                    if paladin.canCast("heal", paladin):
                                        hero.command(paladin, "cast", "heal", hero)
                            n00B = hero.findNearestEnemy()
                            if n00B:
                                hero.attack(n00B)

can somebody pls say what is wrong

Why did you write Paladin’s heal two times?

is that where it goes wrong?

I don’t know, maybe you know? This is why I asked.

the code problem is at line 11
maybe you know what is wrong there

Here?

yes

Maybe because you wrote enemy = hero.findNearestEnemy() instead of enemies = hero.findEnemies() Because you write a for.

problem

i made a screen shot

i will try it

Okay you can write for enemy in hero.findEnemies():

i always die at the beam tower
and did you mean this:

for enemy in hero.findEnemies():
    if enemy.type == "catapult":
        while enemy.health > 0:
            hero.attack(enemy)
    friends = hero.findFriends()

do i need another hero instead of Tharin

What heroes do you have?

Tharin,Amara,Hushbaum and Ritic

but mostly i use Tharin the other ones (instead of Ritic) use in them for extra levels

you can use any hero as long as you have decent health and a good strategy