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
This commit is contained in:
41
server/model.py
Normal file
41
server/model.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user