home · contact · privacy
Don't recalculate directions all the time, unnecessarily.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 6 Dec 2020 18:59:02 +0000 (19:59 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 6 Dec 2020 18:59:02 +0000 (19:59 +0100)
plomrogue/game.py
plomrogue/mapping.py

index c4951799002c3a2ec086bde6342cb07231c1c6f5..a1c2ee641cc1dcfefd8797b284676095ab69e83b 100755 (executable)
@@ -180,7 +180,7 @@ class Game(GameBase):
 
     def get_string_options(self, string_option_type):
         if string_option_type == 'direction':
-            return self.map_geometry.get_directions()
+            return self.map_geometry.directions
         elif string_option_type == 'char':
             return [c for c in
                     string.digits + string.ascii_letters + string.punctuation + ' ']
index e806ef70f8c721386bf9cdeada5733fc57eea176..53e9d29fed1267d51e68dd2c19c2aa5626be6688 100644 (file)
@@ -21,6 +21,7 @@ class MapGeometry():
     def __init__(self, size):
         self.size = size
         self.neighbors_i = {}
+        self.directions = self.get_directions()
 
     def get_directions(self):
         directions = []
@@ -32,13 +33,13 @@ class MapGeometry():
 
     def get_neighbors_yxyx(self, yxyx):
         neighbors = {}
-        for direction in self.get_directions():
+        for direction in self.directions:
             neighbors[direction] = self.move_yxyx(yxyx, direction)
         return neighbors
 
     def get_neighbors_yx(self, pos):
         neighbors = {}
-        for direction in self.get_directions():
+        for direction in self.directions:
             neighbors[direction] = self.move_yx(pos, direction)
         return neighbors