summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-26 22:51:20 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-26 22:51:20 +0200
commitbe59b002fb2650bf17f58420fa93b0f8bef74a25 (patch)
treec41879281ee84c8c8c757748117b65b99fdac733
parentb1492078b6b23d2ead2aeddeca3fd0f4f69df0ef (diff)
detect splits and add cell.parent attribute
-rw-r--r--subscriber.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/subscriber.py b/subscriber.py
index b2b6643..e910087 100644
--- a/subscriber.py
+++ b/subscriber.py
@@ -1,6 +1,7 @@
from log import log
from collections import deque
import sys
+import mechanics
class DummySubscriber:
def on_connect_error(self,s):
@@ -126,3 +127,31 @@ class EnhancingSubscriber(DummySubscriber):
else:
cell.player = None
+ # detect split cells and clean up obsolete parent references
+ for cell in self.c.world.cells.values():
+ if not cell.is_food and not cell.is_ejected_mass and not cell.is_virus:
+ # create attribute if not already there
+ try:
+ cell.parent = cell.parent
+ except:
+ cell.parent = None
+ print("new cell, setting parent = None")
+
+ # clean up obsolete parent references
+ if cell.parent and cell.parent.cid not in self.c.world.cells:
+ cell.parent = None
+ print("obsolete parent")
+
+
+ if not cell.is_food and not cell.is_ejected_mass and not cell.is_virus:
+ is_split = False
+ try:
+ if cell.parent == None and cell.movement.len() > 2 * mechanics.speed(cell.size):
+ print("looks like a split!"+str(cell.movement.len() / mechanics.speed(cell.size)))
+ is_split = True
+ except AttributeError:
+ pass
+
+ if is_split:
+ history_len = len(cell.poslog)
+ cell.parent = min(self.c.world.cells.values(), key=lambda c : (c.poslog[-history_len] - cell.poslog[-history_len]).len() if c != cell and len(c.poslog) >= history_len else 999999)