5 class YX(collections.namedtuple('YX', ('y', 'x'))):
7 def __add__(self, other):
8 return YX(self.y + other.y, self.x + other.x)
10 def __sub__(self, other):
11 return YX(self.y - other.y, self.x - other.x)
14 return 'Y:%s,X:%s' % (self.y, self.x)
20 def get_directions(self):
22 for name in dir(self):
23 if name[:5] == 'move_':
24 directions += [name[5:]]
27 def move(self, start_pos, direction):
28 mover = getattr(self, 'move_' + direction)
29 return mover(start_pos)
33 class MapGeometryWithLeftRightMoves(MapGeometry):
35 def move_LEFT(self, start_pos):
36 return YX(start_pos.y, start_pos.x - 1)
38 def move_RIGHT(self, start_pos):
39 return YX(start_pos.y, start_pos.x + 1)
43 class MapGeometrySquare(MapGeometryWithLeftRightMoves):
45 def move_UP(self, start_pos):
46 return YX(start_pos.y - 1, start_pos.x)
48 def move_DOWN(self, start_pos):
49 return YX(start_pos.y + 1, start_pos.x)