fix not used code for flood_fill_count
This commit is contained in:
@@ -218,7 +218,7 @@ class BetterMasterSnake(TemplateSnake):
|
||||
future_position = self.safe_positions[move]
|
||||
except KeyError:
|
||||
for move, pos in self.safe_positions.items():
|
||||
if self.is_near_tail((pos["x"], pos["y"]), (self.my_body[-1]['x'], self.my_body[-1]['y'])):
|
||||
if self.is_near_tail(pos, (self.my_body[-1]['x'], self.my_body[-1]['y'])):
|
||||
self.add_calculations({"function": "ensure_escape_route", "move": move, "is_near_tail": True})
|
||||
move = self.move_towards(pos)
|
||||
return move
|
||||
@@ -237,18 +237,23 @@ class BetterMasterSnake(TemplateSnake):
|
||||
|
||||
accessible_area_count = self.flood_fill_count(future_coords, [(part['x'], part['y']) for part in self.my_body])
|
||||
self.add_calculations({
|
||||
"function": "ensure_escape_route",
|
||||
"function": "flood_fill_count",
|
||||
"move": move,
|
||||
"future_coords": future_coords,
|
||||
"tail_position": tail_position,
|
||||
"accessible_area_count": accessible_area_count,
|
||||
})
|
||||
|
||||
# TODO: Fix - Snake Neat to find the best way - Close to the Tail and maybe fill most free cells as posible
|
||||
#if accessible_area_count < self.min_safe_area:
|
||||
# # Finde den nächstgelegenen Zug zum Schwanz
|
||||
# print(self.safe_positions.keys())
|
||||
# closest_move = min(self.safe_positions.keys(), key=lambda m: self.distance_to_tail(self.safe_positions[m], tail_position))
|
||||
# accessible_area_count = self.flood_fill_count((self.safe_positions[closest_move]["x"], self.safe_positions[closest_move]["y"]), [(part['x'], part['y']) for part in self.my_body])
|
||||
|
||||
# print(closest_move, accessible_area_count, accessible_area_count >= self.min_safe_area)
|
||||
# # Überprüfe, ob der nächstgelegene Zug eine größere zugängliche Fläche hat
|
||||
# if self.flood_fill_count(self.safe_positions[closest_move], [(part['x'], part['y']) for part in self.my_body]) >= self.min_safe_area:
|
||||
# if accessible_area_count >= self.min_safe_area:
|
||||
# return closest_move
|
||||
|
||||
return move
|
||||
@@ -263,7 +268,7 @@ class BetterMasterSnake(TemplateSnake):
|
||||
if current not in visited:
|
||||
visited.add(current)
|
||||
for direction, pos in self.safe_positions.items():
|
||||
neighbor = (current[0] + pos[0], current[1] + pos[1])
|
||||
neighbor = (pos["x"], pos["y"])
|
||||
if (neighbor not in visited and neighbor not in body_set and
|
||||
0 <= neighbor[0] < self.board_width and
|
||||
0 <= neighbor[1] < self.board_height):
|
||||
@@ -272,10 +277,10 @@ class BetterMasterSnake(TemplateSnake):
|
||||
return len(visited)
|
||||
|
||||
def is_near_tail(self, position, tail):
|
||||
return abs(position[0] - tail[0]) + abs(position[1] - tail[1]) <= 2
|
||||
return abs(position["x"] - tail[0]) + abs(position["y"] - tail[1]) <= 2
|
||||
|
||||
def distance_to_tail(self, position, tail):
|
||||
return abs(position[0] - tail[0]) + abs(position[1] - tail[1])
|
||||
return abs(position["x"] - tail[0]) + abs(position["y"] - tail[1])
|
||||
|
||||
def a_star_search(self, start, goal, obstacles, board_width, board_height):
|
||||
# Helper functions
|
||||
|
||||
Reference in New Issue
Block a user