Lately when attempting levels I am having a hard time/unable to target and attack monsters.
using the code:
# Collect 150 gold while evading ogres with teleporters.
# If you win, it gets harder (and more rewarding).
# If you lose, you must wait a day before you can resubmit.
# Remember, each submission gets a new random seed.
enemies = self.findEnemies()
enemyIndex = 0
loop:
while enemy <len(enemyIndex):
enemy = self.findNearest(enemies)
if enemy:
self.say("1234")
My hero never actually says 1234
If I add:
while not enemy:
self.say("5678")
He will sit and spam 5678 and not attack the ogre.
enemies = self.findEnemies()
enemyIndex = 0
loop:
while enemy <len(enemies):
enemy = self.findNearest(enemies)
while enemy:
self.say("1234")
while not enemy:
self.say("5678")
will also sit and spam 5678
I have also tried:
enemies = self.findEnemies()
enemyIndex = 0
loop:
while enemy <len(enemies):
enemy = self.findNearest(self.findEnemies())
while enemy:
self.say("1234")
while not enemy:
self.say("5678")
You are comparing enemy to a number. (len(varName) returns a number. enemy would be an object, and comparing an object to a number doesn’t make sense.
At the time you are checking while enemy <len(enemyIndex): enemy hasn’t been defined. So the while statement never evaluates. However, because you define it later, it doesn’t give an error.
You are using len() on a non-list variable type. len(["a", "b", "c"]) is 3, len(0) is None.
So I end up actually being to slow if I kill the enemies, is there a way to prioritize the 2 and 3 gold coins over the 1 value and if no 2/3 then collect 1’s?
I’m about 1200 short of getting the speed ring sadly.
My code right now is:
loop:
coins = self.findItems()
coinIndex = 0
enemies = self.findEnemies()
enemyIndex = 0
enemy = self.findNearest(enemies)
if enemy:
while enemy.health > 0:
self.attack(enemy)
# Wrap this into a loop that iterates over all coins.
while coinIndex < len(coins):
coin = coins[coinIndex]
# Gold coins are worth 1 or more.
if coin.value >=1:
# Move to coin.
self.moveXY(coin.pos.x, coin.pos.y)
pass
coinIndex += 1
I end up only getting 56 coins after 59.9 seconds right now though.
get a better chestplate if you can and what level in sarvern treasure its a replayable level
I could not finish it until I got the speed ring and softened boots with runesword but mostly the speed helped
I think its impossible to win without speed ring and softened leather boots
i have tried to win without those and I failed just always runs out of time
but when i used the speed ring with the boots it worked