# Munchkin Swarm;not enough time?

**URL:** <https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102>\
**Category:** Uncategorized\
**Created:** [March 15, 2015, 7:13pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102 "2015-03-15T19:13:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subv](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Subv](https://discourse.codecombat.com/u/Subv)\
**Post date:** [March 15, 2015, 7:13pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102/1 "2015-03-15T19:13:34Z")

</div>

So I am on munchkin swarm, and my code doesn’t have problems as far as I know, but when I use it, I don’t break the chest in time, I don’t think I can do this without like a claymore or something.

```
loop:
    enemy = self.findNearestEnemy()
    enemyDistance = self.distanceTo(enemy.pos)
    if self.isReady("cleave"):
        if enemyDistance < 10:
            self.cleave(enemy)
        else:
            self.attack(enemy)
    else self.attack("Chest")

```

code^^

---

<div class="post-metadata">

**Author:** ![Subv](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Subv](https://discourse.codecombat.com/u/Subv)\
**Post date:** [March 15, 2015, 7:19pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102/2 "2015-03-15T19:19:29Z")

</div>

after tinkering, this code works aswell`

```
loop:
    enemy = self.findNearestEnemy()
    enemyDistance = self.distanceTo(enemy.pos)
    if enemyDistance < 5:
        if self.isReady("cleave"):
            self.cleave(enemy)
    else: self.attack("Chest")

```

however i still think a time limit is stupid cause if a code works it should have enough time to work  
`

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [March 15, 2015, 7:45pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102/3 "2015-03-15T19:45:11Z")

</div>

You have a very specific task:  
Only cleave when they come close, otherwise attack the chest.  
Your first code does not accomplish this.  
Your second code does.

---

<div class="post-metadata">

**Author:** ![BrokenSyntax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brokensyntax/32/34781_2.png) [@BrokenSyntax](https://discourse.codecombat.com/u/BrokenSyntax)\
**Post date:** [March 15, 2015, 8:47pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102/4 "2015-03-15T20:47:10Z")

</div>

As J\_F\_B\_M states, the task is to attack the chest.  
This (I suspect) is to help teach us how to prioritize our operations better.  
I created a bit of code that detects how many units are nearby, and I only cleave when the number exceeds a threshold.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [March 16, 2015, 6:47pm UTC](https://discourse.codecombat.com/t/munchkin-swarm-not-enough-time/3102/5 "2015-03-16T18:47:18Z")

</div>

You should be able to attack the chest constantly except for cleaving once every 10 seconds to clear the munchkin attacks.
