야단법석 달리기 화면을 부루마불처럼: 네모난 고리 판(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;
|
||||
}
|
||||
Reference in New Issue
Block a user