M9: 게임 26종 30초 요약 카드·[?] 지금 할 수 있는 것 내용
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
85
apps/web/src/games/rummikub/help.test.ts
Normal file
85
apps/web/src/games/rummikub/help.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
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', 'C']);
|
||||
const view = (s: unknown, who: string | null) => GAMES.rummikub!.view(s, who) as any;
|
||||
const nickOf = (id: string) => `${users[id]!.nickname}님`;
|
||||
|
||||
/** Fresh game; the current player gets a known rack (view-only edit, enough for help text). */
|
||||
function game(options: Record<string, unknown> = {}, rack?: string[]) {
|
||||
const { state, players } = setupGame('rummikub', 3, options);
|
||||
const cur: string = state.current;
|
||||
const other = players.find((p) => p !== cur)!;
|
||||
if (rack) state.racks[cur] = rack;
|
||||
return { state, cur, other };
|
||||
}
|
||||
|
||||
test('숫자 타일: 내 차례(첫 등록 전) / 상대 차례 / 관전', () => {
|
||||
const { state, cur, other } = game();
|
||||
const mine = helpNow(view(state, cur), cur, users);
|
||||
expect(mine).toContain('내 차례예요');
|
||||
expect(mine).toContain('30점 이상');
|
||||
expect(mine).toContain('(지금 0점)');
|
||||
expect(mine).toContain('[한 장 가져오기]');
|
||||
expect(mine).toContain('[도와줘]');
|
||||
const theirs = helpNow(view(state, other), other, users);
|
||||
expect(theirs).toContain(`${nickOf(cur)} 차례예요. 기다려 주세요.`);
|
||||
expect(theirs).toContain('나는 아직 첫 등록 전');
|
||||
expect(theirs).toContain('내 받침대 14장');
|
||||
const spec = helpNow(view(state, null), null, users);
|
||||
expect(spec).toContain(`${nickOf(cur)} 차례예요(받침대 14장)`);
|
||||
expect(spec).toContain('첫 등록 전');
|
||||
expect(spec).not.toContain('내 받침대');
|
||||
});
|
||||
|
||||
test('숫자 타일: 방 옵션 반영(첫 등록 없음, 힌트 끔)', () => {
|
||||
const { state, cur } = game({ initialMeldPoints: 0, hints: false });
|
||||
const t = helpNow(view(state, cur), cur, users);
|
||||
expect(t).not.toContain('첫 등록');
|
||||
expect(t).not.toContain('[도와줘]');
|
||||
expect(t).toContain('바닥 묶음을 쪼개고 합쳐');
|
||||
});
|
||||
|
||||
test('숫자 타일: 틀린 배치 / 올바른 배치 / 조커', () => {
|
||||
const rack = ['R10a', 'R11a', 'R12a', 'K1a', 'JK1'];
|
||||
const { state, cur } = game({}, rack);
|
||||
const bad = applyAction('rummikub', state, cur, { type: 'setDraft', sets: [{ tileIds: ['K1a'] }] });
|
||||
const tb = helpNow(view(bad, cur), cur, users);
|
||||
expect(tb).toContain('아직 확정할 수 없어요');
|
||||
expect(tb).toContain('[되돌리기]');
|
||||
expect(tb).toContain('3장을 가져와요');
|
||||
expect(tb).toContain('조커');
|
||||
const good = applyAction('rummikub', state, cur, { type: 'setDraft', sets: [{ tileIds: ['R10a', 'R11a', 'R12a'] }] });
|
||||
const tg = helpNow(view(good, cur), cur, users);
|
||||
expect(tg).toContain('(지금 33점)');
|
||||
expect(tg).toContain('[확정]을 눌러야');
|
||||
|
||||
const p3 = game({ invalidCommitPenalty: 'penalty3', invalidTimeoutPenalty: 1 }, rack);
|
||||
const bad3 = applyAction('rummikub', p3.state, p3.cur, { type: 'setDraft', sets: [{ tileIds: ['K1a'] }] });
|
||||
const t3 = helpNow(view(bad3, p3.cur), p3.cur, users);
|
||||
expect(t3).toContain('틀린 채로 [확정]하면');
|
||||
expect(t3).toContain('1장을 가져와요');
|
||||
});
|
||||
|
||||
test('숫자 타일: 판 끝(다음 판 시작) / 게임 끝', () => {
|
||||
const rack = ['R10a', 'R11a', 'R12a'];
|
||||
const m = game({ gamesPerMatch: '2' }, rack);
|
||||
let s = applyAction('rummikub', m.state, m.cur, { type: 'setDraft', sets: [{ tileIds: rack }] });
|
||||
s = applyAction('rummikub', s, m.cur, { type: 'commit' });
|
||||
expect(s.phase).toBe('roundEnd');
|
||||
const t = helpNow(view(s, m.other), m.other, users);
|
||||
expect(t).toContain(`${nickOf(m.cur)}이 타일을 모두 내려놓아`);
|
||||
expect(t).toContain('[다음 판 시작]');
|
||||
expect(t).toContain('이번 판 내 점수는 -');
|
||||
const s2 = applyAction('rummikub', s, m.other, { type: 'ready' });
|
||||
expect(helpNow(view(s2, m.other), m.other, users)).toContain('나는 준비했어요');
|
||||
expect(helpNow(view(s2, null), null, users)).toContain('기다리는 중');
|
||||
|
||||
const one = game({}, rack);
|
||||
let f = applyAction('rummikub', one.state, one.cur, { type: 'setDraft', sets: [{ tileIds: rack }] });
|
||||
f = applyAction('rummikub', f, one.cur, { type: 'commit' });
|
||||
expect(f.phase).toBe('finished');
|
||||
expect(helpNow(view(f, one.other), one.other, users)).toContain('게임이 끝났어요');
|
||||
});
|
||||
103
apps/web/src/games/rummikub/help.ts
Normal file
103
apps/web/src/games/rummikub/help.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/** 숫자 타일 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
|
||||
import type { RummikubView } from '@bg/games/rummikub';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
|
||||
const who = (players: Record<string, PublicUser>, id: string) => {
|
||||
const n = players[id]?.nickname;
|
||||
return n ? `${n}님` : '다른 사람';
|
||||
};
|
||||
|
||||
/** First meld rule for someone who has not melded yet (only when the room has a minimum). */
|
||||
function meldRule(v: RummikubView, now?: number): string {
|
||||
const pts = v.options.initialMeldPoints;
|
||||
const touch = v.options.initialMeldAllowExtend
|
||||
? `${pts}점을 채운 뒤에는 같은 차례에 바닥 묶음에도 붙일 수 있어요.`
|
||||
: '첫 등록하는 차례에는 바닥 묶음을 건드릴 수 없어요.';
|
||||
const cur = now === undefined ? '' : `(지금 ${now}점)`;
|
||||
return `첫 등록(처음 내려놓기)은 받침대 타일만으로 만든 새 묶음의 숫자 합이 ${pts}점 이상이어야 해요${cur}. 조커는 대신하는 숫자로 세요. ${touch}`;
|
||||
}
|
||||
|
||||
function roundHead(v: RummikubView, players: Record<string, PublicUser>): string {
|
||||
const r = v.round;
|
||||
const no = v.match.total > 1 ? `${r?.gameNo ?? v.match.gameNo}판(전체 ${v.match.total}판)이 끝났어요.` : '판이 끝났어요.';
|
||||
if (!r) return no;
|
||||
if (r.endReason === 'rackEmpty') return `${r.winners.map((w) => who(players, w)).join(', ')}이 타일을 모두 내려놓아 ${no}`;
|
||||
if (r.endReason === 'stalemate') return `더 낼 수 있는 사람이 없어 ${no} 남은 타일 점수가 가장 적은 사람이 이겨요.`;
|
||||
return no;
|
||||
}
|
||||
|
||||
export function helpNow(v: RummikubView, me: string | null, players: Record<string, PublicUser>): string {
|
||||
const seat = me ? v.seats.find((s) => s.id === me) : undefined;
|
||||
const my = seat ? v.my : null;
|
||||
|
||||
if (v.phase === 'finished') {
|
||||
const sum = v.result?.summary ?? '';
|
||||
return `게임이 끝났어요. ${sum}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
|
||||
}
|
||||
|
||||
if (v.phase === 'roundEnd') {
|
||||
const lines = [roundHead(v, players)];
|
||||
const mine = me && v.round ? v.round.scores[me] : undefined;
|
||||
if (seat && mine !== undefined) lines.push(`이번 판 내 점수는 ${mine > 0 ? '+' : ''}${mine}점이에요. 아래 표에서 각자 남은 타일을 볼 수 있어요.`);
|
||||
if (my?.needReady) lines.push('[다음 판 시작]을 눌러 주세요. 모두 누르거나 30초가 지나면 다음 판이 시작돼요.');
|
||||
else if (seat && !seat.left) lines.push('나는 준비했어요. 다른 사람이 [다음 판 시작]을 누르기를 기다리는 중이에요.');
|
||||
else lines.push('다음 판이 시작되기를 기다리는 중이에요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
// playing
|
||||
const cur = v.current;
|
||||
const curName = cur ? who(players, cur) : '다른 사람';
|
||||
const curSeat = cur ? v.seats.find((s) => s.id === cur) : undefined;
|
||||
const pool = v.poolCount > 0 ? `가져올 수 있는 남은 타일은 ${v.poolCount}장이에요.` : '남은 타일이 다 떨어져서 가져오기 대신 넘기기만 할 수 있어요.';
|
||||
|
||||
if (!seat || !my) {
|
||||
const lines = [`${curName} 차례예요${curSeat ? `(받침대 ${curSeat.tiles}장)` : ''}. ${pool}`];
|
||||
if (curSeat && !curSeat.melded) lines.push(`${curName}은 아직 첫 등록 전이라 받침대 타일만으로 ${v.options.initialMeldPoints}점 이상을 만들어 내야 해요.`);
|
||||
if (v.draft) lines.push(`바닥에는 ${curName}이 고민 중인 배치가 보여요. [확정] 전이라 바뀔 수 있어요.`);
|
||||
else if (v.draftEdits > 0) lines.push(`${curName}이 타일을 옮겨 보며 생각 중이에요.`);
|
||||
if (curSeat?.away) lines.push(`${curName}은 자리 비움 상태라 차례가 금방 넘어가요.`);
|
||||
lines.push('같은 숫자 다른 색 3~4장, 또는 같은 색 이어진 숫자 3장 이상으로 묶어 받침대를 먼저 비우면 이겨요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
if (seat.left) return `나는 방을 나가서 이 판에는 참여하지 않아요. 지금은 ${curName} 차례예요.`;
|
||||
|
||||
const hasJoker = my.rack.some((id) => id === 'JK1' || id === 'JK2');
|
||||
const jokerTip = hasJoker
|
||||
? `내 받침대에 조커(가운데 J가 있는 4색 동그라미 타일)가 있어요. 조커는 아무 숫자·색이나 대신해요. 끝날 때 받침대에 남으면 ${v.options.jokerPenalty}점 감점이에요.`
|
||||
: '';
|
||||
|
||||
if (cur !== me) {
|
||||
const lines = [`${curName} 차례예요. 기다려 주세요.${v.draft ? ` 바닥에 ${curName}이 고민 중인 배치가 보여요(확정 전).` : v.draftEdits > 0 ? ` ${curName}이 생각 중이에요.` : ''}`];
|
||||
lines.push(`내 받침대 ${my.rack.length}장 · ${pool}`);
|
||||
if (!my.melded) lines.push(`나는 아직 첫 등록 전이에요. ${meldRule(v)}`);
|
||||
if (seat.away) lines.push('시간 초과가 이어져 자리 비움 상태예요. 내 차례가 3초 만에 넘어가니, 차례가 오면 바로 무엇이든 해 주세요.');
|
||||
if (jokerTip) lines.push(jokerTip);
|
||||
lines.push('기다리는 동안 [색깔순]·[숫자순]으로 받침대를 정리해 보세요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
// My turn.
|
||||
const check = my.check;
|
||||
const drawLabel = v.poolCount > 0 ? '[한 장 가져오기]' : '[넘기기]';
|
||||
const lines = [`내 차례예요(받침대 ${my.rack.length}장). 타일을 눌러 고른 뒤, 바닥 묶음의 ◀ 앞·▶ 뒤나 [새 묶음]을 눌러 놓아요.`];
|
||||
if (!my.melded) lines.push(meldRule(v, check?.meldPoints ?? 0));
|
||||
else lines.push('바닥 묶음을 쪼개고 합쳐 내 타일을 끼워 넣어도 돼요. 바닥 타일은 받침대로 가져올 수 없어요.');
|
||||
|
||||
if (!my.changed) {
|
||||
const hint = v.options.hints ? ' [도와줘]를 누르면 받침대 타일로 바로 낼 수 있는 묶음을 보라색으로 찾아 줘요.' : '';
|
||||
lines.push(`낼 게 없으면 ${drawLabel}를 눌러요. 그러면 차례가 끝나요.${hint} ${pool}`);
|
||||
} else if (check?.ok) {
|
||||
lines.push(`바닥이 모두 올바라요. [확정]을 눌러야 차례가 끝나요.${v.options.timeoutValidDraft === 'revert' ? ' 시간이 다 되면 놓은 타일이 돌아오고 1장을 가져오니 서둘러요.' : ''}`);
|
||||
} else {
|
||||
lines.push(`아직 확정할 수 없어요: ${check?.reason ?? '바닥 묶음을 확인해 주세요.'} 고치기 어려우면 [되돌리기](한 단계 전)나 [처음으로](차례 시작 상태)를 눌러요.`);
|
||||
lines.push(
|
||||
v.options.invalidCommitPenalty === 'penalty3'
|
||||
? `이 방에서는 틀린 채로 [확정]하면 놓은 타일이 돌아오고 3장을 가져와요. 시간이 다 돼도 처음으로 돌아가고 ${v.options.invalidTimeoutPenalty}장을 가져와요.`
|
||||
: `틀린 채로 시간이 다 되면 처음으로 돌아가고 ${v.options.invalidTimeoutPenalty}장을 가져와요. ${drawLabel}를 누르면 확인 창이 뜨고, 바꾼 배치를 되돌린 뒤 차례를 끝내요.`,
|
||||
);
|
||||
}
|
||||
if (jokerTip) lines.push(jokerTip);
|
||||
return lines.join('\n');
|
||||
}
|
||||
@@ -8,6 +8,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';
|
||||
|
||||
const nick = (players: Record<string, PublicUser>, id: string) => players[id]?.nickname ?? '알 수 없음';
|
||||
const userOf = (players: Record<string, PublicUser>, id: string): PublicUser => players[id] ?? { id, nickname: '알 수 없음', avatar: null, kind: 'guest' };
|
||||
@@ -818,6 +820,8 @@ const ui: GameUI<RummikubView, RummikubOptions> = {
|
||||
Options,
|
||||
optionsSummary,
|
||||
Rules,
|
||||
quickStart,
|
||||
helpNow,
|
||||
};
|
||||
|
||||
export default ui;
|
||||
|
||||
101
apps/web/src/games/rummikub/quick.tsx
Normal file
101
apps/web/src/games/rummikub/quick.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
/** 숫자 타일 30초 규칙 요약 (docs/07 §5). Tiles are redrawn here as simple SVG (the screen's Tile lives in index.tsx). */
|
||||
import type { ReactNode } from 'react';
|
||||
import type { QuickCard } from '../types';
|
||||
|
||||
type C = 'K' | 'R' | 'B' | 'O' | 'J';
|
||||
const INK: Record<C, string> = { K: '#111827', R: '#c62828', B: '#1d4ed8', O: '#a14a00', J: '#111827' };
|
||||
const MARK: Record<C, string> = { K: '●', R: '♥', B: '◆', O: '★', J: '' };
|
||||
|
||||
/** One tile at (x, y), 28 x 40. `n` 0 = joker. */
|
||||
function T({ x, y, c, n, fresh }: { x: number; y: number; c: C; n: number; fresh?: boolean }) {
|
||||
return (
|
||||
<g transform={`translate(${x} ${y})`}>
|
||||
<rect width={28} height={40} rx={5} fill="#fffdf7" stroke={fresh ? '#7c3aed' : '#c9b98f'} strokeWidth={fresh ? 2.5 : 1} />
|
||||
{c === 'J' ? (
|
||||
<g transform="translate(14 18)">
|
||||
<path d="M0 0 L0 -10 A10 10 0 0 1 10 0 Z" fill="#c62828" />
|
||||
<path d="M0 0 L10 0 A10 10 0 0 1 0 10 Z" fill="#1d4ed8" />
|
||||
<path d="M0 0 L0 10 A10 10 0 0 1 -10 0 Z" fill="#a14a00" />
|
||||
<path d="M0 0 L-10 0 A10 10 0 0 1 0 -10 Z" fill="#111827" />
|
||||
<circle r={5} fill="#fffdf7" />
|
||||
<text y={3} textAnchor="middle" fontSize={7} fontWeight={900} fill="#111827">
|
||||
J
|
||||
</text>
|
||||
</g>
|
||||
) : (
|
||||
<>
|
||||
<text x={14} y={22} textAnchor="middle" fontSize={17} fontWeight={900} fill={INK[c]}>
|
||||
{n}
|
||||
</text>
|
||||
<text x={14} y={35} textAnchor="middle" fontSize={8} fill={INK[c]}>
|
||||
{MARK[c]}
|
||||
</text>
|
||||
</>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
/** A row of tiles starting at x; returns the tiles for one set (gap 2). */
|
||||
const row = (x: number, y: number, tiles: [C, number][], fresh: number[] = []) =>
|
||||
tiles.map(([c, n], i) => <T key={`${x}-${y}-${i}`} x={x + i * 30} y={y} c={c} n={n} fresh={fresh.includes(i)} />);
|
||||
|
||||
function Felt({ children, h = 150 }: { children: ReactNode; h?: number }) {
|
||||
return (
|
||||
<svg viewBox={`0 0 250 ${h}`} width={250} height={h} aria-hidden>
|
||||
<rect width={250} height={h} rx={12} fill="#1f6f4a" />
|
||||
{children}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
const label = (x: number, y: number, s: string) => (
|
||||
<text x={x} y={y} textAnchor="middle" fontSize={12} fontWeight={800} fill="#fff">
|
||||
{s}
|
||||
</text>
|
||||
);
|
||||
|
||||
export const quickStart: QuickCard[] = [
|
||||
{
|
||||
pic: (
|
||||
<Felt>
|
||||
{label(48, 22, '같은 숫자')}
|
||||
{row(5, 30, [['K', 7], ['R', 7], ['B', 7]])}
|
||||
{label(185, 22, '이어진 숫자')}
|
||||
{row(126, 30, [['B', 3], ['B', 4], ['B', 5], ['B', 6]])}
|
||||
<rect x={20} y={88} width={210} height={52} rx={8} fill="#b07a3c" />
|
||||
{row(35, 94, [['O', 2], ['K', 9], ['R', 12], ['J', 0], ['B', 1], ['O', 13]])}
|
||||
</Felt>
|
||||
),
|
||||
alt: '바닥에 같은 숫자 7 세 장과 파란 3·4·5·6이 놓여 있고, 아래 받침대에 내 타일이 있어요',
|
||||
title: '묶음을 만들어 내요',
|
||||
text: '같은 숫자 다른 색 3~4장, 또는 같은 색 이어진 숫자 3장 이상을 바닥에 내요. 낼 게 없으면 한 장 가져와요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<Felt h={130}>
|
||||
{row(80, 22, [['R', 10], ['R', 11], ['R', 12]])}
|
||||
{label(125, 88, '10 + 11 + 12 = 33점')}
|
||||
{label(125, 110, '첫 등록 30점 넘었어요!')}
|
||||
</Felt>
|
||||
),
|
||||
alt: '빨간 10, 11, 12 타일 세 장, 합이 33점이라 첫 등록 30점을 넘었어요',
|
||||
title: '첫 등록은 점수가 필요해요',
|
||||
text: '처음 낼 때는 내 타일만으로 만든 묶음의 숫자 합이 방에서 정한 점수(보통 30점) 이상이어야 해요.',
|
||||
},
|
||||
{
|
||||
pic: (
|
||||
<Felt h={150}>
|
||||
{row(50, 10, [['R', 4], ['R', 5], ['R', 6], ['R', 7], ['R', 8]])}
|
||||
<text x={125} y={72} textAnchor="middle" fontSize={13} fontWeight={800} fill="#fde047">
|
||||
▼ 내 빨강 6을 넣어 나눠요
|
||||
</text>
|
||||
{row(10, 90, [['R', 4], ['R', 5], ['R', 6]], [2])}
|
||||
{row(150, 90, [['R', 6], ['R', 7], ['R', 8]])}
|
||||
</Felt>
|
||||
),
|
||||
alt: '빨간 4부터 8까지 묶음에 내 빨강 6을 넣어 4·5·6과 6·7·8 두 묶음으로 나눈 모습',
|
||||
title: '바닥을 고쳐서 끼워요',
|
||||
text: '첫 등록 뒤에는 바닥 묶음을 쪼개고 합쳐 내 타일을 끼울 수 있어요. 조커는 아무 타일이나 대신해요. 받침대를 먼저 비우면 이겨요.',
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user