From 7930d1037ae8e6625453538c2623f1f708847d79 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Thu, 13 Aug 2015 05:22:04 +0200 Subject: Added basic cell weighting Very basic and still needs several refinements. --- strategy.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'strategy.py') diff --git a/strategy.py b/strategy.py index e093ad6..37dc340 100644 --- a/strategy.py +++ b/strategy.py @@ -15,10 +15,30 @@ class Strategy: return math.sqrt((cell.pos[0]-self.c.player.center[0])**2 + (cell.pos[1]-self.c.player.center[1])**2) def edible(self, cell): - return (cell.is_food) or (cell.mass <= sorted(self.c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75) and not (cell.is_virus) + return ((cell.is_food) or (cell.mass <= sorted(self.c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75)) and not (cell.is_virus) + + def threat(self, cell): + if cell.is_virus and (cell.mass <= sorted(self.c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75): + return True + elif (cell.mass <= sorted(self.c.player.own_cells, key = lambda x: x.mass)[0].mass * 1.25): + return True + else: + return False def weight_cell(self, cell): - pass + df = (1/self.dist(cell)) + if self.edible(cell): + if cell.is_food: + return cell.mass * df + else: + return cell.mass * df #todo: factor for optimal food mass + elif self.threat(cell): + if cell.is_virus: + return -cell.mass * df * 100 + else: + return -cell.mass * df + else: + return 0 def process_frame(self): runaway = False @@ -148,6 +168,10 @@ class Strategy: if len(food) > 0: self.target = (food[0].pos[0], food[0].pos[1]) self.target_cell = food[0] + + print(self.target_cell.mass) + print(self.weight_cell(self.target_cell)) + self.has_target = True self.color = (0,0,255) print("Found food at: " + str(food[0].pos)) -- cgit v1.2.3