diff options
author | Florian Jung <flo@windfisch.org> | 2015-09-03 18:23:27 +0200 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2015-09-03 18:23:27 +0200 |
commit | 3044000ea30e423fa4e2f973c0bea5012c1f4ee0 (patch) | |
tree | ae5fa97e935da31d0eaf122f735b26f55b8a791f /fancyclient.py | |
parent | ccd6387920432c9a8263a2b9813d552642e6546a (diff) |
forgot to add fancyclient.py m(fancyclient
Diffstat (limited to 'fancyclient.py')
-rw-r--r-- | fancyclient.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/fancyclient.py b/fancyclient.py new file mode 100644 index 0000000..fe2854c --- /dev/null +++ b/fancyclient.py @@ -0,0 +1,60 @@ +from agarnet.agarnet import client +import time +import math +from collections import deque +from geometry import angle_diff + +class FancyClient(client.Client): + def __init__(self, sub): + super().__init__(sub) + self.last = {"split":0, "shoot":0} + self.anglelog = deque(maxlen=30) + self.latency = 0.1 + + def send_split(self): + super().send_split() + if max(map(lambda c:c.mass, self.player.own_cells)) >= 40: + self.report_send_event("split") + + def send_shoot(self): + super().send_shoot() + if max(map(lambda c:c.mass, self.player.own_cells)) >= 40: + self.report_send_event("shoot") + + def send_target(self, x, y): + super().send_target(x, y) + self.current_target = (x,y) + + + def movement_steadyness(self): + nvalues = int(self.latency * 1.33 * 30) + 5 + change = 0 + try: + for i in range(0,nvalues): + change += abs(angle_diff(self.anglelog[-1-i], self.anglelog[-2-i])) + + change /= nvalues + print("movement_steadyness returns %.3f"%change) + return change + except: + print("movement_steadyness has too few data") + return 999 + + def report_send_event(self, evtype): + """evtype can be 'split' or 'shoot'""" + t = time.time() + if t - self.last[evtype] > 3: + print("overwriting pending %s event" % evtype) + self.last[evtype] = t + else: + print("ignoring %s event because there is already one pending" % evtype) + + def report_actual_event(self, evtype, t): + lag = t - self.last[evtype] + if lag > 3: + print("unplausibly high lag of %.2fsec" % lag) + else: + print("lag of %.1fmsec" % (lag*1000)) + self.latency = lag + + |