From ccd6387920432c9a8263a2b9813d552642e6546a Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 1 Sep 2015 18:04:04 +0200 Subject: FancyClient has latency detection and rates motion steadyness --- geometry.py | 4 ++++ main.py | 4 ++-- strategy.py | 2 +- subscriber.py | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/geometry.py b/geometry.py index d69add8..0fa1114 100644 --- a/geometry.py +++ b/geometry.py @@ -25,3 +25,7 @@ def is_colinear(points, epsilon=1): return False return True +def angle_diff(alpha, beta): + result = (alpha-beta) % (2*math.pi) + if result > math.pi: result -= 2*math.pi + return result diff --git a/main.py b/main.py index ab92ce3..6857d45 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from agarnet.agarnet import client +from fancyclient import FancyClient from agarnet.agarnet import utils import pygame from pygame import gfxdraw @@ -72,7 +72,7 @@ else: # global vars sub = EnhancingSubscriber() -c = client.Client(sub) +c = FancyClient(sub) sub.set_client(c) stats = stats.Stats(c) diff --git a/strategy.py b/strategy.py index 900cf8f..d0554c9 100644 --- a/strategy.py +++ b/strategy.py @@ -186,7 +186,7 @@ class Strategy: self.gui.draw_bar(((100,40),(500,24)), success_rate, thresh=.98, color=(0,0,127)) - if success_rate >= 0.98: + if success_rate >= 0.98 and self.c.movement_steadyness() < math.pi/4: self.c.send_shoot() diff --git a/subscriber.py b/subscriber.py index b89a6a9..6c2bcce 100644 --- a/subscriber.py +++ b/subscriber.py @@ -2,6 +2,8 @@ from log import log from collections import deque import sys import mechanics +import time +import math class DummySubscriber: def on_connect_error(self,s): @@ -114,6 +116,16 @@ class EnhancingSubscriber(DummySubscriber): if self.time % 100 == 0: self.cleanup_victims() + + + try: + angle = math.atan2(self.c.current_target[1] - self.c.player.center.y, self.c.current_target[0] - self.c.player.center.x) + except: + angle = 0 + + self.c.anglelog.append(angle) + + # create and purge poslog history, movement and movement_angle for cid in self.history: self.history[cid].stale = True @@ -135,6 +147,7 @@ class EnhancingSubscriber(DummySubscriber): if not hasattr(cell, "spawntime"): cell.spawntime = self.c.world.time + cell.spawnrealtime = time.time() try: oldpos = cell.poslog[-3-1] @@ -197,6 +210,9 @@ class EnhancingSubscriber(DummySubscriber): cell.shoot_vec = None cell.calmed_down = False + if cell.parent != None and cell.parent in self.c.player.own_cells: + # we have split. use this for lag calculation + self.c.report_actual_event("split", cell.spawnrealtime) elif cell.is_virus: try: if cell.parent == None and cell.movement.len() > 0: @@ -246,6 +262,11 @@ class EnhancingSubscriber(DummySubscriber): except: cell.shoot_vec = None cell.calmed_down = False + + if cell.parent != None and cell.parent in self.c.player.own_cells: + # we ejected mass. use this for lag calculation + self.c.report_actual_event("shoot", cell.spawnrealtime) + except ValueError: # if no possible parents are found, min will raise a ValueError. ignore that. pass -- cgit v1.2.1