home · contact · privacy
Don't recalculate directions all the time, unnecessarily.
[plomrogue2] / plomrogue / mapping.py
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