Quick question guys. Below is my code for Sarven Sum:
whiteX = {'x':27, 'y':42}
redX = {'x':151 , 'y': 118}
while True:
traps = hero.findByType("fire-trap")
lowestTrap = None
maxTrapVal = 999999
trapIndex = 0
if hero.health < hero.maxHealth / 2:
if hero.canCast("regen", self):
hero.cast("regen", self)
while trapIndex < len(traps):
if traps[trapIndex].value < maxTrapVal:
lowestTrap = traps[trapIndex]
maxTrapVal = lowestTrap.value
trapIndex += 1
traps = hero.findByType("fire-trap")
highestTrap = None
minTrapVal = 0
trapIndex = 0
while trapIndex < len(traps):
if traps[trapIndex].value > minTrapVal:
highestTrap = traps[trapIndex]
minTrapVal = highestTrap.value
trapIndex += 1
hero.moveXY(28, 42)
hero.say(lowestTrap.value + highestTrap.value)
break
while True:
enemies = hero.findEnemies()
potion = hero.findByType("potion", hero.findItems())
nearestEnemy = None
maxDistance = 99999
enemyIndex = 0
while enemyIndex < len(enemies):
if hero.distanceTo(enemies[enemyIndex]) < maxDistance:
nearestEnemy = enemies[enemyIndex]
maxDistance = hero.distanceTo(nearestEnemy)
enemyIndex += 1
break
if nearestEnemy:
while nearestEnemy.health > 0:
if hero.canCast("lightning-bolt", nearestEnemy):
hero.cast("lightning-bolt", nearestEnemy)
else:
hero.attack(nearestEnemy)
else:
hero.move(redX)
My question is in regards to the very last line…
Originally it was hero.moveXY(151, 118)
and what would happen is my hero, after disabling the traps, would just start moving right to the coordinates regardless of if enemies were nearby, even though the code cleary says “if there are enemies nearby, kill them fools first.”(or does it?) When I remembered that whiteX and redX were defined by default, I changed it to the current code and it worked fine. Level is solved, just looking for some understanding here.
Thanks!