if got Key Error in move function create a new snake and calculate next best move
This commit is contained in:
+5
-1
@@ -96,7 +96,11 @@ class Server:
|
||||
|
||||
# move is called when your Battlesnake game is running game
|
||||
def _move(self, game_state:dict) -> dict:
|
||||
next_move = self.running_snake[game_state["game"]["id"]].choose_move(game_state)
|
||||
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:
|
||||
self.running_games[game_state["game"]["id"]].add_moves(game_state["turn"], game_state["board"], next_move)
|
||||
|
||||
Reference in New Issue
Block a user