[SOLVED] Bank Raid Help?


#1

I’ve been stuck on this level for a day and I don’t know how to solve it. Here is my code.

while True:
    enemies = hero.findEnemies()
    # enemyIndex is used to iterate the enemies array.
    enemyIndex = 0
    # While enemyIndex is less than len(enemies)
    while enemyIndex < len(enemies):
        # Attack the enemy at enemyIndex
        enemy = enemies[enemyIndex]
        hero.attack(enemy)
        # Increase enemyIndex by one.
        enemyIndex += 1
    coins = hero.findItems()
    # coinIndex is used to iterate the coins array.
    coinIndex = 0
    while coinIndex < len(coins):
        # Get a coin from the coins array using coinIndex
        coins = hero.findNearestItem()
        coin = coins[coinIndex]
        # Collect that coin.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Increase coinIndex by one.
        coinIndex += 1


#2

It’s because you’ve said

That doesn’t make any sense if you think about it.
And you’ve got to check if there’s a coin.
Your code is correct apart from that though.


#3

I’ve fixed it but my hero is not collecting the coin he only attacks the enemy.

Fixed code seems to be working so removed by mod

#4

Ugly patch to make your code working. But there is something wrong with the level default code…

        enemy = enemies[enemyIndex]
        while enemy and enemy.health > 0: # put this line 
            hero.attack(enemy)

#5

This code works for me, I used Anya with obsidian armour and claymore, because that’s what I had at the time. What equipment are you using?
@xython I don’t see any problem?


#6

The armor is a little bit extreme but the level passes with the correction and fails without it. I think the default code is not the best…


#7

This is my equipment
42


#8

I don’t see a problem with the body armor. Try replacing the sword with another better one, because that sword is pretty slow and weak


#9

I only have 47 gems.


#10

Can I see the list of swords you currently have?


#11

Hero you go
25


#12

Use the other one, since @xython managed to beat this level with the simple one, the other sword should do just fine, since you also have great amounts of HP. I haven’t gotten on codecombat in a while, so I forgot the name of the sword. Try using the sword with a short blade.


#13

The sharped sword did not work at all. :frowning:


#14

@ Sharknado - I passed the level with the sword and armor on my picture - did you try to correct your code?
@ Chaboi_3000
There are 2 problems with the default code:

#1
    while enemyIndex < len(enemies):
        # Attack the enemy at enemyIndex
        enemy = enemies[enemyIndex]
        hero.attack(enemy)
        # Increase enemyIndex by one. 

        # Why increasing the index if you are not sure the enemy is dead

        enemyIndex += 1
while coinIndex < len(coins): 
# an so on

You start to collect coins but are you sure there are no enemies? They can chase you an hit you in the back
He needs no better armor or sword - only to put a line of extra code.


#15

@xython I did use the armor that you used and the sword but it attacked the enemy and stayed in the same spot to attack the enemy


#16

Sometimes, code isn’t just what they give you, sometimes you have to manipulate and shift and change the code a bit, until you get the code that’s working for you, and yes, there’s some errors in codecombat that isn’t fixed yet, and sometimes, you’ll have to deal with it, and fix it yourself! Equipment is just to make the game easier. Nick managed to do great with his Tharin against many opponents, So if you try, you can do anything with code. :wink: