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

**URL:** <https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207>\
**Category:** Ambassador\
**Created:** [November 3, 2020, 11:37pm UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207 "2020-11-03T23:37:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 3, 2020, 11:37pm UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/1 "2020-11-03T23:37:59Z")

</div>

Reading @jka2706  
[![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/807bfaa6d99f327070d5cab77f78c3fe6e8d5506.png) ](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/8/807bfaa6d99f327070d5cab77f78c3fe6e8d5506.png)  
and following the path given in [Restless dead - it's restless - #18 by xython](https://discourse.codecombat.com/t/restless-dead-its-restless/16228/18)

```python
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:

```python
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**:

 ![summit-gate-01](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/e/0/e022b20070b2f295b632f8008845d9c63bf4b35a.gif)

- 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

 ![summit-gate-05](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/b/0bbde85065c9ce051a8ca4ee12c8fa352ac628fc.gif)

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`

---

<div class="post-metadata">

**Author:** ![cheddarcheese](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cheddarcheese/32/22417_2.png) [@cheddarcheese](https://discourse.codecombat.com/u/cheddarcheese)\
**Post date:** [November 4, 2020, 1:45am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/2 "2020-11-04T01:45:07Z")

</div>

how do you stop warlocks from spawning?

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [November 4, 2020, 9:39am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/3 "2020-11-04T09:39:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 10:20am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/5 "2020-12-22T10:20:20Z")

</div>

what is wrong with my code this is the code:

```python
# 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

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 10:44am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/6 "2020-12-22T10:44:17Z")

</div>

Why did you write Paladin’s heal two times?

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:02am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/7 "2020-12-22T11:02:57Z")

</div>

is that where it goes wrong?

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 11:03am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/8 "2020-12-22T11:03:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:05am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/9 "2020-12-22T11:05:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 11:06am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/10 "2020-12-22T11:06:15Z")

</div>

> [@stefan\_grecu](#):
>
> `for enemy in enemies:`

Here?

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:06am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/11 "2020-12-22T11:06:41Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 11:10am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/12 "2020-12-22T11:10:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:12am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/13 "2020-12-22T11:12:06Z")

</div>

![problem](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/0/a050d32a0f4c85c5e7817eb8ba6fe432f13b65ae.png)

i made a screen shot

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:12am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/14 "2020-12-22T11:12:39Z")

</div>

i will try it

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 11:12am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/15 "2020-12-22T11:12:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:17am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/16 "2020-12-22T11:17:33Z")

</div>

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()
```

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:19am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/17 "2020-12-22T11:19:46Z")

</div>

do i need another hero instead of Tharin

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [December 22, 2020, 11:20am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/18 "2020-12-22T11:20:03Z")

</div>

What heroes do you have?

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:21am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/19 "2020-12-22T11:21:48Z")

</div>

Tharin,Amara,Hushbaum and Ritic

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [December 22, 2020, 11:25am UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/20 "2020-12-22T11:25:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 22, 2020, 1:39pm UTC](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207/21 "2020-12-22T13:39:23Z")

</div>

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

[Next page](https://discourse.codecombat.com/t/jennys-method-stacking-while-true-loops-summit-gate/25207.md?page=2)
