summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.py7
-rw-r--r--main.py5
-rw-r--r--subscriber.py31
3 files changed, 41 insertions, 2 deletions
diff --git a/gui.py b/gui.py
index 19fffbb..440e0ef 100644
--- a/gui.py
+++ b/gui.py
@@ -142,6 +142,11 @@ def generate_virus(spikes, spike_length, radius, global_coords):
def draw_cell(cell):
cx,cy = world_to_win_pt(cell.pos,c.player.center)
+ try:
+ cx2,cy2 = world_to_win_pt(cell.poslog[-2],c.player.center)
+ except:
+ print("wtf, no poslog available?!")
+ cx2,cy2=cx,cy
radius = world_to_win_length(cell.size)
if cell.is_virus:
@@ -158,6 +163,8 @@ def draw_cell(cell):
gfxdraw.aapolygon(screen, polygon2, color)
else:
color=(int(cell.color[0]*255), int(cell.color[1]*255), int(cell.color[2]*255))
+
+ gfxdraw.filled_circle(screen, cx2, cy2, radius, (127,127,127))
if not (cell.is_ejected_mass or cell.is_food):
gfxdraw.filled_circle(screen, cx, cy, radius, color)
diff --git a/main.py b/main.py
index d13c4ea..fd75b42 100644
--- a/main.py
+++ b/main.py
@@ -9,13 +9,14 @@ import time
import random
import gui
import stats
-from subscriber import DummySubscriber
+from subscriber import EnhancingSubscriber
from interval_utils import *
from strategy import *
# global vars
-sub = DummySubscriber()
+sub = EnhancingSubscriber()
c = client.Client(sub)
+sub.set_client(c)
stats = stats.Stats()
for i in range(1,10): # 10 connection attempts
diff --git a/subscriber.py b/subscriber.py
index a637e67..1dcccc6 100644
--- a/subscriber.py
+++ b/subscriber.py
@@ -1,4 +1,5 @@
from log import log
+from collections import deque
import sys
class DummySubscriber:
@@ -65,3 +66,33 @@ class DummySubscriber:
def on_debug_line(self,x,y):
log("debug line")
+class CellHistory:
+ def __init__(self):
+ self.poslog = deque(maxlen=10)
+ self.stale = False
+
+class EnhancingSubscriber(DummySubscriber):
+ def __init__(self):
+ self.c = None
+ self.history = {}
+
+ def set_client(self,c):
+ self.c = c
+
+ def on_world_update_post(self):
+ for cid in self.history:
+ self.history[cid].stale = True
+
+ for cid in self.c.world.cells:
+ if cid not in self.history:
+ self.history[cid] = CellHistory()
+ print("unknown cell")
+
+ self.history[cid].poslog.append(self.c.world.cells[cid].pos.copy())
+ self.c.world.cells[cid].poslog = self.history[cid].poslog
+ print("poslog of size="+str(len(self.history[cid].poslog)))
+
+ self.history[cid].stale = False
+
+ self.history = {k: v for k, v in self.history.items() if v.stale == False}
+