Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TypedDicts for Battlesnake /move endpoint
from dataclasses import dataclass
from types import TypedDict, Annotated, Literal
class Squad(TypedDict):
allowBodyCollisions: bool
sharedElimination: bool
sharedHealth: bool
sharedLength: bool
class Royale(TypedDict):
shrinkEveryNTurns: int
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment