Browse code
cleanup
Ed L authored on 10/06/2014 21:24:19
Showing 3 changed files
Showing 3 changed files
... | ... |
@@ -34,34 +34,23 @@ def scale_array(arr, min, max): |
34 | 34 |
arr += min |
35 | 35 |
return arr |
36 | 36 |
|
37 |
-cm = np.array([[1,1,1],[1,0,1],[1,1,1]]) |
|
38 |
-#cm = np.random.random_integers(0,np.random.random_integers(1,3), (3,3)) |
|
37 |
+# For Conway's game of life: |
|
38 |
+#cm = np.array([[1,1,1],[1,0,1],[1,1,1]]) |
|
39 |
+# For a random neighbour selection: |
|
40 |
+cm = np.random.random_integers(0,np.random.random_integers(1,3), (3,3)) |
|
39 | 41 |
gens = 0 |
40 | 42 |
def change(arr): |
41 | 43 |
global gens |
42 | 44 |
gens += 1 |
43 | 45 |
live = arr == 1 |
44 |
- new = sig.convolve2d(arr,cm,'same') |
|
46 |
+ # Finite grid |
|
47 |
+ #new = sig.convolve2d(arr,cm,'same') |
|
48 |
+ # Torus |
|
45 | 49 |
new = sig.convolve2d(arr,cm,'same', 'wrap') |
46 | 50 |
arr[live & (new < 2)] = 0 |
47 | 51 |
arr[live & (new > 3)] = 0 |
48 | 52 |
arr[new == 3] = 1 |
49 | 53 |
|
50 |
-pattern = np.array( |
|
51 |
- [ |
|
52 |
- [0,0,0,0,0,0,0], |
|
53 |
- [0,0,0,1,0,0,0], |
|
54 |
- [0,1,1,0,0,0,0], |
|
55 |
- [0,0,1,0,0,0,0], |
|
56 |
- [0,1,0,0,1,0,0], |
|
57 |
- [0,0,0,0,0,1,0], |
|
58 |
- [0,0,1,0,0,1,0], |
|
59 |
- [0,0,0,1,0,1,0], |
|
60 |
- [0,0,1,0,0,0,0], |
|
61 |
- [0,0,0,0,0,0,0] |
|
62 |
- ] |
|
63 |
-) |
|
64 |
- |
|
65 | 54 |
class Application(object): |
66 | 55 |
def __init__(self): |
67 | 56 |
self.screen = console.Screen(WIDTH, HEIGHT+5) |
... | ... |
@@ -77,29 +66,8 @@ class Application(object): |
77 | 66 |
self.tc_events = events.TCODEventHandler() |
78 | 67 |
self.events = events.EventHandler() |
79 | 68 |
|
80 |
- #tc.sys_set_fps(30) |
|
81 |
- #self.arr = np.random.random_integers(0,1,(HEIGHT,WIDTH)) |
|
82 |
- self.arr = np.zeros((HEIGHT,WIDTH)) |
|
83 |
- self.arr[HEIGHT/2-5:HEIGHT/2+5,WIDTH/2-4:WIDTH/2+3] = pattern |
|
84 |
- |
|
85 |
- def tick_actor(self, actor): |
|
86 |
- keep = actor.tick() |
|
87 |
- if not keep: |
|
88 |
- self.actors.remove(actor) |
|
89 |
- self.objects.append(actor) |
|
90 |
- |
|
91 |
- def update_actors(self): |
|
92 |
- self.player.tick() |
|
93 |
- |
|
94 |
- def tick_actors(self, player): |
|
95 |
- print 'actor_tick' |
|
96 |
- to_pop = [] |
|
97 |
- for idx,actor in enumerate(self.actors[1:],1): |
|
98 |
- if not actor.tick(): |
|
99 |
- bisect.insort(to_pop, idx) |
|
100 |
- for pop in reversed(to_pop): |
|
101 |
- actor = self.actors.pop(pop) |
|
102 |
- self.objects.append(actor) |
|
69 |
+ tc.sys_set_fps(30) |
|
70 |
+ self.arr = np.random.random_integers(0,1,(HEIGHT,WIDTH)) |
|
103 | 71 |
|
104 | 72 |
def init(self): |
105 | 73 |
self.screen.init("test") |
... | ... |
@@ -107,17 +75,12 @@ class Application(object): |
107 | 75 |
self.border.blit() |
108 | 76 |
self.message_console.fill(0,0,128) |
109 | 77 |
self.rule.update() |
110 |
- #self.player.draw() |
|
111 |
- #for overlay in self.actors + self.objects: |
|
112 |
- # overlay.draw() |
|
113 | 78 |
|
114 | 79 |
def tick(self): |
115 | 80 |
self.tc_events.tick() |
116 | 81 |
self.fps_display.set_text('%d', tc.sys_get_fps()) |
117 | 82 |
self.generations.set_text('%d' % gens) |
118 |
- #self.update_actors() |
|
119 |
- #self.map.draw(self.console) |
|
120 |
- #change(self.arr) |
|
83 |
+ change(self.arr) |
|
121 | 84 |
c = self.arr*255 |
122 | 85 |
tc.console_fill_background(self.console.con, c,c,c) |
123 | 86 |
|
124 | 87 |
deleted file mode 100644 |
... | ... |
@@ -1,17 +0,0 @@ |
1 |
-import numpy as np |
|
2 |
-from scipy import signal |
|
3 |
- |
|
4 |
-class SmellMap(object): |
|
5 |
- def __init__(self, size_x, size_y): |
|
6 |
- self.map = np.zeros((size_x, size_y), int) |
|
7 |
- def tick(self): |
|
8 |
- self.map -= 1 |
|
9 |
- self.map[self.map<0] = 0 |
|
10 |
- def impress(self, pos, degree): |
|
11 |
- self.map[pos] = degree |
|
12 |
- def get_move(self, pos): |
|
13 |
- x,y = pos |
|
14 |
- neighbours = self.map[x-1:x+2,y-1:y+2] |
|
15 |
- neighbours[1,1] = 0 |
|
16 |
- dx,dy = np.unravel_index(neighbours.argmax(), neighbours.shape) |
|
17 |
- return dx-1, dy-1 |