Lars Yencken avatar Lars Yencken committed c13e0df

Use a matrix to represent the map.

Comments (0)

Files changed (1)

 import time
 from collections import defaultdict
 from math import sqrt
+import numpy as np
 MY_ANT = 0
 ANTS = 0
                     self.spawnradius2 = int(tokens[1])
                 elif key == 'turns':
                     self.turns = int(tokens[1])
- = [[LAND for col in range(self.cols)]
-                    for row in range(self.rows)]
+ = np.ones((self.rows, self.cols))*LAND
     def update(self, data):
         'parse engine input and update the game state'
         # clear hill, ant and food data
         self.hill_list = {}
         for row, col in self.ant_list.keys():
-  [row][col] = LAND
+  [row, col] = LAND
         self.ant_list = {}
         for row, col in self.dead_list.keys():
-  [row][col] = LAND
+  [row, col] = LAND
         self.dead_list = defaultdict(list)
         for row, col in self.food_list:
-  [row][col] = LAND
+  [row, col] = LAND
         self.food_list = []
         # update map and create new ant and food lists
                     row = int(tokens[1])
                     col = int(tokens[2])
                     if tokens[0] == 'w':
-              [row][col] = WATER
+              [row, col] = WATER
                     elif tokens[0] == 'f':
-              [row][col] = FOOD
+              [row, col] = FOOD
                         self.food_list.append((row, col))
                         owner = int(tokens[3])
                         if tokens[0] == 'a':
-                  [row][col] = owner
+                  [row, col] = owner
                             self.ant_list[(row, col)] = owner
                         elif tokens[0] == 'd':
                             # food could spawn on a spot where an ant just died
                             # don't overwrite the space unless it is land
-                            if[row][col] == LAND:
-                      [row][col] = DEAD
+                            if[row, col] == LAND:
+                      [row, col] = DEAD
                             # but always add to the dead list
                             self.dead_list[(row, col)].append(owner)
                         elif tokens[0] == 'h':
     def passable(self, loc):
         'true if not water'
         row, col = loc
-        return[row][col] != WATER
+        return[row, col] != WATER
     def unoccupied(self, loc):
         'true if no ants are at the location'
         row, col = loc
-        return[row][col] in (LAND, DEAD)
+        return[row, col] in (LAND, DEAD)
     def destination(self, loc, direction):
         'calculate a new location given the direction and wrap correctly'
     def visible(self, loc):
         ' determine which squares are visible to the given player '
         if == None:
             if not hasattr(self, 'vision_offsets_2'):
                 # precalculate squares around an ant to set as visible
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.