fixed reload setting in init, added typed dicts for the /move endpoint, implemented basic /start and /end

This commit is contained in:
2021-10-14 20:21:23 +00:00
parent 4a3a67e0d0
commit 66160eb7a6
2 changed files with 78 additions and 3 deletions

View File

@@ -1,3 +1,8 @@
from dataclasses import dataclass
from pprint import pprint as pp
from typing import TypedDict, Literal, Annotated
from uuid import uuid4
from flask import Flask, jsonify, request
app = Flask(__name__)
@@ -19,17 +24,86 @@ def home():
@app.route("/start", methods=["POST"])
def start():
pass
return "hi", 200
class Squad(TypedDict):
allowBodyCollisions: bool
sharedElimination: bool
sharedHealth: bool
sharedLength: bool
class Royale(TypedDict):
shrinkEveryNTurns: int
@dataclass
class ValueRange:
min: int
max: int
class Settings(TypedDict):
foodSpawnChance: Annotated[int, ValueRange(0, 10)]
hazardDamagePerTurn: int
minimumFood: int
royale: Royale
squad: Squad
class Ruleset(TypedDict):
name: Literal["standard", "solo", "royale", "squad", "constrictor"]
settings: Settings
version: str
class Game(TypedDict):
id: uuid4
ruleset: Ruleset
source: str
timeout: Annotated[int, "milliseconds"]
class Coordinate(TypedDict):
x: int
y: int
class Snake(TypedDict):
body: list[Coordinate]
head: Coordinate
health: Annotated[int, ValueRange(0, 100)]
id: str
latency: int
length: int
name: str
shout: str
squad: str
class Board(TypedDict):
food: list[Coordinate]
hazards: list[Coordinate]
height: int
width: int
snakes: list[Snake]
@app.route("/move", methods=["POST"])
def move():
game_info = request.get_json()
game: Game = game_info["game"]
turn: int = game_info["turn"]
board: Board = game_info["board"]
you: Snake = game_info["you"]
return jsonify({"move": "up"})
@app.route("/end", methods=["POST"])
def end():
pass
return "hi", 200
if __name__ == "__main__":

View File

@@ -6,4 +6,5 @@ socket = battlesnake.sock
chmod-socket = 660
vacuum = true
die-on-term = true
touch-reload = /home/vagrant/PythonVision/app.py
touch-reload = /home/zev/battlesnake/battlesnake/app.py
logto = /home/zev/battlesnake.log