야단법석 달리기 화면을 부루마불처럼: 네모난 고리 판(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:
EJClaw
2026-10-13 22:03:28 +09:00
parent d35b7207a3
commit b1b6cccad4
7 changed files with 1095 additions and 288 deletions

View File

@@ -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 });

View File

@@ -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();

View File

@@ -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 {