From 0b38518540aef32e5420aed456acfa7402200215 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Mon, 10 Aug 2015 22:30:18 +0200 Subject: Made default window size better line up with the actual vision range --- gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.py b/gui.py index 0b27187..bd59f88 100644 --- a/gui.py +++ b/gui.py @@ -22,7 +22,7 @@ logging = False input = False clock = pygame.time.Clock() -screensize=(800,600) +screensize=(1280, 720) screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE) def debug_line(p1,p2,col): -- cgit v1.2.3 From a4219f004cea5392fa5e9356ee9f42bc877c8224 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Mon, 10 Aug 2015 23:32:15 +0200 Subject: Added basic statistics - added a new stats module - added mass and position tracking to the current cell logic --- main.py | 15 +++++++++------ stats.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 stats.py diff --git a/main.py b/main.py index aa1430c..a4c77f2 100644 --- a/main.py +++ b/main.py @@ -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 -- cgit v1.2.3 From 06ec1ca17d38ebb8b1a901b938f5f812e494e26e Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Tue, 11 Aug 2015 00:31:30 +0200 Subject: Added more debug drawing options --- gui.py | 31 +++++++++++++++++++++++++++++-- main.py | 10 ++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/gui.py b/gui.py index bd59f88..7040ab0 100644 --- a/gui.py +++ b/gui.py @@ -25,9 +25,36 @@ clock = pygame.time.Clock() screensize=(1280, 720) screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE) -def debug_line(p1,p2,col): +def debug_line(p1, p2, color): global screen - pygame.draw.line(screen, col, world_to_win_pt(p1, c.player.center), world_to_win_pt(p2, c.player.center)) + p1win = world_to_win_pt(p1, c.player.center) + p2win = world_to_win_pt(p2, c.player.center) + gfxdraw.line(screen, p1win[0], p1win[1], p2win[0], p2win[1], color) + +def debug_box(rect, color, filled=False): + if filled: + screen.fill(color, rect) + else: + gfxdraw.rectangle(screen, rect, color) + +def debug_circle(pos, r, color, filled=False): + if filled: + gfxdraw.filled_circle(screen, pos[0], pos[1], r, color) + else: + gfxdraw.circle(screen, pos[0], pos[1], r, color) + gfxdraw.aacircle(screen, pos[0], pos[1], r, color) + +def debug_polygon(polygon, color, filled=False): + polygon = list(map(lambda x: world_to_win_pt(x, c.player.center), polygon)) + if filled: + gfxdraw.filled_polygon(screen, polygon, color) + else: + gfxdraw.polygon(screen, polygon, color) + gfxdraw.aapolygon(screen, polygon, color) + +def debug_path(path, color): + for i in range(1, len(path)): + debug_line(path[i-1], path[i], color) def update(): pygame.display.update() diff --git a/main.py b/main.py index a4c77f2..af452fa 100644 --- a/main.py +++ b/main.py @@ -25,10 +25,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.player.nick="test cell pls ignore" c.send_spectate() @@ -58,7 +58,6 @@ while True: c.send_target(runaway_x, runaway_y) print ("Running away: " + 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 and not x.is_virus, 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) @@ -67,15 +66,14 @@ while True: 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() print("Found food at: " + str(food[0].pos)) 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() print("Nothing to do, heading to random destination: " + str((rx, ry))) + gui.update() stats.log_pos(c.player.center) stats.log_mass(c.player.total_mass) \ No newline at end of file -- cgit v1.2.3