야단법석 달리기 화면을 부루마불처럼: 네모난 고리 판(PC 9×8, 휴대폰 7×10, 출발 모서리가 결승), 가운데 입체 주사위·시상대·할 일 버튼, 말이 한 칸씩 걷기·화살표 미끄러짐·순간이동 날기, 능력·별·돌·결승 효과와 소리
엔진: 경주 기록 줄에 화면용 mv(이동 출발·도착 칸)와 die(굴린 눈) 추가, mv만 따라가도 말 자리가 맞는지 무작위 대국 테스트. 화면: replay.ts(기록 → 주사위·걷기·효과 순서) + 테스트, 문서 §9·§10. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
44
apps/web/src/games/magical-athlete/replay.test.ts
Normal file
44
apps/web/src/games/magical-athlete/replay.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import type { LogLine } from '@bg/games/magical-athlete';
|
||||
import { itemsOf, pathOf } from './replay';
|
||||
|
||||
describe('야단법석 달리기 판 다시 그리기', () => {
|
||||
test('걷는 길: 앞으로·뒤로 한 칸씩, 순간이동은 두 끝만', () => {
|
||||
expect(pathOf(3, 7, false)).toEqual([3, 4, 5, 6, 7]);
|
||||
expect(pathOf(12, 9, false)).toEqual([12, 11, 10, 9]);
|
||||
expect(pathOf(4, 20, true)).toEqual([4, 20]);
|
||||
});
|
||||
|
||||
test('주사위 → 걷기 → 화살표 칸(미끄러짐) → 도착 순서로 보여요', () => {
|
||||
const lines: LogLine[] = [
|
||||
{ n: 1, kind: 'turn', text: '토끼 차례예요.', racer: 'hare' },
|
||||
{ n: 2, kind: 'roll', text: '토끼가 주사위를 굴려 3이(가) 나왔어요.', racer: 'hare', die: 3 },
|
||||
{ n: 3, kind: 'move', text: '토끼가 5칸 가서 5칸에 왔어요.', racer: 'hare', mv: [{ racer: 'hare', from: 0, to: 5 }] },
|
||||
{ n: 4, kind: 'space', text: '토끼가 앞 화살표 칸에 멈춰 3칸 앞으로 가요.', racer: 'hare' },
|
||||
{ n: 5, kind: 'move', text: '토끼가 3칸 가서 8칸에 왔어요.', racer: 'hare', mv: [{ racer: 'hare', from: 5, to: 8 }] },
|
||||
{ n: 6, kind: 'power', text: '마술사가 주사위를 다시 굴려 6이(가) 나왔어요.', racer: 'magician', die: 6 },
|
||||
{
|
||||
n: 7,
|
||||
kind: 'move',
|
||||
text: '자리바꿈이가 토끼와 자리를 바꿨어요.',
|
||||
racer: 'flipflop',
|
||||
mv: [
|
||||
{ racer: 'flipflop', from: 2, to: 8, jump: true },
|
||||
{ racer: 'hare', from: 8, to: 2, jump: true },
|
||||
],
|
||||
},
|
||||
{ n: 8, kind: 'finish', text: '롱다리가 1등으로 결승선을 넘었어요!', racer: 'legs' },
|
||||
];
|
||||
const items = itemsOf(lines, ['legs']);
|
||||
expect(items.map((i) => i.t)).toEqual(['line', 'roll', 'walk', 'line', 'walk', 'roll', 'line', 'walk', 'walk', 'line']);
|
||||
const walks = items.filter((i) => i.t === 'walk');
|
||||
expect(walks.map((w) => [w.racer, w.path, w.slide, w.jump])).toEqual([
|
||||
['hare', [0, 1, 2, 3, 4, 5], false, false],
|
||||
['hare', [5, 6, 7, 8], true, false],
|
||||
['flipflop', [2, 8], false, true],
|
||||
['hare', [8, 2], false, true],
|
||||
]);
|
||||
expect(items.find((i) => i.t === 'roll' && i.value === 6)).toBeDefined();
|
||||
expect(items.at(-1)).toMatchObject({ t: 'line', place: 1 });
|
||||
});
|
||||
});
|
||||
41
apps/web/src/games/magical-athlete/replay.ts
Normal file
41
apps/web/src/games/magical-athlete/replay.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 야단법석 달리기 board replay: new log lines → what the board shows, in order (die, token walks, effects). The view
|
||||
* already has the result; the drawing follows it a beat behind so every roll, step and power can be seen.
|
||||
*/
|
||||
import type { LogLine, MaRacerView } from '@bg/games/magical-athlete';
|
||||
import type { RacerId } from '@bg/games/magical-athlete/racers';
|
||||
|
||||
export type Item =
|
||||
| { t: 'roll'; line: LogLine; value: number }
|
||||
| { t: 'walk'; line: LogLine; racer: RacerId; path: number[]; jump: boolean; slide: boolean }
|
||||
| { t: 'line'; line: LogLine; place?: number }
|
||||
/** The update is fully drawn: statuses, spaces and podium as the view has them. */
|
||||
| { t: 'end'; racers: MaRacerView[]; finishers: RacerId[]; cur: RacerId | null; last: number };
|
||||
|
||||
/** Spaces of a straight walk, both ends included (a jump: just both ends). */
|
||||
export function pathOf(from: number, to: number, jump: boolean): number[] {
|
||||
if (jump) return [from, to];
|
||||
const out = [from];
|
||||
for (let p = from; p !== to; ) out.push((p += to > from ? 1 : -1));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log lines → board items. A die face shows first; a move line walks each racer it moved (a space line followed by
|
||||
* a move of the same racer is an arrow, so that walk slides); the other lines show as effects. `finishers` gives
|
||||
* the place of a `finish` line.
|
||||
*/
|
||||
export function itemsOf(lines: LogLine[], finishers: RacerId[]): Item[] {
|
||||
const out: Item[] = [];
|
||||
let arrow: RacerId | null = null;
|
||||
for (const l of lines) {
|
||||
if (l.die) out.push({ t: 'roll', line: l, value: l.die });
|
||||
if (l.mv?.length) {
|
||||
for (const m of l.mv) out.push({ t: 'walk', line: l, racer: m.racer, path: pathOf(m.from, m.to, !!m.jump), jump: !!m.jump, slide: arrow === m.racer });
|
||||
} else if (l.kind !== 'roll') {
|
||||
out.push({ t: 'line', line: l, ...(l.kind === 'finish' && l.racer ? { place: finishers.indexOf(l.racer) + 1 } : {}) });
|
||||
}
|
||||
arrow = l.kind === 'space' ? (l.racer ?? null) : null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -186,11 +186,20 @@ interface MagicalAthleteState {
|
||||
- 네 번째 경주가 끝나면 종료. `ranking`(같은 총점은 같은 묶음, 나간 사람은 맨 뒤), `scores`(총점), `scoreText`("N점"), `summary`(§6).
|
||||
|
||||
## 9. UI/UX
|
||||
- PC: 위에 경주 번호·판 종류·점수표, 가운데 경주로(뱀 모양 11칸 줄, 휴대폰은 8칸 줄), 아래에 내 차례 할 일·방금 일어난 일·경주 기록·
|
||||
이번 경주 선수 카드. 오른쪽 패널에 사람별 점수(금·은·별)와 선수 칩(달린 선수는 줄 그음).
|
||||
- 경주로는 부루마불처럼 네모난 고리 판이다. 오른쪽 아래 모서리가 출발이고 시계 방향으로 30칸을 한 바퀴 돌면 그 모서리가 결승선이다
|
||||
(PC 가로 9칸 × 세로 8칸, 휴대폰은 세로로 긴 7 × 10칸). 변마다 안쪽에 색 띠, 거친 판 칸은 색(별 노랑·돌 회색·앞 화살표 초록·
|
||||
뒤 화살표 빨강)과 표시(⭐·🪨·+3·−3)로 구분하고 판 아래에 뜻을 적는다.
|
||||
- 판 가운데: 경주 번호·판 종류·메달 점수, 입체 주사위와 지금 움직이는 선수, 도착한 선수 시상대(1·2등), 내 차례 할 일 버튼,
|
||||
방금 일어난 일 두 줄. 판 아래에 경주 기록과 이번 경주 선수 카드, 오른쪽 패널에 사람별 점수(금·은·별)와 선수 칩(달린 선수는 줄 그음).
|
||||
- 뽑기: 카드(그림·이름·능력 한 줄)를 눌러 바로 뽑음. 고르기: 카드를 눌러 고른 뒤 "… 내보내기".
|
||||
- 경주: 주사위 버튼, 능력 버튼("⚗️ 3 대신 4칸 가기" / "3(으)로 가기")처럼 결과가 보이는 문구. 말은 칸 사이를 미끄러지듯 움직이고
|
||||
(움직임 줄이기 설정이면 바로), 넘어진 선수는 눕혀서 흐리게.
|
||||
- 경주: 주사위 버튼, 능력 버튼("⚗️ 3 대신 4칸 가기" / "3(으)로 가기")처럼 결과가 보이는 문구.
|
||||
- 움직임(누가 했든 같은 연출, `replay.ts`): 화면은 결과를 바로 받지만 판은 경주 기록 순서대로 한 박자 늦게 다시 그린다.
|
||||
주사위가 공중에서 굴러 떨어져 눈이 나오고 → 말이 한 칸씩 폴짝 걸어가며(지나간 칸 반짝, 발소리) → 화살표 칸이면 미끄러지고,
|
||||
최면술사·끼어들기·자리바꿈이·시시포스는 날아서 옮겨 간다. 능력은 말 위에 "✨ 이름", 별은 "⭐ +1점", 돌은 "🪨 꽈당!"(말이 눕고 흔들림),
|
||||
결승은 큰 글자 "🥇 … 1등!"과 색종이, 경주 시작은 "🏁 N번째 경주 출발!". 지금 움직이는 말에는 깜빡이는 고리.
|
||||
밀린 업데이트가 있으면 빨리 감고, 너무 밀리면(4개 이상) 지금 모습으로 바로 맞춘다. 새로 열거나 다시 접속한 화면은 다시 그리지 않고
|
||||
지금 모습만 보이며, 움직임 줄이기 설정이면 연출 없이 바로 바뀐다(소리는 한 번).
|
||||
- 이를 위해 경주 기록 줄에 화면용 정보가 붙는다: 이동 줄 `mv`(선수·출발 칸·도착 칸, 순간이동이면 `jump`), 굴림 줄(마술사 다시 굴림 포함) `die`.
|
||||
- 접근성: 경주로 SVG에 전체 상황 aria-label, 기록은 `aria-live`, 모든 조작은 버튼(키보드 Tab·Enter). 다크 모드 색 변수 사용.
|
||||
- 도움말: [?] 지금 할 수 있는 것(`help.ts`), 30초 요약 카드 3장(`quick.tsx`), 규칙 보기에 선수 24명 표.
|
||||
|
||||
@@ -206,6 +215,7 @@ interface MagicalAthleteState {
|
||||
- [x] 뱀 순서 뽑기(2명 8명씩, 4명 4명씩), 몰래 고르기(남에게는 골랐는지만), 시간 초과 기본값, 나간 사람 자동 진행, 점수표 두 가지.
|
||||
- [x] 엔진 공통 무작위 대국(유출 검사 포함), 빠른 무작위 대국(보존 규칙·경주 4번·차례 상한), 결정성, 시간 초과만으로 끝남, 상한 종료.
|
||||
- [x] 컴퓨터: 뽑기·출전·롱다리·마술사·연금술사·로켓 박사·최면술사·자리바꿈이 판단, 무작위보다 자주 이김, 2~6명 끝까지.
|
||||
- [x] 화면 다시 그리기: 무작위 대국에서 이동 줄(`mv`)만 따라가도 말 자리가 실제와 같음·굴림 줄에 눈(`die`), `replay.test.ts`(걷는 길·화살표 미끄러짐·순간이동·도착 순서).
|
||||
- [x] 방 통합(`apps/server/src/rooms/magical-athlete.room.test.ts`): 컴퓨터와 연습 한 판을 사람이 자기 화면만 보고 끝까지, 몰래 고른 선수 비공개.
|
||||
- [x] E2E(`e2e/games.e2e.ts`): PC 방장 + 휴대폰, 실제 뽑기(키보드 포함)·고르기·굴리기·능력 선택으로 네 경주 끝까지, 거친 판·능력 기록 확인.
|
||||
|
||||
|
||||
@@ -593,6 +593,44 @@ describe('무작위 대국', () => {
|
||||
expect(capped).toBeLessThanOrEqual(Math.ceil(FAST / 50));
|
||||
}, 120_000);
|
||||
|
||||
test('이동 줄(mv)만 따라가도 화면의 말 자리가 실제 자리와 같아요(굴린 줄에는 눈)', () => {
|
||||
let moves = 0;
|
||||
let jumps = 0;
|
||||
for (let i = 1; i <= 30; i++) {
|
||||
const n = 2 + (i % 5);
|
||||
const rng = SeededRng.fromSeed(seedN(700 + i));
|
||||
const chooser = SeededRng.fromSeed(seedN(800 + i));
|
||||
let s = def.setup({ players: Array.from({ length: n }, (_, k) => `p${k}`), options: optionsFor(i), rng, now: 0 });
|
||||
let steps = 0;
|
||||
while (!def.result(s)) {
|
||||
if (++steps > 4000) throw new Error(`seed ${i}: game did not finish`);
|
||||
const before = s.race;
|
||||
const shown = new Map(before?.racers.map((x) => [x.id, x.pos]));
|
||||
const lastN = before?.log.at(-1)?.n ?? 0;
|
||||
const p = def.activePlayers(s)[chooser.int(def.activePlayers(s).length)]!;
|
||||
const legal = def.legalActions!(s, p);
|
||||
s = def.apply(s, p, legal[chooser.int(legal.length)]!, { rng, now: steps }).state;
|
||||
const r = s.race;
|
||||
if (!r) continue;
|
||||
const fresh = r.no === before?.no ? r.log.filter((l) => l.n > lastN) : r.log;
|
||||
if (r.no !== before?.no) shown.clear();
|
||||
for (const l of fresh) {
|
||||
if (l.kind === 'roll') expect([1, 2, 3, 4, 5, 6]).toContain(l.die!);
|
||||
for (const m of l.mv ?? []) {
|
||||
expect(m.from).toBe(shown.get(m.racer) ?? 0);
|
||||
expect(m.from === m.to && !m.jump).toBe(false);
|
||||
shown.set(m.racer, m.to);
|
||||
moves++;
|
||||
if (m.jump) jumps++;
|
||||
}
|
||||
}
|
||||
for (const x of r.racers) expect(shown.get(x.id) ?? 0).toBe(x.pos);
|
||||
}
|
||||
}
|
||||
expect(moves).toBeGreaterThan(500);
|
||||
expect(jumps).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('같은 시드면 같은 결과(결정성)', () => {
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
const a = randomPlayout(def, { players: ['a', 'b', 'c'], seed: seedN(100 + i), maxApplyMs: 30 });
|
||||
|
||||
@@ -104,27 +104,29 @@ export class Runner {
|
||||
|
||||
// ------------------------------------------------------------ log & powers
|
||||
|
||||
log(kind: LogLine['kind'], text: string, racer?: RacerId): void {
|
||||
log(kind: LogLine['kind'], text: string, racer?: RacerId, more?: Pick<LogLine, 'mv' | 'die'>): void {
|
||||
const r = this.r;
|
||||
r.logSeq++;
|
||||
r.log.push({ n: r.logSeq, kind, text, ...(racer ? { racer } : {}) });
|
||||
const extra = { ...(racer ? { racer } : {}), ...more };
|
||||
r.log.push({ n: r.logSeq, kind, text, ...extra });
|
||||
if (r.log.length > LOG_KEEP) r.log.splice(0, r.log.length - LOG_KEEP);
|
||||
this.ev.push({ type: 'log', n: r.logSeq, kind, text, ...(racer ? { racer } : {}) });
|
||||
this.ev.push({ type: 'log', n: r.logSeq, kind, text, ...extra });
|
||||
}
|
||||
|
||||
/**
|
||||
* A racer's power happens: logged, and 꼼지락이 reacts. Returns false once the racer's power hit POWER_CAP this
|
||||
* racer-turn (the caller then skips an optional effect; rule powers pass `force` and still apply silently).
|
||||
*/
|
||||
fire(id: RacerId, text: string, force = false): boolean {
|
||||
fire(id: RacerId, text: string, force = false, die?: number): boolean {
|
||||
const r = this.r;
|
||||
const n = r.fired[id] ?? 0;
|
||||
const more = die ? { die } : undefined;
|
||||
if (n >= POWER_CAP) {
|
||||
if (force) this.log('power', text, id);
|
||||
if (force) this.log('power', text, id, more);
|
||||
return false;
|
||||
}
|
||||
r.fired[id] = n + 1;
|
||||
this.log('power', text, id);
|
||||
this.log('power', text, id, more);
|
||||
const sc = this.has('scoocher');
|
||||
if (sc && id !== 'scoocher') {
|
||||
this.enqueue([
|
||||
@@ -206,7 +208,7 @@ export class Runner {
|
||||
.filter((y) => y !== x && y.pos > from && y.pos < target)
|
||||
.sort((a, b) => a.pos - b.pos);
|
||||
x.pos = Math.min(target, FINISH);
|
||||
this.log('move', `${ga(x.id)} ${target - from}칸 가서 ${x.pos >= FINISH ? '결승선' : `${x.pos}칸`}에 왔어요.`, x.id);
|
||||
this.log('move', `${ga(x.id)} ${target - from}칸 가서 ${x.pos >= FINISH ? '결승선' : `${x.pos}칸`}에 왔어요.`, x.id, { mv: [{ racer: x.id, from, to: x.pos }] });
|
||||
if (target >= FINISH) this.finish(x);
|
||||
const tasks: Task[] = [];
|
||||
if (x.status === 'run') this.stopTasks(x, tasks);
|
||||
@@ -236,7 +238,7 @@ export class Runner {
|
||||
target = this.babyAdjust(x, target, 0);
|
||||
if (target === from) return;
|
||||
x.pos = target;
|
||||
this.log('move', `${ga(x.id)} ${from - target}칸 뒤로 가서 ${target === 0 ? '출발점' : `${target}칸`}에 왔어요.`, x.id);
|
||||
this.log('move', `${ga(x.id)} ${from - target}칸 뒤로 가서 ${target === 0 ? '출발점' : `${target}칸`}에 왔어요.`, x.id, { mv: [{ racer: x.id, from, to: target }] });
|
||||
const tasks: Task[] = [];
|
||||
this.stopTasks(x, tasks);
|
||||
this.enqueue(tasks);
|
||||
@@ -246,8 +248,9 @@ export class Runner {
|
||||
warp(x: RacerState, to: number, text: string): void {
|
||||
if (x.status !== 'run') return;
|
||||
const target = this.babyAdjust(x, to, 0);
|
||||
const from = x.pos;
|
||||
x.pos = target;
|
||||
this.log('move', `${text} (${target === 0 ? '출발점' : `${target}칸`})`, x.id);
|
||||
this.log('move', `${text} (${target === 0 ? '출발점' : `${target}칸`})`, x.id, { mv: [{ racer: x.id, from, to: target, jump: true }] });
|
||||
const tasks: Task[] = [];
|
||||
this.stopTasks(x, tasks);
|
||||
this.enqueue(tasks);
|
||||
@@ -258,7 +261,12 @@ export class Runner {
|
||||
const pa = a.pos;
|
||||
a.pos = b.pos;
|
||||
b.pos = pa;
|
||||
this.log('move', `${ga(a.id)} ${nm(b.id)}와 자리를 바꿨어요. (${a.pos}칸 ↔ ${b.pos}칸)`, a.id);
|
||||
this.log('move', `${ga(a.id)} ${nm(b.id)}와 자리를 바꿨어요. (${a.pos}칸 ↔ ${b.pos}칸)`, a.id, {
|
||||
mv: [
|
||||
{ racer: a.id, from: pa, to: a.pos, jump: true },
|
||||
{ racer: b.id, from: a.pos, to: pa, jump: true },
|
||||
],
|
||||
});
|
||||
const tasks: Task[] = [];
|
||||
this.stopTasks(a, tasks);
|
||||
this.stopTasks(b, tasks);
|
||||
@@ -444,7 +452,7 @@ export class Runner {
|
||||
const value = 1 + this.rng.int(6);
|
||||
r.roll = { value, rerolls: 0 };
|
||||
this.s.rollSeq++;
|
||||
this.log('roll', `${ga(r.cur!)} 주사위를 굴려 ${value}이(가) 나왔어요.`, r.cur!);
|
||||
this.log('roll', `${ga(r.cur!)} 주사위를 굴려 ${value}이(가) 나왔어요.`, r.cur!, { die: value });
|
||||
this.ev.push({ type: 'rolled', racer: r.cur, value });
|
||||
if (r.cur === 'magician') {
|
||||
r.step = 'reroll';
|
||||
@@ -461,7 +469,7 @@ export class Runner {
|
||||
const value = 1 + this.rng.int(6);
|
||||
r.roll = { value, rerolls: r.roll.rerolls + 1 };
|
||||
this.s.rollSeq++;
|
||||
this.fire('magician', `마술사가 주사위를 다시 굴려 ${value}이(가) 나왔어요.`);
|
||||
this.fire('magician', `마술사가 주사위를 다시 굴려 ${value}이(가) 나왔어요.`, false, value);
|
||||
this.ev.push({ type: 'rolled', racer: r.cur, value });
|
||||
this.drain();
|
||||
if (this.over()) return this.endRace();
|
||||
|
||||
@@ -118,11 +118,23 @@ export interface RacerState {
|
||||
|
||||
export type Step = 'go' | 'start' | 'roll' | 'reroll' | 'boost';
|
||||
|
||||
/** One racer's move for the screen: walked space by space (forward or back) or `jump`ed there (warp / swap). */
|
||||
export interface LogMove {
|
||||
racer: RacerId;
|
||||
from: number;
|
||||
to: number;
|
||||
jump?: true;
|
||||
}
|
||||
|
||||
export interface LogLine {
|
||||
n: number;
|
||||
kind: 'turn' | 'roll' | 'move' | 'power' | 'space' | 'finish' | 'info';
|
||||
text: string;
|
||||
racer?: RacerId;
|
||||
/** `move` lines: who went where, so the board can walk the token (the text alone stays the record). */
|
||||
mv?: LogMove[];
|
||||
/** The die face of a roll (`roll` line, or 마술사's reroll `power` line). */
|
||||
die?: number;
|
||||
}
|
||||
|
||||
export interface RaceState {
|
||||
|
||||
Reference in New Issue
Block a user