From 439bd070611a22284098343d83bd439e272bccaa Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Mon, 1 Apr 2024 05:21:52 +0200 Subject: [PATCH] test new sname and add save history code into main --- config.py | 3 ++- main.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index e007a3c..1c873ec 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,5 @@ from snakes.DummSnake import DummSnake from snakes.LogicSnake import LogicSnake +from snakes.AStarSnake import AStarSnake -SNAKE = DummSnake() +SNAKE = AStarSnake() diff --git a/main.py b/main.py index 086940e..8d91fd9 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ from config import SNAKE import typing +import json, os # info is called when you create your Battlesnake on play.battlesnake.com # and controls your Battlesnake's appearance @@ -29,10 +30,15 @@ def info() -> typing.Dict: # start is called when your Battlesnake begins a game def start(game_state: typing.Dict): + SNAKE.clear_history() print("GAME START") # end is called when your Battlesnake finishes a game def end(game_state: typing.Dict): + os.makedirs(f"{os.path.dirname(__file__)}/history", exist_ok=True) + with open(f"{os.path.dirname(__file__)}/history/{SNAKE.__class__.__name__}-{game_state['game']['id']}", "w") as f: + json.dump(SNAKE.get_history(), f, ensure_ascii=False) + print("GAME OVER\n") def move(game_state: typing.Dict) -> typing.Dict: