From a4219f004cea5392fa5e9356ee9f42bc877c8224 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Mon, 10 Aug 2015 23:32:15 +0200 Subject: Added basic statistics - added a new stats module - added mass and position tracking to the current cell logic --- stats.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 stats.py (limited to 'stats.py') diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..f850339 --- /dev/null +++ b/stats.py @@ -0,0 +1,36 @@ +import time + +class Stats: + def __init__(self): + self.min_mass = 0 + self.max_mass = 0 + self.current_mass = 0 + + self.mass_history = [] + self.pos_history = [] + self.cell_aggressivity = {} + self.cell_split_frequency = {} + self.cell_defensiveness = {} + + def log_mass(self, mass): + self.mass_history.append((time.time(), mass)) + self.current_mass = mass + if mass > self.max_mass: + self.max_mass = mass + if mass < self.min_mass: + self.min_mass = mass + + def log_pos(self, pos): + self.pos_history.append((time.time(), (pos[0], pos[1]))) + + def update_cell_aggressivity(self, cell, value): + self.cell_aggressivity[cell] = value + + def update_cell_split_frequency(self, cell, value): + self.cell_split_frequency[cell] = value + + def update_cell_defensiveness(self, cell, value): + self.cell_defensiveness[cell] = value + + def get_last_steps(self, list, steps = 10): + return list[-steps:] \ No newline at end of file -- cgit v1.2.3