Files
ai-chess/src/ai_chess/state.py
T
ai-chess 0eec263fd8 feat(ui): floating moves under board, chat full-height right, refined eval bar
Layout (after iterative feedback):
- Two columns: board+eval (left, square) | chat full-height (right).
- Moves row floats just under the board as a compact one-row strip with
  the controls (new game / settings) — replaces the old right sidebar.
- Board sized imperatively via fitBoard + ResizeObserver; eval bar height
  matches the board exactly (no overflow into neighbours).

Eval bar:
- 36px wide (was 28); text fits without pill background.
- System sans-serif, 10.5px / 700 weight, tabular-nums.
- Text positioned on whichever side is winning (bottom-white-half when
  white ahead → dark text; top-black-half when black ahead → light).
- Sign now correct: backend stores raw cp from side-to-move; frontend
  flips when FEN says "b" so the bar always reflects white POV.

Replay:
- evalByFen on the client gets backfilled from /api/state's new `evals`
  list (backend keeps state.eval_cache per game). Clicking past bubbles
  now restores the stockfish eval for that ply.
- renderBoard clears stockfish arrow when no eval is known yet for the
  shown FEN, so the arrow no longer 'lags' onto the next position.

Auto-focus:
- Latest played move is highlighted in both the chat bubble list and
  the moves strip when in live mode (viewPly === null).
- scrollIntoView keeps the active bubble/SAN visible after each move.
2026-05-15 00:17:33 +03:00

49 lines
1.5 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional
from ai_chess.chess_game import ChessGame
from ai_chess.events import EventBus
from ai_chess.settings import Settings, load_settings
from ai_chess.sides import Side
ROOT = Path(__file__).resolve().parents[2]
GAMES_DIR = ROOT / "games"
CONFIG_DIR = ROOT / "config"
LOGS_DIR = ROOT / "logs"
PUBLIC_DIR = ROOT / "public"
@dataclass
class AgentBinding:
side: Side
agent: str # "claude" | "codex"
model: str
effort: str = ""
extra: dict = field(default_factory=dict)
def to_dict(self) -> dict:
return {"side": self.side.value, "agent": self.agent, "model": self.model,
"effort": self.effort, **self.extra}
class AppState:
def __init__(self) -> None:
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
GAMES_DIR.mkdir(parents=True, exist_ok=True)
LOGS_DIR.mkdir(parents=True, exist_ok=True)
self.settings: Settings = load_settings(CONFIG_DIR / "settings.json")
self.events: EventBus = EventBus()
self.game: Optional[ChessGame] = None
self.bindings: dict[Side, AgentBinding] = {}
self.first_move_sent: dict[Side, bool] = {Side.WHITE: False, Side.BLACK: False}
self.nudge_count: dict[Side, int] = {Side.WHITE: 0, Side.BLACK: 0}
# fen → {cp, mate, best_uci, pv, fen} — populated by eval_bridge per move
self.eval_cache: dict[str, dict] = {}
state = AppState()