Skip to content

Instantly share code, notes, and snippets.

@zevaverbach
Created October 14, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zevaverbach/6fba43ee01c70d71bbe620030e19ead6 to your computer and use it in GitHub Desktop.
Save zevaverbach/6fba43ee01c70d71bbe620030e19ead6 to your computer and use it in GitHub Desktop.
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
@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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment