Skip to content

Instantly share code, notes, and snippets.

@joooyzee
Last active Jul 19, 2021
Embed
What would you like to do?
# given an adjacent tile location, move us there
def move_to_tile(self, location, tile):
# see where the tile is relative to our current location
diff = tuple(x-y for x, y in zip(tile, self.location))
# return the action that moves in the direction of the tile
if diff == (0,1):
action = 'u'
elif diff == (0,-1):
action = 'd'
elif diff == (1,0):
action = 'r'
elif diff == (-1,0):
action = 'l'
else:
action = ''
return action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment