Files
codexPySnake/server/model.py
Vladyslav Doloman 9043ba81c0 Server scaffold: protocol + config + transport abstraction + tick loop skeleton
- Protocol: PacketType, TLV Body types, QUIC varint, header, input_broadcast
  and config_update builders, 2-bit body bitpacking helper
- Config/model: live-config ServerConfig, basic GameState/Snake/Session
- Transport: InMemoryTransport placeholder and QUIC server stub
- Server: asyncio tick loop, periodic config_update broadcast, immediate
  input_broadcast relay; main entry and run.py
2025-10-07 20:02:28 +03:00

42 lines
808 B
Python

from __future__ import annotations
from dataclasses import dataclass, field
from typing import Deque, Dict, List, Optional, Tuple
from collections import deque
from .protocol import Direction
Coord = Tuple[int, int]
@dataclass
class Snake:
snake_id: int
head: Coord
direction: Direction
body: Deque[Coord] = field(default_factory=deque) # includes head at index 0
@property
def length(self) -> int:
return len(self.body)
@dataclass
class PlayerSession:
player_id: int
name: str
color_id: int
peer: object # transport-specific handle
input_seq: int = 0
@dataclass
class GameState:
width: int
height: int
snakes: Dict[int, Snake] = field(default_factory=dict)
apples: List[Coord] = field(default_factory=list)
tick: int = 0