Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import partial
- def update_pos(self, room, exit_name):
- # this ensures the pointer variables always
- # stays up to date to where the worm is currently at.
- self.curX, self.curY = self.worm_has_mapped[room][0], self.worm_has_mapped[room][1]
- # now we have to actually move the pointer
- # variables depending on which 'exit' it found
- def _update_pos(x=0, y=0):
- return self.curX + x, self.curY + y
- # define the different cases
- switch = {
- 'east': partial(_update_pos, y=1),
- 'west': partial(_update_pos, y=-1),
- 'north': partial(_update_pos, x=-1),
- 'south': partial(_update_pos, x=1),
- 'northwest': partial(_update_pos, x=-1, y=-1),
- 'northeast': partial(_update_pos, x=-1, y=1),
- 'southwest': partial(_update_pos, x=1, y=-1),
- 'southeast': partial(_update_pos, x=1, y=1),
- }
- update_pos_func = switch.get(exit_name) # get the right case
- self.curX, self.curY = update_pos_func() if update_pos_func else self.curX, self.curY # update position
Advertisement
Add Comment
Please, Sign In to add comment