git.fiddlerwoaroof.com
Browse code

relies on numpy to make getting a sub-array easier

Ed L authored on 01/08/2012 03:49:03
Showing 1 changed files
... ...
@@ -4,6 +4,10 @@ import libtcodpy as libtcod
4 4
 import random
5 5
 from utilities import Rect
6 6
 
7
+try: import numpypy
8
+except ImportError: pass
9
+import numpy as np
10
+
7 11
 import objects
8 12
 
9 13
 class Tile(object):
... ...
@@ -18,12 +22,13 @@ class Tile(object):
18 22
 
19 23
 class AutomataEngine(object):
20 24
 	def __init__(self, width=None, height=None, data=None, randomize=True):
21
-		if data:
25
+		if data is not None:
22 26
 			self.data = data
23 27
 		elif randomize:
24 28
 			self.data = [ [ random.choice([0]+[1]*3) for y in range(height)] for x in range(width) ]
25 29
 		else:
26 30
 			self.data = [ [1 for y in range(height)] for x in range(width) ]
31
+		self.data = np.array(self.data)
27 32
 		self.width = width
28 33
 		self.height = height
29 34
 
... ...
@@ -32,7 +37,7 @@ class AutomataEngine(object):
32 37
 		x2,y2 = p2
33 38
 		x1,x2 = min([x1,x2]), max([x1,x2])
34 39
 		y1,y2 = min([y1,y2]), max([y1,y2])
35
-		result = [row[y1:y2+1] for row in self.data[x1:x2+1]]
40
+		result = self.data[x1:x2,y1:y2]
36 41
 		return result
37 42
 
38 43
 	def sum_area(self, p1, p2=None, summator=sum):
... ...
@@ -51,7 +56,7 @@ class AutomataEngine(object):
51 56
 				yield x,y,cell
52 57
 
53 58
 	def munge(self):
54
-		tmp_data = copy.deepcopy(self.data)
59
+		tmp_data = np.array(self.data)
55 60
 
56 61
 		for x,row in enumerate(self.data):
57 62
 			for y,cell in enumerate(row):
... ...
@@ -181,7 +186,7 @@ class MazeGen(AutomataEngine):
181 186
 		return cell
182 187
 
183 188
 	def munge(self):
184
-		tmp_data = copy.deepcopy(self.data)
189
+		tmp_data = np.array(self.data)
185 190
 
186 191
 		for x,row in enumerate(self.data):
187 192
 			for y,cell in enumerate(row):