M9: 게임 26종 30초 요약 카드·[?] 지금 할 수 있는 것 내용
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
62
apps/web/src/games/yut/help.test.ts
Normal file
62
apps/web/src/games/yut/help.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
|
||||
import { GAMES } from '@bg/games';
|
||||
import { helpNow } from './help';
|
||||
|
||||
const users = usersOf(['A', 'B']);
|
||||
const view = (s: unknown, who: string | null) => GAMES.yut!.view(s, who) as any;
|
||||
|
||||
/** Scripted sticks: F = 배 up, R = 등 up (see packages/games/src/yut/yut.test.ts). */
|
||||
const F = 0;
|
||||
const R = 0.99;
|
||||
const STICKS = { do: [R, F, R, R], gae: [F, F, R, R], geol: [F, F, F, R], yut: [F, F, F, F], mo: [R, R, R, R] } as const;
|
||||
const sticks = (...ts: (keyof typeof STICKS)[]) => {
|
||||
const vals: number[] = ts.flatMap((t) => [...STICKS[t]]);
|
||||
return { next: () => vals.shift()!, int: (n: number) => Math.floor(vals.shift()! * n), shuffle: <T,>(a: readonly T[]) => [...a] } as any;
|
||||
};
|
||||
|
||||
function fresh() {
|
||||
const { state } = setupGame('yut', 2);
|
||||
state.turnSide = 0;
|
||||
state.current = state.sides[0].members[0];
|
||||
const me: string = state.current;
|
||||
return { state, me, other: me === 'A' ? 'B' : 'A' };
|
||||
}
|
||||
|
||||
test('윷: 던지기 차례 / 상대 차례 / 관전', () => {
|
||||
const { state, me, other } = fresh();
|
||||
const t = helpNow(view(state, me), me, users);
|
||||
expect(t).toContain('[🥢 윷 던지기]');
|
||||
expect(t).toContain('대기 4개');
|
||||
expect(helpNow(view(state, other), other, users)).toContain(`${users[me]!.nickname}님(빨강 말) 차례예요. 윷을 던지는 중이에요. 기다려 주세요.`);
|
||||
expect(helpNow(view(state, null), null, users)).toContain('자기 편 말을 모두');
|
||||
});
|
||||
|
||||
test('윷: 윷이 나오면 한 번 더, 그다음 결과를 골라 말 옮기기', () => {
|
||||
const { state, me, other } = fresh();
|
||||
let s = applyAction('yut', state, me, { type: 'THROW' }, sticks('yut'));
|
||||
expect(helpNow(view(s, me), me, users)).toContain('윷이나 모가 나와서 한 번 더');
|
||||
s = applyAction('yut', s, me, { type: 'THROW' }, sticks('geol'));
|
||||
const t = helpNow(view(s, me), me, users);
|
||||
expect(t).toContain('모아 둔 결과(윷, 걸)');
|
||||
expect(t).toContain('반짝이는 말');
|
||||
expect(helpNow(view(s, other), other, users)).toContain('말을 옮기는 중이에요. 모아 둔 결과: 윷, 걸.');
|
||||
});
|
||||
|
||||
test('윷: 잡을 수 있으면 알려 주고, 잡으면 한 번 더 던지기', () => {
|
||||
const { state, me } = fresh();
|
||||
const opp = state.sides[1].pieces[0];
|
||||
Object.assign(opp, { status: 'board', node: 2, trail: [1, 2], lapped: false });
|
||||
let s = applyAction('yut', state, me, { type: 'THROW' }, sticks('gae'));
|
||||
const t = helpNow(view(s, me), me, users);
|
||||
expect(t).toContain('상대 말을 잡을 수 있어요(잡으면 한 번 더 던져요)');
|
||||
expect(t).toContain('[자동 이동]');
|
||||
s = applyAction('yut', s, me, { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(helpNow(view(s, me), me, users)).toContain('상대 말을 잡아서 한 번 더 던져요');
|
||||
});
|
||||
|
||||
test('윷: 게임 끝', () => {
|
||||
const { state, me, other } = fresh();
|
||||
const s = applyAction('yut', state, other, { type: 'CONCEDE' });
|
||||
expect(helpNow(view(s, me), me, users)).toContain('게임이 끝났어요');
|
||||
});
|
||||
71
apps/web/src/games/yut/help.ts
Normal file
71
apps/web/src/games/yut/help.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/** 윷놀이 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
|
||||
import type { Throw, YutView } from '@bg/games/yut';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
|
||||
const THROW_KO: Record<Throw, string> = { do: '도', gae: '개', geol: '걸', yut: '윷', mo: '모', backdo: '빽도' };
|
||||
|
||||
const pendingText = (v: YutView) => v.pending.map((t) => THROW_KO[t]).join(', ');
|
||||
|
||||
/** Why the current player throws (again): fresh turn, 윷·모, or a capture bonus. */
|
||||
function throwReason(v: YutView): 'fresh' | 'yutmo' | 'capture' {
|
||||
for (let i = v.log.length - 1; i >= 0; i--) {
|
||||
const e = v.log[i]!;
|
||||
if (e.type === 'bonusThrow') return 'capture';
|
||||
if (e.type === 'thrown') return e.result === 'yut' || e.result === 'mo' ? 'yutmo' : 'fresh';
|
||||
if (e.type === 'turnChanged' || e.type === 'nak' || e.type === 'moved') return 'fresh';
|
||||
}
|
||||
return 'fresh';
|
||||
}
|
||||
|
||||
export function helpNow(v: YutView, me: string | null, players: Record<string, PublicUser>): string {
|
||||
const goal = '내 말을 모두 먼저 한 바퀴 돌려 판 밖으로 내보내면(날) 이겨요.';
|
||||
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
|
||||
const turnSide = v.sides[v.turnSide];
|
||||
const sideTag = turnSide ? `(${turnSide.name}${v.team ? '' : ' 말'})` : '';
|
||||
const who = `${players[v.current]?.nickname ?? '다른 사람'}님`;
|
||||
const doing = v.phase === 'throw' ? '윷을 던지는 중이에요.' : `말을 옮기는 중이에요. 모아 둔 결과: ${pendingText(v)}.`;
|
||||
const mySide = v.mySide !== null ? v.sides[v.mySide] : undefined;
|
||||
const progress = mySide ? `${v.team ? '우리 팀 말' : '내 말'}: 대기 ${mySide.home}개, 판 위 ${mySide.onBoard}개, 난 말 ${mySide.done}/${v.options.pieces}개.` : '';
|
||||
|
||||
if (!mySide || !me) return `${who}${sideTag} 차례예요. ${doing}\n${goal.replace('내 말을', '자기 편 말을')}`;
|
||||
if (mySide.conceded.includes(me)) return `나는 기권해서 지금은 구경만 할 수 있어요. ${who}${sideTag} 차례예요.`;
|
||||
|
||||
if (v.current !== me) {
|
||||
const ours = v.team && v.mySide === v.turnSide ? '(우리 팀)' : sideTag;
|
||||
return `${who}${ours} 차례예요. ${doing} 기다려 주세요.\n${progress}`;
|
||||
}
|
||||
|
||||
// My turn.
|
||||
if (v.phase === 'throw') {
|
||||
const reason = throwReason(v);
|
||||
const lines: string[] = [];
|
||||
if (reason === 'yutmo') lines.push('윷이나 모가 나와서 한 번 더 던져요! [🥢 한 번 더 던지기]를 눌러 주세요.');
|
||||
else if (reason === 'capture') lines.push('상대 말을 잡아서 한 번 더 던져요! [🥢 한 번 더 던지기]를 눌러 주세요.');
|
||||
else lines.push(`내 차례예요. [🥢 윷 던지기]를 눌러 윷을 던져요.`);
|
||||
if (v.pending.length) lines.push(`모아 둔 결과(${pendingText(v)})는 다 던진 뒤에 원하는 순서로 써요.`);
|
||||
else lines.push(`도 1칸, 개 2칸, 걸 3칸, 윷 4칸, 모 5칸 움직여요. 윷·모가 나오면 한 번 더 던져요.`);
|
||||
lines.push(progress);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
const moves = v.legalMoves ?? [];
|
||||
const lines = [`내 차례예요. 모아 둔 결과(${pendingText(v)})를 하나씩 써서 말을 움직여요.`];
|
||||
if (moves.length === 1) {
|
||||
lines.push('지금 움직일 수 있는 방법이 하나뿐이에요. 초록색 [자동 이동] 버튼을 누르면 바로 움직여요.');
|
||||
} else {
|
||||
lines.push('아래 결과를 먼저 누르고(한 가지뿐이면 이미 골라져 있어요), 반짝이는 말을 누르면 갈 자리가 보여요. 한 번 더 누르면 움직여요.');
|
||||
if (mySide.home > 0 && moves.some((m) => m.from === 'home')) lines.push(`새 말은 [대기 ${mySide.home}개] 버튼을 눌러 판에 올려요.`);
|
||||
}
|
||||
const usable = new Set(moves.map((m) => m.throw));
|
||||
if (v.pending.some((t) => !usable.has(t))) lines.push('지금 쓸 곳이 없는 결과는 눌리지 않아요. 다른 결과를 먼저 써 보세요.');
|
||||
const tips: string[] = [];
|
||||
if (moves.some((m) => m.captures > 0)) {
|
||||
const bonus = moves.some((m) => m.captures > 0 && (m.throw !== 'backdo' || v.options.backdoCaptureBonus));
|
||||
tips.push(`상대 말을 잡을 수 있어요${bonus ? '(잡으면 한 번 더 던져요)' : ''}`);
|
||||
}
|
||||
if (moves.some((m) => m.finishes)) tips.push('판 밖으로 낼(날) 수 있는 말이 있어요');
|
||||
if (moves.some((m) => m.stacks)) tips.push('내 말끼리 업어서 함께 움직일 수 있어요');
|
||||
if (tips.length) lines.push(`${tips.join('. ')}.`);
|
||||
lines.push(progress);
|
||||
return lines.join('\n');
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import { Avatar, ConfirmSheet } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
|
||||
type From = number | 'home';
|
||||
type GameEvent = YutView['log'][number];
|
||||
@@ -861,6 +863,8 @@ const ui: GameUI<YutView, YutOptions> = {
|
||||
Options,
|
||||
optionsSummary,
|
||||
Rules,
|
||||
quickStart,
|
||||
helpNow,
|
||||
};
|
||||
|
||||
export default ui;
|
||||
|
||||
128
apps/web/src/games/yut/quick.tsx
Normal file
128
apps/web/src/games/yut/quick.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
/** 윷놀이 30초 규칙 요약 (docs/07 §5). */
|
||||
import type { ReactNode } from 'react';
|
||||
import type { QuickCard } from '../types';
|
||||
|
||||
/** One 윷가락: 배(flat, light) or 등(round, dark with marks). */
|
||||
function Stick({ x, flat }: { x: number; flat: boolean }) {
|
||||
return (
|
||||
<g>
|
||||
<rect x={x} y={8} width={18} height={64} rx={9} fill={flat ? '#f6e4b8' : '#a86b2d'} stroke={flat ? '#9a7432' : '#5c3713'} strokeWidth={2} />
|
||||
{flat ? (
|
||||
<line x1={x + 9} y1={16} x2={x + 9} y2={64} stroke="#d9bd83" strokeWidth={1.5} />
|
||||
) : (
|
||||
[20, 32, 44, 56].map((y) => <line key={y} x1={x + 5} y1={y} x2={x + 13} y2={y} stroke="#f6e4b8" strokeWidth={2} strokeLinecap="round" opacity={0.7} />)
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function SticksPic() {
|
||||
const groups: [boolean[], string][] = [
|
||||
[[true, true, true, false], '걸 · 3칸'],
|
||||
[[true, true, true, true], '윷 · 4칸+1번'],
|
||||
];
|
||||
return (
|
||||
<svg viewBox="0 0 260 110" width={250} height={106} aria-hidden>
|
||||
{groups.map(([flats, label], g) => (
|
||||
<g key={g} transform={`translate(${g * 135} 0)`}>
|
||||
{flats.map((f, i) => (
|
||||
<Stick key={i} x={6 + i * 28} flat={f} />
|
||||
))}
|
||||
<text x={60} y={98} textAnchor="middle" fontSize={17} fontWeight={800} fill="#3b2a12">
|
||||
{label}
|
||||
</text>
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
// Board geometry like the game screen: 참먹이 bottom-right, pieces go anticlockwise.
|
||||
const LO = 8;
|
||||
const HI = 92;
|
||||
const GAP = (HI - LO) / 5;
|
||||
const POS: [number, number][] = (() => {
|
||||
const p: [number, number][] = [];
|
||||
p[0] = [HI, HI];
|
||||
for (let i = 1; i <= 4; i++) p[i] = [HI, HI - GAP * i];
|
||||
p[5] = [HI, LO];
|
||||
for (let i = 6; i <= 9; i++) p[i] = [HI - GAP * (i - 5), LO];
|
||||
p[10] = [LO, LO];
|
||||
for (let i = 11; i <= 14; i++) p[i] = [LO, LO + GAP * (i - 10)];
|
||||
p[15] = [LO, HI];
|
||||
for (let i = 16; i <= 19; i++) p[i] = [LO + GAP * (i - 15), HI];
|
||||
const lerp = (a: [number, number], b: [number, number], t: number): [number, number] => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
||||
[20, 21, 22, 23, 24].forEach((n, k) => (p[n] = lerp(p[5]!, p[15]!, (k + 1) / 6)));
|
||||
[25, 26].forEach((n, k) => (p[n] = lerp(p[10]!, p[0]!, (k + 1) / 6)));
|
||||
[27, 28].forEach((n, k) => (p[n] = lerp(p[10]!, p[0]!, (k + 4) / 6)));
|
||||
return p;
|
||||
})();
|
||||
const LINES: [number, number][] = [
|
||||
...Array.from({ length: 20 }, (_, i) => [i, (i + 1) % 20] as [number, number]),
|
||||
[5, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 15],
|
||||
[10, 25], [25, 26], [26, 22], [22, 27], [27, 28], [28, 0],
|
||||
];
|
||||
const BIG = new Set([0, 5, 10, 15, 22]);
|
||||
|
||||
function Board({ children, path }: { children?: ReactNode; path?: number[] }) {
|
||||
return (
|
||||
<svg viewBox="0 0 100 100" width={160} height={160} aria-hidden style={{ background: '#e9c98f', borderRadius: 12 }}>
|
||||
{LINES.map(([a, b]) => (
|
||||
<line key={`${a}-${b}`} x1={POS[a]![0]} y1={POS[a]![1]} x2={POS[b]![0]} y2={POS[b]![1]} stroke="#8a6232" strokeWidth={0.9} opacity={0.7} />
|
||||
))}
|
||||
{path && <polyline points={path.map((n) => POS[n]!.join(',')).join(' ')} fill="none" stroke="#2563eb" strokeWidth={2.4} strokeDasharray="3 2" />}
|
||||
{POS.map(([x, y], n) => (
|
||||
<circle key={n} cx={x} cy={y} r={BIG.has(n) ? 6 : 4.2} fill="#fffdf8" stroke="#8a6232" strokeWidth={0.7} />
|
||||
))}
|
||||
{children}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
const Red = ({ n, dx = 0, dy = 0 }: { n: number; dx?: number; dy?: number }) => (
|
||||
<circle cx={POS[n]![0] + dx} cy={POS[n]![1] + dy} r={4.6} fill="#dc2626" stroke="#fff" strokeWidth={0.8} />
|
||||
);
|
||||
const Blue = ({ n }: { n: number }) => {
|
||||
const [x, y] = POS[n]!;
|
||||
return <polygon points={`${x},${y - 5} ${x + 5},${y + 3.6} ${x - 5},${y + 3.6}`} fill="#2563eb" stroke="#fff" strokeWidth={0.8} />;
|
||||
};
|
||||
const Label = ({ n, text, dy = -9 }: { n: number; text: string; dy?: number }) => (
|
||||
<text x={POS[n]![0]} y={POS[n]![1] + dy} textAnchor="middle" fontSize={7} fontWeight={900} fill="#b91c1c" stroke="#fff" strokeWidth={0.6} paintOrder="stroke">
|
||||
{text}
|
||||
</text>
|
||||
);
|
||||
|
||||
export const quickStart: QuickCard[] = [
|
||||
{
|
||||
pic: <SticksPic />,
|
||||
alt: '윷가락 네 개: 세 개가 배면 걸 3칸, 네 개 모두 배면 윷 4칸과 한 번 더',
|
||||
title: '윷 던지고 말 옮겨요',
|
||||
text: '도 1칸, 개 2칸, 걸 3칸, 윷 4칸, 모 5칸. 윷·모가 나오면 한 번 더 던지고, 나온 결과로 말을 움직여요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<Board>
|
||||
<Blue n={3} />
|
||||
<Red n={3} dx={1.5} dy={-1.5} />
|
||||
<Label n={3} text="잡기!" />
|
||||
<Red n={8} dx={-1.2} dy={1.2} />
|
||||
<Red n={8} dx={1.2} dy={-1.2} />
|
||||
<Label n={8} text="업기" dy={10} />
|
||||
</Board>
|
||||
),
|
||||
alt: '빨간 말이 파란 말을 잡고, 다른 빨간 말 두 개는 업혀 있는 윷판',
|
||||
title: '잡기와 업기',
|
||||
text: '상대 말이 있는 자리에 멈추면 잡아서 처음으로 보내고 한 번 더 던져요. 내 말 자리에 멈추면 업혀서 같이 가요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<Board path={[5, 20, 21, 22, 27, 28, 0]}>
|
||||
<Red n={5} />
|
||||
<Label n={22} text="방" dy={-7} />
|
||||
</Board>
|
||||
),
|
||||
alt: '오른쪽 위 모서리에서 가운데 방을 지나 출발점으로 가는 지름길',
|
||||
title: '지름길로 빨리 나가요',
|
||||
text: '모서리나 가운데 방에 멈췄다가 출발하면 안쪽 지름길로 가요. 내 말을 모두 먼저 판 밖으로 내보내면 이겨요.',
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user