diff options
author | SpitfireX <timm.weber@me.com> | 2015-08-10 23:32:15 +0200 |
---|---|---|
committer | SpitfireX <timm.weber@me.com> | 2015-08-10 23:32:15 +0200 |
commit | a4219f004cea5392fa5e9356ee9f42bc877c8224 (patch) | |
tree | f0f9f9af0557e6b9fc84bb6fe92fe68f5bddd6ec | |
parent | 0b38518540aef32e5420aed456acfa7402200215 (diff) |
Added basic statistics
- added a new stats module
- added mass and position tracking to the current cell logic
-rw-r--r-- | main.py | 15 | ||||
-rw-r--r-- | stats.py | 36 |
2 files changed, 45 insertions, 6 deletions
@@ -6,13 +6,15 @@ from pygame.locals import * import sys import math import time -import gui import random +import gui +import stats from subscriber import DummySubscriber +# global vars sub = DummySubscriber() c = client.Client(sub) - +stats = stats.Stats() # find out server and token to connect try: @@ -26,14 +28,13 @@ c.connect(addr,token) c.send_facebook( 'g2gDYQFtAAAAEKO6L3c8C8/eXtbtbVJDGU5tAAAAUvOo7JuWAVSczT5Aj0eo0CvpeU8ijGzKy/gXBVCxhP5UO+ERH0jWjAo9bU1V7dU0GmwFr+SnzqWohx3qvG8Fg8RHlL17/y9ifVWpYUdweuODb9c=') -c.player.nick="test cell pls ignore" +#c.player.nick="test cell pls ignore" c.send_spectate() # initialize GUI gui.set_client(c) - # main loop while True: c.on_message() @@ -49,7 +50,6 @@ while True: if dist < cell.size*4 and cell.mass > 1.25 * my_smallest: runaway_x += (c.player.center[0] - cell.pos[0]) / cell.mass / dist runaway_y += (c.player.center[1] - cell.pos[1]) / cell.mass / dist - runaway_r = math.sqrt(runaway_x**2 + runaway_y**2) if (runaway_r > 0): @@ -75,4 +75,7 @@ while True: c.send_target(rx, ry) gui.debug_line(c.player.center, (rx, ry),(0,255,0)) gui.update() - print("Nothing to do, heading to random destination: " + str((rx, ry)))
\ No newline at end of file + print("Nothing to do, heading to random destination: " + str((rx, ry))) + + stats.log_pos(c.player.center) + stats.log_mass(c.player.total_mass)
\ No newline at end of file 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 |