import collections
+from plomrogue.errors import ArgError
directions += [name[5:]]
return directions
+ def get_neighbors(self, pos):
+ neighbors = {}
+ for direction in self.get_directions():
+ neighbors[direction] = self.move(pos, direction)
+ return neighbors
+
def move(self, start_pos, direction):
mover = getattr(self, 'move_' + direction)
target = mover(start_pos)
+class MapGeometryHex(MapGeometryWithLeftRightMoves):
+
+ def move_UPLEFT(self, start_pos):
+ start_indented = start_pos.y % 2
+ if start_indented:
+ return YX(start_pos.y - 1, start_pos.x)
+ else:
+ return YX(start_pos.y - 1, start_pos.x - 1)
+
+ def move_UPRIGHT(self, start_pos):
+ start_indented = start_pos.y % 2
+ if start_indented:
+ return YX(start_pos.y - 1, start_pos.x + 1)
+ else:
+ return YX(start_pos.y - 1, start_pos.x)
+
+ def move_DOWNLEFT(self, start_pos):
+ start_indented = start_pos.y % 2
+ if start_indented:
+ return YX(start_pos.y + 1, start_pos.x)
+ else:
+ return YX(start_pos.y + 1, start_pos.x - 1)
+
+ def move_DOWNRIGHT(self, start_pos):
+ start_indented = start_pos.y % 2
+ if start_indented:
+ return YX(start_pos.y + 1, start_pos.x + 1)
+ else:
+ return YX(start_pos.y + 1, start_pos.x)
+
+
+
class Map():
def __init__(self, map_size):
if y >= height_map:
raise ArgError('too large row number %s' % y)
width_line = len(line)
- if width_line > width_map:
- raise ArgError('too large map line width %s' % width_line)
+ if width_line != width_map:
+ raise ArgError('map line width %s unequal map width %s' % (width_line, width_map))
self.terrain = self.terrain[:y * width_map] + line +\
self.terrain[(y + 1) * width_map:]