summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/main.py b/main.py
index 3f09e02..91feecc 100644
--- a/main.py
+++ b/main.py
@@ -7,6 +7,7 @@ import sys
import math
import time
import gui
+import random
from subscriber import DummySubscriber
sub = DummySubscriber()
@@ -45,7 +46,7 @@ while True:
runaway_x, runaway_y=(0.0,0.0)
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)
- if dist < cell.size*4 and cell.mass > my_smallest:
+ 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
@@ -53,9 +54,23 @@ while 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))
-
+
c.send_target(runaway_x, runaway_y)
print (str((runaway_x-c.player.center[0], runaway_y-c.player.center[1])))
gui.debug_line(c.player.center, (runaway_x,runaway_y),(255,0,0))
gui.update()
-
+ else:
+ food = list(filter(lambda x: x.is_food or x.mass <= sorted(c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75, c.world.cells.values()))
+ def dist(cell): return math.sqrt((cell.pos[0]-c.player.center[0])**2 + (cell.pos[1]-c.player.center[1])**2)
+ food = sorted(food, key = dist)
+
+ if len(food) > 0:
+ c.send_target(food[0].pos[0], food[0].pos[1])
+ gui.debug_line(c.player.center, food[0].pos,(0,0,255))
+ gui.update()
+ else:
+ rx = c.player.center[0] + random.randrange(-400, 401)
+ ry = c.player.center[1] + random.randrange(-400, 401)
+ c.send_target(rx, ry)
+ gui.debug_line(c.player.center, (rx, ry),(0,255,0))
+ gui.update() \ No newline at end of file