when both posisions are not save keep them in safe posisions - remove other useless MasterSnake
This commit is contained in:
@@ -119,6 +119,7 @@ class TemplateSnake:
|
||||
|
||||
def avoid_get_eaten_by_other_snakes(self):
|
||||
remove = []
|
||||
no_way_out = {}
|
||||
for snake in self.other_snakes:
|
||||
for direction, location in self.safe_positions.items():
|
||||
if len(self.safe_positions) > 1:
|
||||
@@ -128,12 +129,16 @@ class TemplateSnake:
|
||||
self.kill_the_snake = direction
|
||||
#TODO: Check if snake on the way to the food here and only remove this pos
|
||||
elif location in [{"x": v["x"], "y": v["y"]} for k, v in self.get_possible_moves(snake["head"]).items()]:
|
||||
no_way_out[direction] = location
|
||||
remove.append(direction)
|
||||
|
||||
remove = set(remove)
|
||||
for direction in remove:
|
||||
del self.safe_positions[direction]
|
||||
|
||||
if len(self.safe_positions) == 0:
|
||||
self.safe_positions = no_way_out
|
||||
|
||||
self.add_calculations({"function": "avoid_get_eaten_by_other_snakes", "other_snakes": self.other_snakes, "safe_positions": self.safe_positions})
|
||||
|
||||
def find_safe_positions(self):
|
||||
|
||||
Reference in New Issue
Block a user