summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-25 19:53:35 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-25 19:53:35 +0200
commit5b91b2732ed339a1c2559e06833cc4f1daec01ae (patch)
tree3e74df508b7b8695032a1b6b26c6bf3a2bae7e95
parent0df1c5f7799fdd63c3cd3fdc92bc9ccc60d1da8f (diff)
statistics
-rw-r--r--main.py2
-rw-r--r--stats.py34
2 files changed, 36 insertions, 0 deletions
diff --git a/main.py b/main.py
index 0cd9b30..c0e9a21 100644
--- a/main.py
+++ b/main.py
@@ -80,4 +80,6 @@ while gui.running:
else:
autorespawn_counter-=1
+stats.save("stats.pickle")
+
print("bye")
diff --git a/stats.py b/stats.py
index 9a745ab..aed7b42 100644
--- a/stats.py
+++ b/stats.py
@@ -1,4 +1,6 @@
import time
+from collections import defaultdict
+import pickle
class Stats:
def __init__(self,c):
@@ -12,6 +14,10 @@ class Stats:
self.cell_aggressivity = {}
self.cell_split_frequency = {}
self.cell_defensiveness = {}
+
+ self.size_vs_speed = defaultdict(lambda : defaultdict(lambda : 0))
+ self.size_vs_visible_window = defaultdict(lambda : [])
+ self.mass_vs_visible_window = defaultdict(lambda : [])
def log_mass(self, mass):
self.mass_history.append((time.time(), mass))
@@ -39,3 +45,31 @@ class Stats:
def process_frame(self):
self.log_pos(self.c.player.center)
self.log_mass(self.c.player.total_mass)
+
+ cells = self.c.world.cells.values()
+ own_cells = self.c.player.own_cells
+
+ own_total_size = sum( map(lambda cell : cell.size, own_cells) )
+ own_total_mass = sum( map(lambda cell : cell.mass, own_cells) )
+
+ n = 3
+ for cell in filter(lambda cell : not cell.is_food and not cell.is_virus and not cell.is_ejected_mass, cells):
+ if hasattr(cell,'poslog') and len(cell.poslog) > n+1:
+ cellspeed = 0
+ for i in range(1,n+1):
+ cellspeed += (cell.poslog[-i] - cell.poslog[-i-1]).len() / n
+
+ cellspeed = int(cellspeed)
+ self.size_vs_speed[cell.size][cellspeed] += 1
+
+ visible_width = max( map(lambda cell : cell.pos.x - cell.size, cells) ) - min( map(lambda cell : cell.pos.x + cell.size, cells) )
+ visible_height = max( map(lambda cell : cell.pos.y - cell.size, cells) ) - min( map(lambda cell : cell.pos.y + cell.size, cells) )
+
+ self.size_vs_visible_window[own_total_size].append((visible_width,visible_height))
+ self.mass_vs_visible_window[own_total_mass].append((visible_width,visible_height))
+
+ def save(self,filename):
+ pickle.dump(self, open(filename,"wb"))
+
+ def load(filename):
+ return pickle.load(open(filename,"rb"))