diff --git a/src/game/MatchBoard.tsx b/src/game/MatchBoard.tsx index 9493300..7e243ba 100644 --- a/src/game/MatchBoard.tsx +++ b/src/game/MatchBoard.tsx @@ -7,8 +7,8 @@ import type { LaneView, MatchView, UIAction, UICard } from './types.ts'; type Sheet = { kind: 'card'; card: UICard; side: 'mine' | 'theirs' } | { kind: 'lane'; lane: LaneView } | { kind: 'concede' } | null; /** The match screen itself: board, thumb dock and bottom sheets. Controllers (local bot / hosted lobby) feed it. */ -export function MatchBoard({ title, opponent, view, legal, onAct, problem, error, onTopicBonus }: { - title: string; opponent: string; view: MatchView; legal: UIAction[]; onAct: (a: UIAction) => void; +export function MatchBoard({ title, opponent, view, legal, onAct, problem, error, onTopicBonus, onResults }: { + onResults?: () => void; title: string; opponent: string; view: MatchView; legal: UIAction[]; onAct: (a: UIAction) => void; problem?: (a: UIAction) => string | null; error?: string; onTopicBonus: number[]; }) { const [selected, setSelected] = useState(); @@ -45,12 +45,13 @@ export function MatchBoard({ title, opponent, view, legal, onAct, problem, error else setSheet({ kind: 'lane', lane }); }; const ending = view.waitingForOpponent; + const queuedCount = view.lanes.reduce((n, l) => n + l.staged.length, 0); const lastEvent = view.log.at(-1); return
Turn {view.turn}/{view.maxTurns} - {opponent} · {view.oppHandCount}{view.oppQueued ? ` · ${view.oppQueued} queued` : ''} + {opponent} · {view.oppHandCount}
{banner &&
{banner}
} @@ -67,11 +68,11 @@ export function MatchBoard({ title, opponent, view, legal, onAct, problem, error
{lane.mine.map(c => setSheet({ kind: 'card', card: c, side: 'mine' })} />)} @@ -84,7 +85,8 @@ export function MatchBoard({ title, opponent, view, legal, onAct, problem, error

- {error ? {error} + {view.over ? <>Final board. Topic totals include at-scoring Portals (+N). + : error ? {error} : ending ? <> Opponent is choosing… : sel ? <> {sel.title}{sel.keyword ? ` · ${sel.keyword.name}: ${sel.keyword.text}` : ''} Tap a lane. : lastEvent} @@ -100,9 +102,11 @@ export function MatchBoard({ title, opponent, view, legal, onAct, problem, error {view.energy} {view.deckCount} - + {view.over ? + : }

diff --git a/src/game/MatchScreen.tsx b/src/game/MatchScreen.tsx index 171e624..27ce1e3 100644 --- a/src/game/MatchScreen.tsx +++ b/src/game/MatchScreen.tsx @@ -23,7 +23,6 @@ export function MatchScreen({ mode, deck, opponentDeck, bot, seed, onFinish }: { const view = useMemo(() => engine.view(state, 0), [state]); const legal = useMemo(() => engine.legal(state, 0), [state]); - useEffect(() => { if (engine.isOver(state)) { const t = setTimeout(() => onFinish(engine.result(state, 0)), 900); return () => clearTimeout(t); } }, [state, onFinish]); // The bot moves once the player has committed (it never sees the player's queued plays). useEffect(() => { @@ -47,5 +46,5 @@ export function MatchScreen({ mode, deck, opponentDeck, bot, seed, onFinish }: { catch (e) { setError(e instanceof Error ? e.message : 'That move isn’t allowed.'); } }; return engine.problem(state, 0, a)} onTopicBonus={mode.ruleset.onTopicBonus} />; + problem={a => engine.problem(state, 0, a)} onResults={engine.isOver(state) ? () => onFinish(engine.result(state, 0)) : undefined} onTopicBonus={mode.ruleset.onTopicBonus} />; } diff --git a/src/game/OnlinePlay.tsx b/src/game/OnlinePlay.tsx index 4e5d3a7..3236e58 100644 --- a/src/game/OnlinePlay.tsx +++ b/src/game/OnlinePlay.tsx @@ -23,7 +23,6 @@ export function OnlinePlay({ mode, playerName, onExit, onFinish }: { const [error, setError] = useState(''); const [busy, setBusy] = useState(false); const inFlight = useRef(false); - const finished = useRef(false); const done = status?.phase === 'finished' || status?.phase === 'expired'; const refreshLobbies = useCallback(() => { @@ -50,17 +49,7 @@ export function OnlinePlay({ mode, playerName, onExit, onFinish }: { return () => clearInterval(t); }, [seat, poll, done]); - // Once finished, stop polling and show results after a beat. The timer must survive later - // re-renders, so it is only cleared on unmount. - const finishTimer = useRef>(undefined); - useEffect(() => { - const st = status?.state; - if (finished.current || !status || !seat || status.phase !== 'finished' || !st?.result) return; - finished.current = true; - const names = st.lanes.map(l => l.topic.name); - finishTimer.current = setTimeout(() => onFinish(resultView(st.result!, seat.seat, names, st.lanes.map(l => l.leader))), 900); - }, [status, seat, onFinish]); - useEffect(() => () => clearTimeout(finishTimer.current), []); + // Once finished, stop polling; the final board stays up until the player opens the results. const enter = async (fn: () => Promise) => { setBusy(true); setError(''); @@ -106,7 +95,8 @@ export function OnlinePlay({ mode, playerName, onExit, onFinish }: { return void send(() => online.act(seat, engineAction(a, seat.seat))); }; return ; + error={error} onTopicBonus={status.state.ruleset.onTopicBonus} + onResults={status.state.result ? () => onFinish(resultView(status.state!.result!, seat.seat, status.state!.lanes.map(l => l.topic.name), status.state!.lanes.map(l => l.leader))) : undefined} />; } // ----- draft ----- diff --git a/src/game/adapter.ts b/src/game/adapter.ts index 7b3ea6f..17e2d14 100644 --- a/src/game/adapter.ts +++ b/src/game/adapter.ts @@ -88,6 +88,9 @@ function capacityFromView(v: PlayerView, i: number): number { export function viewFromPlayerView(v: PlayerView, opts: { log?: string[]; capacity?: (lane: number) => number } = {}): MatchView { const rules = v.ruleset; const me = v.you; + const opp = me === 0 ? 1 : 0; + // After the last turn, show scoring power (incl. "at scoring" Portals) from the result, from my side. + const final = v.result ? v.result.lanePower.map(p => [p[me], p[opp]] as [number, number]) : undefined; const onBoard = (c: CardInPlay, power: number, stat: string, allOnTopic: boolean) => toUICard(c.card, rules, { id: `${c.owner}:${c.card.cardId}`, power, onTopic: allOnTopic || c.card.home === stat }); // both seats may share loaner cardIds const lanes: LaneView[] = v.lanes.map((lane, i) => { @@ -101,9 +104,13 @@ export function viewFromPlayerView(v: PlayerView, opts: { log?: string[]; capaci theirs: lane.cards[1].map((c, k) => onBoard(c, lane.cardPower[1][k], lane.topic.stat, allOn)), staged: v.queue.filter(q => q.lane === i).flatMap(q => { const c = v.hand.find(h => h.cardId === q.cardId); - return c ? [toUICard(c, rules)] : []; + if (!c) return []; + const onTopic = allOn || c.home === lane.topic.stat; + const power = Math.max(0, c.power + c.trend + (onTopic ? rules.onTopicBonus[c.cost] ?? 0 : 0)); + return [toUICard(c, rules, { power, onTopic })]; }), - myPower: lane.power[0], theirPower: lane.power[1], leader: lane.leader, + myPower: final ? final[i][0] : lane.power[0], theirPower: final ? final[i][1] : lane.power[1], leader: lane.leader, + scoringBonus: final ? [final[i][0] - lane.power[0], final[i][1] - lane.power[1]] as [number, number] : undefined, capacity: opts.capacity ? opts.capacity(i) : capacityFromView(v, i), }; }); @@ -112,7 +119,7 @@ export function viewFromPlayerView(v: PlayerView, opts: { log?: string[]; capaci me, turn: v.turn, maxTurns: rules.turns, energy: v.energyLeft, maxEnergy: v.energy, saved: Math.max(0, v.energy - (rules.energyByTurn[v.turn - 1] ?? 0) - rules.bonusEnergy), hand: v.hand.filter(c => !queued.has(c.cardId)).map(c => toUICard(c, rules)), deckCount: v.deckCount, - oppHandCount: v.opponent.handCount, oppDeckCount: v.opponent.deckCount, oppQueued: v.opponent.queuedCount, + oppHandCount: v.opponent.handCount, oppDeckCount: v.opponent.deckCount, lanes, log: opts.log ?? [], waitingForOpponent: v.committed && v.phase !== 'over', over: v.phase === 'over', }; } diff --git a/src/game/play.css b/src/game/play.css index 550e311..69a7c9c 100644 --- a/src/game/play.css +++ b/src/game/play.css @@ -205,3 +205,4 @@ html.wd-in-match .auth-wrap,body:has(.match) .auth-wrap{display:none} @media(max-width:480px){.hide-narrow{display:none}.play-actions{flex-wrap:nowrap}.play-actions .button{padding-inline:12px}} .show-narrow{display:none} @media(max-width:480px){.show-narrow{display:inline}.play-actions .button{min-width:0}} +.lane-bonus{color:var(--ctp-yellow)!important;margin-left:2px} diff --git a/src/game/types.ts b/src/game/types.ts index 1b45ad2..d3ddad2 100644 --- a/src/game/types.ts +++ b/src/game/types.ts @@ -39,6 +39,7 @@ export type LaneView = { theirPower: number; leader: 'you' | 'opponent' | null; capacity: number; + scoringBonus?: [number, number]; // at-scoring Portal adjustments (mine, theirs), match over only }; export type MatchView = { @@ -52,7 +53,6 @@ export type MatchView = { deckCount: number; oppHandCount: number; oppDeckCount: number; - oppQueued: number; lanes: LaneView[]; log: string[]; // newest last, this seat's events only waitingForOpponent: boolean; diff --git a/tests/ui-play.test.ts b/tests/ui-play.test.ts index 1519fbf..2348b53 100644 --- a/tests/ui-play.test.ts +++ b/tests/ui-play.test.ts @@ -61,7 +61,6 @@ test('my view never shows the opponent’s queued cards', () => { s = engine.apply(s, 1, play!); const mine = engine.view(s, 0); assert.equal(mine.lanes.flatMap(l => [...l.theirs, ...l.staged]).length, 0); - assert.equal(mine.oppQueued, 1); const theirs = engine.view(s, 1); assert.equal(theirs.lanes.flatMap(l => l.staged).length, 1); assert.ok(!theirs.hand.some(c => play!.type === 'play' && c.id === play!.cardId), 'a queued card leaves the visible hand'); @@ -126,3 +125,19 @@ test('leaderboard parsers cap and sanitise host data', async () => { assert.deepEqual(parseLeaderboard({ entries: [{ name: '', wins: 2 }] }), [{ name: 'Anonymous', wins: 2, losses: 0, draws: 0, played: 0 }]); assert.deepEqual(parseLeaderboard(42), []); }); + +test('the final board shows scoring power, and queued cards preview their lane power', () => { + const s = playOut('final-board'); + const v = engine.view(s, 0), r = engine.result(s, 0); + assert.ok(v.over); + v.lanes.forEach((l, i) => { assert.equal(l.myPower, r.lanes[i].myPower); assert.equal(l.theirPower, r.lanes[i].theirPower); }); + let m = engine.createMatch(DEFAULT_RULESET, [starterDeck(), opponentDeck('q')], 'queued-power'); + const play = engine.legal(m, 0).find(a => a.type === 'play'); + if (play?.type === 'play') { + m = engine.apply(m, 0, play); + const lane = engine.view(m, 0).lanes[play.lane]; + const [q] = lane.staged; + const bonus = q.home === lane.stat ? DEFAULT_RULESET.onTopicBonus[q.cost] : 0; + assert.equal(q.power, q.basePower + q.trend + bonus); + } +});