Got the starter snake going
This commit is contained in:
parent
6de4111b05
commit
3654aebb5e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
deploy
|
||||||
|
publish.sh
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
|
@ -13,4 +13,4 @@ RUN pip install --upgrade pip && pip install -r requirements.txt
|
||||||
|
|
||||||
# Run Battlesnake
|
# Run Battlesnake
|
||||||
ENTRYPOINT [ "python", "server.py" ]
|
ENTRYPOINT [ "python", "server.py" ]
|
||||||
CMD [ "StarterSnake" ]
|
CMD [ "starter_snake" ]
|
10
requirements.txt
Normal file
10
requirements.txt
Normal file
|
@ -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
|
11
server.py
11
server.py
|
@ -10,24 +10,25 @@ from snakes.snake import Snake
|
||||||
|
|
||||||
|
|
||||||
def run_server(snake: Snake, host: str, port: int):
|
def run_server(snake: Snake, host: str, port: int):
|
||||||
|
path = snake.name
|
||||||
app = Flask("Battlesnake")
|
app = Flask("Battlesnake")
|
||||||
|
|
||||||
@app.get("/")
|
@app.get(f"/{path}/")
|
||||||
def on_info():
|
def on_info():
|
||||||
return snake.info()
|
return snake.info()
|
||||||
|
|
||||||
@app.post("/start")
|
@app.post(f"/{path}/start")
|
||||||
def on_start():
|
def on_start():
|
||||||
game_state = request.get_json()
|
game_state = request.get_json()
|
||||||
snake.start(game_state)
|
snake.start(game_state)
|
||||||
return "ok"
|
return "ok"
|
||||||
|
|
||||||
@app.post("/move")
|
@app.post(f"/{path}/move")
|
||||||
def on_move():
|
def on_move():
|
||||||
game_state = request.get_json()
|
game_state = request.get_json()
|
||||||
return snake.move(game_state)
|
return snake.move(game_state)
|
||||||
|
|
||||||
@app.post("/end")
|
@app.post(f"/{path}/end")
|
||||||
def on_end():
|
def on_end():
|
||||||
game_state = request.get_json()
|
game_state = request.get_json()
|
||||||
snake.end(game_state)
|
snake.end(game_state)
|
||||||
|
@ -42,7 +43,7 @@ def run_server(snake: Snake, host: str, port: int):
|
||||||
|
|
||||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
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)
|
app.run(host=host, port=port)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,10 @@ import typing
|
||||||
class Snake:
|
class Snake:
|
||||||
|
|
||||||
SNAKES: typing.Dict[str, typing.Type["Snake"]] = {}
|
SNAKES: typing.Dict[str, typing.Type["Snake"]] = {}
|
||||||
|
name = "snake"
|
||||||
|
|
||||||
def __init_subclass__(cls) -> None:
|
def __init_subclass__(cls) -> None:
|
||||||
cls.SNAKES[cls.__name__] = cls
|
cls.SNAKES[cls.name] = cls
|
||||||
|
|
||||||
def info(self) -> typing.Dict:
|
def info(self) -> typing.Dict:
|
||||||
'''info is called when you create your Battlesnake on play.battlesnake.com
|
'''info is called when you create your Battlesnake on play.battlesnake.com
|
||||||
|
|
|
@ -8,6 +8,8 @@ from .snake import Snake
|
||||||
class StarterSnake(Snake):
|
class StarterSnake(Snake):
|
||||||
'''Snake from Battlesnake's starter snake repo'''
|
'''Snake from Battlesnake's starter snake repo'''
|
||||||
|
|
||||||
|
name = "starter_snake"
|
||||||
|
|
||||||
def info(self) -> typing.Dict:
|
def info(self) -> typing.Dict:
|
||||||
print("INFO")
|
print("INFO")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user