diff --git a/.gitignore b/.gitignore index 5d381cc..d1549c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +deploy +publish.sh + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/Dockerfile b/Dockerfile index c785aeb..01fe337 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,4 @@ RUN pip install --upgrade pip && pip install -r requirements.txt # Run Battlesnake ENTRYPOINT [ "python", "server.py" ] -CMD [ "StarterSnake" ] \ No newline at end of file +CMD [ "starter_snake" ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..31fcf80 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +blinker==1.6.2 +click==8.1.7 +Flask==2.3.3 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +mypy==1.5.1 +mypy-extensions==1.0.0 +typing_extensions==4.7.1 +Werkzeug==2.3.7 diff --git a/server.py b/server.py index 291d71b..43b3a1b 100644 --- a/server.py +++ b/server.py @@ -10,24 +10,25 @@ from snakes.snake import Snake def run_server(snake: Snake, host: str, port: int): + path = snake.name app = Flask("Battlesnake") - @app.get("/") + @app.get(f"/{path}/") def on_info(): return snake.info() - @app.post("/start") + @app.post(f"/{path}/start") def on_start(): game_state = request.get_json() snake.start(game_state) return "ok" - @app.post("/move") + @app.post(f"/{path}/move") def on_move(): game_state = request.get_json() return snake.move(game_state) - @app.post("/end") + @app.post(f"/{path}/end") def on_end(): game_state = request.get_json() snake.end(game_state) @@ -42,7 +43,7 @@ def run_server(snake: Snake, host: str, port: int): logging.getLogger("werkzeug").setLevel(logging.ERROR) - print(f"\nRunning Battlesnake at http://{host}:{port}") + print(f"\nRunning Battlesnake at http://{host}:{port}/{path}") app.run(host=host, port=port) diff --git a/snakes/snake.py b/snakes/snake.py index 2b535ed..3939d6c 100644 --- a/snakes/snake.py +++ b/snakes/snake.py @@ -4,9 +4,10 @@ import typing class Snake: SNAKES: typing.Dict[str, typing.Type["Snake"]] = {} + name = "snake" def __init_subclass__(cls) -> None: - cls.SNAKES[cls.__name__] = cls + cls.SNAKES[cls.name] = cls def info(self) -> typing.Dict: '''info is called when you create your Battlesnake on play.battlesnake.com diff --git a/snakes/starter_snake.py b/snakes/starter_snake.py index e70438f..b00430a 100644 --- a/snakes/starter_snake.py +++ b/snakes/starter_snake.py @@ -8,6 +8,8 @@ from .snake import Snake class StarterSnake(Snake): '''Snake from Battlesnake's starter snake repo''' + name = "starter_snake" + def info(self) -> typing.Dict: print("INFO")