test new sname and add save history code into main
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user