if got Key Error in move function create a new snake and calculate next best move

This commit is contained in:
2024-04-17 15:55:37 +02:00
parent 5ce12d70c1
commit 8c57e48f60
+4
View File
@@ -96,6 +96,10 @@ class Server:
# move is called when your Battlesnake game is running game
def _move(self, game_state:dict) -> dict:
try:
next_move = self.running_snake[game_state["game"]["id"]].choose_move(game_state)
except KeyError:
self.running_snake[game_state["game"]["id"]] = SnakeBuilder.build(self.snake_type)
next_move = self.running_snake[game_state["game"]["id"]].choose_move(game_state)
if self.store_game_state: