change code to not have a big choose_move function and add todos to try fix some problems in game
This commit is contained in:
@@ -5,7 +5,7 @@ class BetterMasterSnake(TemplateSnake):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.name = "BetterMasterSnake"
|
||||
self.disabled_find_near_by_food = True
|
||||
self.disabled_check_if_food_is_near_by = True
|
||||
# Definiere die möglichen Bewegungsrichtungen
|
||||
self.min_safe_area = 2
|
||||
|
||||
@@ -90,6 +90,7 @@ class BetterMasterSnake(TemplateSnake):
|
||||
if snake["length"] < self.my_snake["length"] and location in [{"x": v["x"], "y": v["y"]} for k, v in self.get_possible_moves(snake["head"]).items()]:
|
||||
self.eat_the_snake_overwrite = True
|
||||
return direction
|
||||
#TODO: Check if snake on the way to the bood 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()]:
|
||||
remove.append(direction)
|
||||
|
||||
@@ -127,22 +128,36 @@ class BetterMasterSnake(TemplateSnake):
|
||||
|
||||
self.find_safe_positions()
|
||||
if self.eat_the_snake_overwrite:
|
||||
move = self.overwrite_eat_the_other_snake(move, game_data["turn"])
|
||||
|
||||
if self.game_type == "constrictor":
|
||||
move = self.selected_move_constrictor()
|
||||
else:
|
||||
move = self.selected_move_standard()
|
||||
|
||||
self.add_to_history({"turn": game_data["turn"], "data": self.calculations})
|
||||
return move if move else "up"
|
||||
|
||||
def overwrite_eat_the_other_snake(self, move:str, turn:int):
|
||||
if len(self.safe_positions) > 1:
|
||||
first_key = list(self.safe_positions.keys())[0]
|
||||
self.add_calculations({"function": "eat_the_snake_overwrite", "my_head": self.my_head, "move": move, "safe_positions": self.safe_positions, "selected_move": self.safe_positions[first_key]})
|
||||
self.add_to_history({"turn": game_data["turn"], "data": self.calculations})
|
||||
self.add_to_history({"turn": turn, "data": self.calculations})
|
||||
return self.safe_positions[first_key]
|
||||
|
||||
self.add_calculations({"function": "eat_the_snake_overwrite", "my_head": self.my_head, "move": move, "safe_positions": self.safe_positions})
|
||||
self.add_to_history({"turn": game_data["turn"], "data": self.calculations})
|
||||
self.add_to_history({"turn": turn, "data": self.calculations})
|
||||
return self.safe_positions
|
||||
|
||||
if self.game_type == "constrictor":
|
||||
#TODO: How to Fill the Gameboard best?
|
||||
def selected_move_constrictor(self):
|
||||
move = self.ensure_escape_route(self.find_direction())
|
||||
self.add_calculations({"function": "find_direction", "my_head": self.my_head, "move": move})
|
||||
else:
|
||||
return move
|
||||
|
||||
def selected_move_standard(self):
|
||||
# Finde den besten Weg zur Nahrung
|
||||
if self.is_food_nearby() or self.disabled_find_near_by_food:
|
||||
if self.is_food_nearby() or self.disabled_check_if_food_is_near_by:
|
||||
path_to_food = self.find_path_to_food()
|
||||
if path_to_food:
|
||||
move = self.move_towards(path_to_food[0])
|
||||
@@ -155,9 +170,7 @@ class BetterMasterSnake(TemplateSnake):
|
||||
# Überprfe, ob der Zug einen Ausweg lässt
|
||||
move = self.ensure_escape_route(move)
|
||||
self.add_calculations({"function": "ensure_escape_route", "my_head": self.my_head, "move": move, "safe_positions": self.safe_positions})
|
||||
|
||||
self.add_to_history({"turn": game_data["turn"], "data": self.calculations})
|
||||
return move if move else "up"
|
||||
return move
|
||||
|
||||
def is_food_nearby(self):
|
||||
for food in self.food_positions:
|
||||
|
||||
Reference in New Issue
Block a user