summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorSpitfireX <timm.weber@me.com>2015-08-11 02:10:15 +0200
committerSpitfireX <timm.weber@me.com>2015-08-11 02:10:15 +0200
commit349f9889e40d75a463bbdee07d67511faa097010 (patch)
tree647459edd9d44ced7e6b33991aa7b222bf6ff3be /main.py
parentdd6832293786ea0f3e7ba872893734db9fd1c30b (diff)
parent9b2078f8db3132754390db4905ac13009046f8bf (diff)
Merge branch 'master' of https://github.com/Windfisch/agario-frickel
Diffstat (limited to 'main.py')
-rw-r--r--main.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/main.py b/main.py
index 1fc04e4..09fb8ae 100644
--- a/main.py
+++ b/main.py
@@ -10,6 +10,7 @@ import random
import gui
import stats
from subscriber import DummySubscriber
+from interval_utils import *
# global vars
sub = DummySubscriber()
@@ -25,11 +26,10 @@ except:
# connect
c.connect(addr,token)
-# c.send_facebook(
- # 'g2gDYQFtAAAAEKO6L3c8C8/eXtbtbVJDGU5tAAAAUvOo7JuWAVSczT5Aj0eo0CvpeU8ijGzKy/gXBVCxhP5UO+ERH0jWjAo9bU1V7dU0GmwFr+SnzqWohx3qvG8Fg8RHlL17/y9ifVWpYUdweuODb9c=')
+c.send_facebook(
+ 'g2gDYQFtAAAAEKO6L3c8C8/eXtbtbVJDGU5tAAAAUvOo7JuWAVSczT5Aj0eo0CvpeU8ijGzKy/gXBVCxhP5UO+ERH0jWjAo9bU1V7dU0GmwFr+SnzqWohx3qvG8Fg8RHlL17/y9ifVWpYUdweuODb9c=')
-c.player.nick="test cell pls ignore"
-c.send_spectate()
+c.player.nick="so mal sehen"
# initialize GUI
@@ -42,18 +42,29 @@ while True:
gui.draw_frame()
if len(list(c.player.own_cells)) > 0:
+ runaway=False
+
my_smallest = min(map(lambda cell : cell.mass, c.player.own_cells))
- runaway_x, runaway_y=(0.0,0.0)
+ forbidden_intervals = []
for cell in c.world.cells.values():
- dist = math.sqrt((cell.pos[0]-c.player.center[0])**2 + (cell.pos[1]-c.player.center[1])**2)
+ relpos = ((cell.pos[0]-c.player.center[0]),(cell.pos[1]-c.player.center[1]))
+ dist = math.sqrt(relpos[0]**2+relpos[1]**2)
+
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
+ angle = math.atan2(relpos[1],relpos[0])
+ corridor_width = 2 * math.asin(cell.size / dist)
+ forbidden_intervals += canonicalize_angle_interval((angle-corridor_width, angle+corridor_width))
+ runaway=True
- runaway_r = math.sqrt(runaway_x**2 + runaway_y**2)
- if (runaway_r > 0):
- runaway_x, runaway_y = (c.player.center[0]+int(100*runaway_x / runaway_r)), (c.player.center[1]+int(100*runaway_y / runaway_r))
+
+ if (runaway):
+ forbidden_intervals = merge_intervals(forbidden_intervals)
+ allowed_intervals = invert_angle_intervals(forbidden_intervals)
+
+ (a,b) = find_largest_angle_interval(allowed_intervals)
+ runaway_angle = (a+b)/2
+ runaway_x, runaway_y = (c.player.center[0]+int(100*math.cos(runaway_angle))), (c.player.center[1]+int(100*math.sin(runaway_angle)))
c.send_target(runaway_x, runaway_y)
print ("Running away: " + str((runaway_x-c.player.center[0], runaway_y-c.player.center[1])))
@@ -76,4 +87,4 @@ while True:
gui.update()
stats.log_pos(c.player.center)
- stats.log_mass(c.player.total_mass) \ No newline at end of file
+ stats.log_mass(c.player.total_mass)