# Be aware of hidden traps, and count your steps
# Coins are separated by 10 meters distance
steps = 1
while True:
# If the number of steps is divisible by 3 AND by 5 -- move to North-West
if steps % 3 and 5 == 0:
hero.moveXY(hero.pos.x - 10, hero.pos.y + 10)
# Else if the number of steps is divisible by 3 -- move to East
else:
if steps % 3 == 0:
hero.moveXY(hero.pos.x + 10, hero.pos.y)
# Else if the number of steps is divisible by 5 -- move to West
else:
if steps % 5 == 0:
hero.moveXY(hero.pos.x - 10, hero.pos.y)
else:
hero.moveXY(hero.pos.x, hero.pos.y + 10)
steps += 1
Thought I’d got this one, but seem to be getting blown up on step 15?
This is on the right track but not complete. Think about what that statement is really saying. Remember that computers are very literal and kinda stupid. They lack the ability to figure out what you mean. You have to be very precise. It should be:
I always wish there was a function which let you do that, like:
if enemy.type == "ogre" or "munchkin" or "thrower":
hero.attack(enemy)
#but it has to make it twice as frickin long. (I run into this a lot, especially with a findEnemyHero function)
if enemy.type == "ogre" or enemy.type == "munchkin" or enemy.type == "thrower":
It won’t work with current python logic though. It’s the or's that are separating them so it’s like if enemy.type==‘ogre-m’ or ‘munchkin’. The code won’t know what munchkin is unless you assign enemy.type to each one. I think…
def orTypes(unit, *types):
for type in types:
if unit and unit.type == type:
return type
return False
# possible use
enemy = hero.findNearestEnemy()
if enemy and enemy.health > 0 and orTypes(enemy,'witch', 'thrower'):
hero.attack(enemy)
function orTypes ( unit){
var returnValue = false;
for (var i = 1; i < arguments.length; i++ ){
// unit is arguments[0]
var type = arguments[i];
if (unit && unit.type == type){
returnValue = true;
// you can also assign unit or type to returnValue
}
}
return returnValue;
}
// possible use
var enemy = hero.findNearestEnemy();
if (enemy && enemy.health > 0 && orTypes(enemy,'witch', 'thrower')
hero.attack(enemy);