My hero moves towards where I believe the teleporter is, in this case it’s the bottom-right one and then he appears and keeps going towards it, over and over and over. The rest of my code may not be perfect but specifically I’m wondering what teleport locations work so that my hero will teleport and then stop and look for money instead of heading towards the same teleporter.
I’ve looked at this question and updated my locations to be as close to (5.27, 19.23), (4.71, 49.19), (76.67, 19.02), (75.95, 51.00)
by rounding to (5, 19), (5, 49), (77, 19), (76, 51)
but there is still a never ending loop to the bottom-right teleporter. Here is my 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.
def teleTL():
hero.moveXY(5, 49)
def teleBL():
hero.moveXY(5, 19)
def teleTR():
hero.moveXY(76, 51)
def teleBR():
hero.moveXY(77, 19)
def inBetween(ogre,coin):
toLeft=hero.pos.x<coin.pos.x
below=hero.pos.y<coin.pos.y
oToLeft=ogre.pos.x<coin.pos.x
oBelow=ogre.pos.y<coin.pos.y
if (toLeft and oToLeft) or (below and oBelow) or (not toLeft and not oToLeft) or (not below and not oBelow):
return True
return False
while True:
ogres = hero.findEnemies()
ogre=hero.findNearest(ogres)
coins=hero.findItems()
coinIndex=0
closest=hero.findNearest(coins)
minDistance=20
while coinIndex<len(coins):
coin=coins[coinIndex]
if coin.value>=2 and hero.distanceTo(coin)<minDistance:
closest=coin
minDistance=hero.distanceTo(coin)
coinIndex+=1
top=hero.pos.y>36
left=hero.pos.x<36
if closest and not ogre:
hero.moveXY(closest.pos.x, closest.pos.y)
elif closest and ogre:
ogreDistance = hero.distanceTo(ogre)
if ogreDistance >= 10 and closest and not inBetween(ogre,coin):
hero.moveXY(closest.pos.x, closest.pos.y)
elif closest:
if top and left:
teleTL()
elif top:
teleTR()
elif not top and left:
teleBL()
else:
teleBR()
hero.say("I'm here") # right now he never says anything
hero.moveXY(closest.pos.x, closest.pos.y)