test new sname and add save history code into main

This commit is contained in:
2024-04-01 05:21:52 +02:00
parent 2c7cf98309
commit 439bd07061
2 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
from snakes.DummSnake import DummSnake from snakes.DummSnake import DummSnake
from snakes.LogicSnake import LogicSnake from snakes.LogicSnake import LogicSnake
from snakes.AStarSnake import AStarSnake
SNAKE = DummSnake() SNAKE = AStarSnake()
+6
View File
@@ -12,6 +12,7 @@
from config import SNAKE from config import SNAKE
import typing import typing
import json, os
# info is called when you create your Battlesnake on play.battlesnake.com # info is called when you create your Battlesnake on play.battlesnake.com
# and controls your Battlesnake's appearance # and controls your Battlesnake's appearance
@@ -29,10 +30,15 @@ def info() -> typing.Dict:
# start is called when your Battlesnake begins a game # start is called when your Battlesnake begins a game
def start(game_state: typing.Dict): def start(game_state: typing.Dict):
SNAKE.clear_history()
print("GAME START") print("GAME START")
# end is called when your Battlesnake finishes a game # end is called when your Battlesnake finishes a game
def end(game_state: typing.Dict): 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") print("GAME OVER\n")
def move(game_state: typing.Dict) -> typing.Dict: def move(game_state: typing.Dict) -> typing.Dict: