// Option 5: the academy draws the game its own way with ChessRooq's building blocks // (@chessrooq/arbiter-react: ChessBoard, useArbiterConnection, useArbiterGame). Rules, clocks and results stay on ChessRooq. import { createRoot } from 'react-dom/client'; import { useState, type CSSProperties } from 'react'; import { ChessBoard, formatClock, useArbiterConnection, useArbiterGame } from '@chessrooq/arbiter-react'; type Color = 'white' | 'black'; function AcademyGame({ url }: { url: string }) { const conn = useArbiterConnection(url); const { game, clock } = useArbiterGame(conn); const [msg, setMsg] = useState(); if (!conn || !game) { return

{conn?.status === 'closed' ? 'Could not connect. Get a new link.' : 'Connecting to your game…'}

; } const me: Color | undefined = conn.hello?.role === 'player' ? (conn.color ?? conn.hello.color) : undefined; const orientation: Color = me ?? 'white'; const opp: Color = orientation === 'white' ? 'black' : 'white'; const active = game.status === 'active'; const name = (c: Color) => (c === 'white' ? game.whiteName : game.blackName) ?? (c === 'white' ? 'White' : 'Black'); const rating = (c: Color) => (c === 'white' ? game.whiteRating : game.blackRating); const turn = (c: Color) => active && game.sideToMove === c; const fail = (p: Promise) => p.catch((e: Error) => setMsg(e.message)); const rows: [string, string | undefined][] = []; game.moves.forEach((m, i) => (i % 2 ? (rows[rows.length - 1][1] = m.san) : rows.push([m.san, undefined]))); const Player = ({ c }: { c: Color }) => (
{c === me ? 'You' : 'Opponent'} · {c}
{name(c)}{rating(c) ? · {rating(c)} : null}
{formatClock(clock[c])}
); return (
{ const p = conn.move(uci); p.catch((e: Error) => setMsg(e.message)); return p; } : undefined} />
Score sheet
Urali Chess Academy
{!active && (
{game.result === '1/2-1/2' ? 'Drawn game' : me ? ((game.result === '1-0') === (me === 'white') ? 'Well played: you won' : 'Game over: you lost') : `Result ${game.result}`}
{game.result} · {game.termination?.replace(/_/g, ' ')}
)} {rows.length === 0 && } {rows.map(([w, b], i) => ( ))}
#WhiteBlack
No moves yet. {active && game.ply < 2 ? 'Each side has 60 seconds for the first move.' : ''}
{i + 1}{w}{b ?? ''}
{me && active && (
{game.drawOfferBy && game.drawOfferBy !== me && }
)} {msg &&

setMsg(undefined)}>{msg}

}

This layout, the colours and the score sheet are the academy's own code. ChessRooq supplies the board, the live connection, the clocks and the rules.

); } const serif = '"Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif'; const layout: CSSProperties = { display: 'grid', gridTemplateColumns: 'minmax(0, 1.25fr) minmax(260px, 1fr)', gap: 22, alignItems: 'start', // the board's own colours, set by the academy through CSS variables ['--arbiter-light' as string]: '#efe3cc', ['--arbiter-dark' as string]: '#a87b52', ['--arbiter-last' as string]: 'rgba(200, 137, 43, .55)', ['--arbiter-target' as string]: 'rgba(18, 60, 58, .35)' } as CSSProperties; const playerCard: CSSProperties = { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12, background: '#123c3a', borderRadius: 16, padding: '12px 16px', outlineOffset: 2 }; const clockStyle: CSSProperties = { fontVariantNumeric: 'tabular-nums', fontSize: 30, fontWeight: 700, borderRadius: 12, padding: '4px 14px', minWidth: 110, textAlign: 'center', transition: 'background .2s' }; const frameStyle: CSSProperties = { padding: 12, borderRadius: 18, background: 'linear-gradient(145deg, #5a3d22, #3b2614)', boxShadow: '0 18px 40px rgba(59, 38, 20, .35)' }; const sheet: CSSProperties = { background: '#fff', border: '1px solid #e7dfcf', borderRadius: 18, padding: 22, boxShadow: '0 10px 30px rgba(18,60,58,.06)', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif' }; const th: CSSProperties = { padding: '6px 8px', borderBottom: '1px solid #e7dfcf', fontWeight: 600 }; const td: CSSProperties = { padding: '6px 8px', fontWeight: 500 }; const btn: CSSProperties = { font: 'inherit', fontSize: 14, fontWeight: 600, border: '1px solid #d8cfbd', background: '#fff', borderRadius: 999, padding: '9px 16px', cursor: 'pointer' }; /** Mounts the academy's board for a ChessRooq realtime URL (from the academy's server). */ export function mount(el: HTMLElement, url: string) { const root = createRoot(el); root.render(); return () => root.unmount(); } (window as unknown as { UraliBoard: unknown }).UraliBoard = { mount };