Created
October 14, 2021 20:16
-
-
Save zevaverbach/6fba43ee01c70d71bbe620030e19ead6 to your computer and use it in GitHub Desktop.
TypedDicts for Battlesnake /move endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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