Skip to content

Instantly share code, notes, and snippets.

@joooyzee
Last active July 19, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joooyzee/c9fa640b4ee2ebc737388218d2da2aea to your computer and use it in GitHub Desktop.
Save joooyzee/c9fa640b4ee2ebc737388218d2da2aea to your computer and use it in GitHub Desktop.
# 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