Stranded in the Dunes help (python)

while True:
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("black")
    if flag:
        hero.moveXY(flag.pos.x, flag.pos.y)
        hero.pickUpFlag(flag)
    elif enemy and enemy.type != "sand-yak":
        if hero.isReady("throw"):
            hero.throw(enemy)
        elif hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        elif hero.canCast("counter-blast", enemy):
            hero.cast("counter-blast", enemy)
        else:
            hero.scattershot(enemy)

sooooo, my hero just keeps dying to the sand-yaks, not the skeleton itself
help please?
linkity link

1 Like

Hello, do you have an error in the code? which? could you share a screenshot, please

Hello, I will share my code in javascript, this will be useful to correct yours or if you manage to get something better let me know, this is very useful for feedback. :smiley:

[Solution removed by moderator]

Use the append function.
What it does, is add something into an array.
You can loop thru all the enemies, and if its not a yak, add it to an array.
Find the nearest in the array. :slight_smile:
Here is how to use append.

friends = hero.findFriends()
archers = []
soldiers = []
paladins = []
for friend in friends:
    if friend.type == 'soldier':
        soldiers.append(friend)
    if friend.type == 'archer':
        archers.append(friend)
    if friend.type == 'paladin':
        paladins.append(friend)

Just loop thru all enemies, if not sand yak, append it to an array.
Find the nearest in the array, then attack.

We can’t share solutions because it’s cheating if others use it.

1 Like

Use flags to move away from the yaks, or does the hero just move to them?

2 Likes

That isn’t a solution.
I’m just trying to teach her how to use append, since she maybe doesnt know how to use it.
I will change that code though.

Matignacio gave the finished code, and that means anyone can look at it and pass the level, which means its cheating.

Oh I though you meant me.
Oops!
:joy:

1 Like

Oh I understand, and how can I help him? Should I guide him in how to code should be structured without completing it or something like that?

or just tell them whats wrong

No error

It doesn’t move to them, in fact, it doesn’t even attack the enemies

she*

2 Likes

Use the append function.
What it does, is add something into an array.
You can loop thru all the enemies, and if its not a yak, add it to an array.
Find the nearest in the array. :slight_smile:
Here is how to use append.

friends = hero.findFriends()
archers = []
soldiers = []
paladins = []
for friend in friends:
    if friend.type == 'soldier':
        soldiers.append(friend)
    if friend.type == 'archer':
        archers.append(friend)
    if friend.type == 'paladin':
        paladins.append(friend)

Just loop thru all enemies, if not sand yak, append it to an array.
Find the nearest in the array, then attack.

Using append is just long and obsolete. Use .filter(). Create a function like “nonYaks(unit)” and make it return a boolean determining whether unit is a yak or not a yak. In this case it should return True if the target is not a yak. Then just assign enemies to herо.findEnemies().filter(nonYaks) and use hero.findNearest() to find the nearest non-yak enemy.

1 Like

Careful teaching CodeCombat’s quirks to people who are learning the language. That should not be available in Python.

And, what happened to attacking the enemy? I don’t use rangers often but I am pretty sure scattershot has a cooldown…
Also:

Am I right in saying that chain-lightning and counter-blast should not have the second argument of the enemy in the if statement? It seems not to work if you do this but put the enemy argument when you are actually going to do it i.e. in the if statement. I have a theory that it’s because the computer will check if the action is ready for the enemy and not in general. @Chaboi_3000, do ammend this if I am wrong.

Thanks

Obviously, but it’s still a way to take advantage of flaws in the parser :stuck_out_tongue: (incl. using Lodash) Stranded in the Dunes isn’t one of those “learn a concept” levels, so it doesn’t hurt too much.

It works both ways, but counter-blast should be used on an ally, not an enemy. (Described in)

2 Likes

What is the parser? Is it a way of parsing through a list or array?