/** 루미큐브 화면 (docs/games/rummikub.md §9). Tap a tile to pick it up, then tap where it goes. */ import { useEffect, useMemo, useRef, useState } from 'react'; // Pure tile/set helpers only (no zod): keeps this lazy chunk small. import { findMeld, normalizeSet, pickDisjoint, setProblem, sortTiles, tileLabel, tileOf, type DraftSet, type JokerAs, type TileColor } from '@bg/games/rummikub/rules'; import type { LogEntry, RummikubOptions, RummikubView } from '@bg/games/rummikub'; import type { PublicUser } from '@bg/shared/lite'; 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, id: string) => players[id]?.nickname ?? '알 수 없음'; const userOf = (players: Record, id: string): PublicUser => players[id] ?? { id, nickname: '알 수 없음', avatar: null, kind: 'guest' }; /** Colour + shape mark so colours never have to be told apart by hue alone (§9). */ const MARK: Record = { K: '●', R: '♥', B: '◆', O: '★' }; const CSS = ` .rk-root { width: 100%; align-self: stretch; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; } .rk-players { display: flex; flex-wrap: wrap; gap: 6px; } .rk-player { display: flex; align-items: center; gap: 6px; background: var(--surface); color: var(--text); border: 3px solid transparent; border-radius: 12px; padding: 4px 10px 4px 6px; box-shadow: var(--shadow); font-size: .9rem; min-height: 44px; } .rk-player.turn { border-color: var(--focus); } .rk-player.gone { opacity: .55; } .rk-player .rk-count { font-weight: 800; font-variant-numeric: tabular-nums; } .rk-badge { display: inline-block; border-radius: 999px; padding: 0 8px; font-weight: 800; font-size: .75rem; line-height: 1.6; } .rk-table { flex: 1; min-height: 200px; overflow: auto; background: var(--felt); border-radius: var(--radius-lg); padding: 10px; display: flex; flex-wrap: wrap; align-content: flex-start; align-items: flex-start; gap: 10px 12px; box-shadow: inset 0 2px 10px rgba(0,0,0,.25); } .rk-table-head { flex-basis: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: .92rem; text-shadow: 0 1px 2px rgba(0,0,0,.4); } .rk-empty { color: rgba(255,255,255,.85); font-size: .95rem; padding: 6px 2px; } .rk-set { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 4px; border-radius: 10px; border: 3px solid transparent; background: rgba(0,0,0,.18); max-width: 100%; } .rk-set.ok { border-color: #86efac; } .rk-set.bad { border-color: #fca5a5; border-style: dashed; background: rgba(127,29,29,.35); } .rk-set.changed { animation: rk-flash 1s ease-out 2; } @keyframes rk-flash { 0% { box-shadow: 0 0 0 5px #fde047; } 100% { box-shadow: 0 0 0 0 rgba(253,224,71,0); } } .rk-problem { flex-basis: 100%; font-size: .8rem; font-weight: 700; color: #fff; background: #b91c1c; border-radius: 6px; padding: 1px 6px; } .rk-setinfo { flex-basis: 100%; display: flex; gap: 6px; align-items: center; justify-content: space-between; font-size: .78rem; color: rgba(255,255,255,.9); } .rk-setinfo button { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 6px; min-height: 28px; padding: 0 6px; cursor: pointer; font-size: .78rem; } .rk-tile { --w: 44px; --h: 60px; --tc: #111827; position: relative; width: var(--w); height: var(--h); flex: none; padding: 0; border-radius: 8px; background: linear-gradient(#fffdf7, #f1e7cf); border: 1px solid #c9b98f; box-shadow: 0 2px 0 #b5a172, 0 3px 6px rgba(0,0,0,.25); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; color: var(--tc); font-weight: 900; line-height: 1; font-family: inherit; transition: transform .2s ease, box-shadow .2s ease; user-select: none; } button.rk-tile { cursor: pointer; } button.rk-tile:disabled { cursor: default; } .rk-tile[data-c=K] { --tc: #111827; } .rk-tile[data-c=R] { --tc: #c62828; } .rk-tile[data-c=B] { --tc: #1d4ed8; } .rk-tile[data-c=O] { --tc: #a14a00; } .rk-n { font-size: calc(var(--h) * .44); font-variant-numeric: tabular-nums; letter-spacing: -.02em; } .rk-m { font-size: calc(var(--h) * .2); margin-top: 3px; } .rk-jk { display: block; width: calc(var(--w) * .62); height: calc(var(--w) * .62); } .rk-jkas { position: absolute; right: 2px; top: 1px; font-size: .62rem; font-weight: 800; color: #374151; } .rk-tile[aria-pressed=true] { transform: translateY(-7px); box-shadow: 0 0 0 3px var(--focus), 0 6px 10px rgba(0,0,0,.3); } .rk-tile.hint { box-shadow: 0 0 0 3px #a855f7, 0 3px 6px rgba(0,0,0,.25); } .rk-tile.fresh::after { content: '새'; position: absolute; top: -7px; left: -5px; background: var(--primary); color: var(--primary-text); font-size: .62rem; font-weight: 800; border-radius: 999px; padding: 1px 4px; } .rk-tile.sm { --w: 38px; --h: 52px; } .rk-tile.xs { --w: 28px; --h: 38px; box-shadow: 0 1px 0 #b5a172; } .rk-tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; } .rk-slot { min-width: 30px; height: 52px; border: 2px dashed rgba(255,255,255,.85); border-radius: 8px; background: rgba(255,255,255,.14); color: #fff; font-weight: 900; font-size: 1rem; cursor: pointer; padding: 0 4px; } .rk-slot:hover, .rk-newset:hover { background: rgba(255,255,255,.28); } .rk-newset { border: 2px dashed rgba(255,255,255,.9); color: #fff; background: rgba(255,255,255,.12); border-radius: 10px; min-height: 60px; padding: 0 16px; font-weight: 800; font-size: 1rem; cursor: pointer; } .rk-meld { flex-basis: 100%; display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: .9rem; } .rk-meld progress { flex: 1; height: 12px; accent-color: #facc15; } .rk-bar { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; } .rk-bar .btn { min-height: 52px; padding: 0 6px; font-size: .98rem; } .rk-msg { margin: 0; min-height: 1.4em; text-align: center; font-size: .92rem; } .rk-rackwrap { display: flex; flex-direction: column; gap: 6px; } .rk-rackhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; } .rk-rackhead .segmented button { min-height: 40px; } .rk-rack { background: var(--wood); border-radius: var(--radius-lg); padding: 10px 8px 14px; display: flex; flex-wrap: wrap; gap: 5px; min-height: 84px; box-shadow: inset 0 -7px 0 var(--wood-line); align-content: flex-start; } .rk-rack-empty { color: #3b2a0a; font-weight: 700; align-self: center; } .rk-result { display: grid; gap: 6px; } .rk-result-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; } .rk-mini { display: inline-flex; gap: 2px; flex-wrap: wrap; } @media (max-width: 1099px) { .rk-table { overflow: visible; min-height: 160px; } } @media (max-width: 719px) { .rk-bar { position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding: 6px 0; grid-template-columns: repeat(3, minmax(0, 1fr)); } .rk-bar .btn { min-height: 48px; font-size: .95rem; } .rk-tile.sm { --w: 34px; --h: 47px; } .rk-slot { height: 47px; min-width: 28px; } .rk-table { padding: 8px; gap: 8px; } .rk-player { font-size: .85rem; padding: 3px 8px 3px 4px; } } @media (prefers-reduced-motion: reduce) { .rk-tile { transition: none; } .rk-set.changed { animation: none; box-shadow: 0 0 0 3px #fde047; } } `; // ---------------------------------------------------------------- tile function JokerFace() { // Four coloured quarters + a ring: not a face, not a copy of any commercial joker design. return ( J ); } interface TileProps { id: string; size?: 'md' | 'sm' | 'xs'; as?: JokerAs; selected?: boolean; hint?: boolean; fresh?: boolean; onClick?: () => void; } function Tile({ id, size = 'md', as, selected, hint, fresh, onClick }: TileProps) { const t = tileOf(id); const cls = `rk-tile${size !== 'md' ? ` ${size}` : ''}${hint ? ' hint' : ''}${fresh ? ' fresh' : ''}`; const body = t.kind === 'joker' ? ( <> {as && {as.n}} ) : ( <> {t.n} {MARK[t.color]} ); const label = `${tileLabel(id, as)}${fresh ? ', 새로 가져온 타일' : ''}`; const dataC = t.kind === 'num' ? t.color : undefined; if (!onClick) { return ( {body} ); } return ( ); } // ---------------------------------------------------------------- draft editing /** Keeps a set in a readable order: the server's interpretation when valid, otherwise as placed. */ function arrange(d: DraftSet): DraftSet { const n = normalizeSet(d); const tileIds = n ? n.tileIds : d.tileIds; return d.as ? { tileIds, as: d.as } : { tileIds }; } type Target = { set: number; at: 'start' | 'end' } | 'new' | 'rack'; /** Moves `sel` to the target; tiles that were on the table at turn start never go back to the rack. */ function moveTiles(sets: DraftSet[], sel: string[], target: Target, onTable0: Set): DraftSet[] | null { const moving = target === 'rack' ? sel.filter((id) => !onTable0.has(id)) : sel; if (!moving.length) return null; const ordered = sortTiles(moving, 'number'); const next: DraftSet[] = sets.map((d) => ({ ...d, tileIds: d.tileIds.filter((id) => !moving.includes(id)) })); let touched: DraftSet | null = null; if (target === 'new') { touched = { tileIds: ordered }; next.push(touched); } else if (target !== 'rack') { touched = next[target.set]!; touched.tileIds = target.at === 'start' ? [...ordered, ...touched.tileIds] : [...touched.tileIds, ...ordered]; } return next.filter((d) => d.tileIds.length > 0).map((d) => (d === touched ? arrange(d) : d)); } // ---------------------------------------------------------------- board function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardProps) { const my = v.my; const mine = v.phase === 'playing' && !!me && v.current === me; const [sel, setSel] = useState([]); const [hintIds, setHintIds] = useState([]); const [local, setLocal] = useState(null); const [sortBy, setSortBy] = useState<'color' | 'number'>(() => (localStorage.getItem('rk-sort') === 'number' ? 'number' : 'color')); const [msg, setMsg] = useState(''); const [confirm, setConfirm] = useState(null); const [announce, setAnnounce] = useState(''); const wasMine = useRef(false); const lastLog = useRef(''); const serverSets: DraftSet[] = useMemo( () => (v.draft ? v.draft.map((d) => (d.as ? { tileIds: d.tileIds, as: d.as } : { tileIds: d.tileIds })) : v.table.map((t) => ({ tileIds: t.tileIds, as: t.kind }))), [v.draft, v.table], ); // Optimistic draft until the server answers (cleared when nothing is pending any more). useEffect(() => { if (!pending) setLocal(null); }, [pending, v.turnNo, v.draftEdits]); const sets = mine && local ? local : serverSets; const onTable0 = useMemo(() => new Set(v.table.flatMap((t) => t.tileIds)), [v.table]); const inSets = useMemo(() => new Set(sets.flatMap((d) => d.tileIds)), [sets]); const rack = useMemo(() => sortTiles((my?.rack ?? []).filter((id) => !inSets.has(id)), sortBy), [my?.rack, inSets, sortBy]); const fresh = new Set(my?.lastDrawn ?? []); // Turn change: clear selection and hints, announce. useEffect(() => { setSel([]); setHintIds([]); setMsg(''); if (mine && !wasMine.current) { haptic(40); sounds.myTurn(); setAnnounce('내 차례예요.'); } wasMine.current = mine; }, [v.turnNo, mine]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { const e = v.log[v.log.length - 1]; if (!e) return; const key = `${v.match.gameNo}-${e.turn}-${e.kind}`; if (key === lastLog.current) return; lastLog.current = key; if (e.by !== me) setAnnounce(logText(e, players, me)); }, [v.log]); // eslint-disable-line react-hooks/exhaustive-deps // Drop selected tiles that disappeared (e.g. after undo on the server). useEffect(() => { setSel((s) => (s.every((id) => inSets.has(id) || rack.includes(id)) ? s : s.filter((id) => inSets.has(id) || rack.includes(id)))); }, [inSets, rack]); const send = (next: DraftSet[]) => { setLocal(next); act({ type: 'setDraft', sets: next, turn: v.turnNo }); }; const toggle = (id: string) => { if (!mine) return; setHintIds([]); setMsg(''); setSel((s) => (s.includes(id) ? s.filter((x) => x !== id) : [...s, id])); }; const move = (target: Target) => { if (!mine || !sel.length) return; if (!my?.melded && !v.options.initialMeldAllowExtend && sel.some((id) => onTable0.has(id))) { setMsg('첫 등록 전에는 바닥의 타일을 옮길 수 없어요. 내 받침대 타일만 골라 주세요.'); return; } if (target === 'rack' && sel.some((id) => onTable0.has(id))) setMsg('바닥에 있던 타일은 받침대로 가져올 수 없어요.'); else setMsg(''); const next = moveTiles(sets, sel, target, onTable0); if (!next) return; setSel([]); send(next); }; const toggleKind = (i: number) => { const d = sets[i]!; const cur = v.draft?.[i]?.kind ?? 'run'; send(sets.map((x, k) => (k === i ? { tileIds: d.tileIds, as: cur === 'run' ? 'group' : 'run' } : x))); }; const hint = () => { const free = rack; let found: string[][] = []; if (!my?.melded) found = (findMeld(free, v.options.initialMeldPoints) ?? []).map((m) => m.tileIds); else found = pickDisjoint(free).sets.slice(0, 1).map((m) => m.tileIds); if (!found.length) { setHintIds([]); setMsg(my?.melded ? '받침대 타일만으로 바로 만들 수 있는 묶음이 없어요. 바닥 묶음에 붙여 보거나 한 장 가져오세요.' : `받침대 타일만으로 ${v.options.initialMeldPoints}점을 만들기 어려워요. 한 장 가져오세요.`); return; } setHintIds(found.flat()); setSel(found[0]!); setMsg(found.length > 1 ? `보라색 타일로 묶음 ${found.length}개를 만들 수 있어요. 첫 묶음을 골라 두었어요. "새 묶음"을 눌러 보세요.` : '보라색 타일로 묶음을 만들 수 있어요. 골라 두었으니 "새 묶음"을 눌러 보세요.'); }; const commit = () => { if (my?.check && !my.check.ok && v.options.invalidCommitPenalty === 'penalty3' && my.changed && my.check.fromRack > 0) { setConfirm('commit'); return; } act({ type: 'commit', turn: v.turnNo }); }; const draw = () => { if (my?.changed) setConfirm('draw'); else act({ type: v.poolCount ? 'draw' : 'pass' }); }; const check = my?.check ?? null; const viewDraft = v.draft; const showingDraft = !!viewDraft; const thinking = v.current && v.current !== me && v.draftEdits > 0; const curName = v.current ? nick(players, v.current) : ''; const selFromSets = sel.some((id) => inSets.has(id) && !onTable0.has(id)); return (
{showingDraft && !mine ? `${curName}님이 고민 중인 배치` : mine && my?.changed ? '바닥(확정 전)' : '바닥'} {thinking && !showingDraft ? ` · ${curName}님이 생각 중…` : ''} 남은 타일 {v.poolCount}장
{mine && my && !my.melded && (
첫 등록 {check?.meldPoints ?? 0} / {v.options.initialMeldPoints}점
)} {sets.length === 0 && !(mine && sel.length) &&

아직 바닥에 놓인 타일이 없어요.

} {sets.map((d, i) => { const info = mine || showingDraft ? (local ? null : viewDraft?.[i]) : null; const n = info ? null : normalizeSet(d); const ok = info ? info.ok : !!n; const problem = info ? info.problem : n ? null : setProblem(d); const jokerAs = info ? info.jokerAs : (n?.jokerAs ?? {}); const tableSet = !mine && !showingDraft ? v.table[i] : undefined; const changed = !!tableSet && v.lastChanged.includes(tableSet.id); const label = `묶음 ${i + 1}: ${d.tileIds.map((id) => tileLabel(id, jokerAs[id])).join(', ')}${mine || showingDraft ? (ok ? ' (올바름)' : ` (고쳐야 함: ${problem ?? ''})`) : ''}`; return (
{mine && sel.length > 0 && ( )} {d.tileIds.map((id) => ( toggle(id) : undefined} /> ))} {mine && sel.length > 0 && ( )} {(mine || showingDraft) && !ok && problem && {problem}} {mine && info?.ambiguous && ( {info.kind === 'group' ? '같은 숫자 묶음으로 봐요' : '이어진 숫자로 봐요'} )}
); })} {mine && sel.length > 0 && ( )}
{mine && ( <>

{msg || (sel.length ? `${sel.length}장 골랐어요. 놓을 곳(◀ ▶ 또는 새 묶음)을 누르세요.` : my?.changed ? check?.ok ? '좋아요! 확정을 누르면 차례가 끝나요.' : (check?.reason ?? '') : '타일을 눌러 고른 뒤 놓을 곳을 누르세요.')}

{selFromSets ? ( ) : ( )}
{check?.ok ? '지금 확정할 수 있어요' : (check?.reason ?? '')} )} {v.phase !== 'playing' && v.round && } {my && v.phase === 'playing' && (
내 받침대 ({my.rack.length}장{rack.length !== my.rack.length ? `, ${my.rack.length - rack.length}장은 바닥에` : ''})
{( [ ['color', '색깔순'], ['number', '숫자순'], ] as const ).map(([k, l]) => ( ))}
{rack.length === 0 && {my.rack.length ? '모두 바닥에 놓았어요.' : '타일이 없어요.'}} {rack.map((id) => ( toggle(id) : undefined} /> ))}
)}

{announce}

{confirm === 'draw' && ( act({ type: v.poolCount ? 'draw' : 'pass' })} onClose={() => setConfirm(null)} /> )} {confirm === 'commit' && ( act({ type: 'commit', turn: v.turnNo })} onClose={() => setConfirm(null)} /> )}
); } function Players({ v, me, players, deadline }: { v: RummikubView; me: string | null; players: Record; deadline: number | null }) { return (
{v.seats.map((s) => { const turn = v.current === s.id; const u = userOf(players, s.id); return (
{u.nickname} {s.id === me && (나)} {s.tiles}장 {!s.melded && s.inRound && ( 첫 등록 전 )} {s.left && ( 나감 )} {!s.left && s.away && ( 자리 비움 )} {v.match.total > 1 && {s.wins}승} {turn && }
); })}
); } function RoundPanel({ v, me, players, act, pending, deadline }: { v: RummikubView; me: string | null; players: Record; act: (a: unknown) => void; pending: boolean; deadline: number | null }) { const r = v.round!; const title = r.endReason === 'rackEmpty' ? `${r.winners.map((w) => nick(players, w)).join(', ')}님이 타일을 모두 내려놓았어요! 다 냈다!` : r.endReason === 'stalemate' ? '더 낼 수 있는 사람이 없어 끝났어요. 남은 타일 점수가 적은 사람이 이겨요.' : '판이 끝났어요.'; const order = r.ranking.flat(); return (
{v.match.total > 1 ? `${r.gameNo}판 결과 · ` : ''} {title} {order.map((p) => (
{nick(players, p)} {r.winners.includes(p) ? ' 🏆' : ''} = 0 ? 'var(--success)' : 'var(--danger)' }}> {r.scores[p]! > 0 ? '+' : ''} {r.scores[p]}점 남은 타일 {r.rackValues[p]}점 {(r.revealed[p] ?? []).map((id) => ( ))}
))} 점수는 이 방에서 순위를 정하는 데만 써요. {v.phase === 'roundEnd' && (
{v.my?.needReady ? ( ) : ( {me && v.ready.includes(me) ? '다른 사람을 기다리는 중이에요.' : '다음 판을 기다리는 중이에요.'} )}
)}
); } function logText(e: LogEntry, players: Record, me: string | null): string { const who = e.by === me ? '내가' : `${nick(players, e.by)}님이`; switch (e.kind) { case 'commit': return `${who} ${e.count}장을 냈어요.`; case 'timeoutCommit': return `시간이 다 되어 ${who} 놓아 둔 ${e.count}장이 확정됐어요.`; case 'draw': return `${who} 1장을 가져왔어요.`; case 'timeoutDraw': return `시간이 다 되어 ${who} ${e.count}장을 가져왔어요.`; case 'penalty': return `${who} 묶음을 다 맞추지 못해 ${e.count}장을 가져왔어요.`; case 'pass': return `${who} 넘겼어요.`; case 'left': return `${nick(players, e.by)}님이 나갔어요.`; } } // ---------------------------------------------------------------- side function RummikubSide({ view: v, me, players }: BoardProps) { const order = [...v.seats].sort((a, b) => b.wins - a.wins || b.total - a.total); const lastRound = v.opening.length ? Math.max(...v.opening.map((o) => o.round)) : 0; return ( <>
{v.phase === 'finished' ? '게임 끝' : v.match.total > 1 ? `${v.match.gameNo}판 / ${v.match.total}판` : '루미큐브'} 남은 타일 {v.poolCount}장
    {order.map((s) => (
  1. {nick(players, s.id)} {s.left ? ' · 나감' : ''} {s.tiles}장 {v.match.total > 1 && ( {s.wins}승 · {s.total > 0 ? '+' : ''} {s.total}점 )}
  2. ))}
{lastRound > 0 && v.match.gameNo >= 1 && ( 선 정하기:{' '} {v.opening .filter((o) => o.round === lastRound) .map((o) => `${nick(players, o.player)} ${o.n === null ? '조커(다시)' : o.n}`) .join(' · ')} {lastRound > 1 ? ` (${lastRound}번째 뽑기)` : ''} )}
{v.log.length > 0 && (
기록
    {[...v.log].reverse().map((e, i) => (
  1. {logText(e, players, me)}
  2. ))}
)}
규칙 요약
); } // ---------------------------------------------------------------- status function isMyTurn(v: RummikubView, me: string | null): boolean { if (!me) return false; if (v.phase === 'roundEnd') return !!v.my?.needReady; return v.phase === 'playing' && v.current === me; } function statusText(v: RummikubView, me: string | null, players: Record): string { if (v.phase === 'finished') return v.result?.summary ?? '게임이 끝났어요'; if (v.phase === 'roundEnd') return v.my?.needReady ? '판이 끝났어요. 다음 판을 시작해 주세요' : '다음 판을 기다리는 중이에요'; if (v.current === me && v.my) { if (!v.my.melded) return `내 차례예요 · 첫 등록 ${v.my.check?.meldPoints ?? 0}/${v.options.initialMeldPoints}점`; return '내 차례예요. 타일을 내거나 한 장 가져오세요'; } if (!v.current) return '잠시만 기다려 주세요'; return `${nick(players, v.current)}님 차례예요${v.draftEdits > 0 ? ' · 생각 중' : ''}`; } // ---------------------------------------------------------------- options function Seg({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) { return (
{options.map(([k, l]) => ( ))}
); } function Field({ label, help, children }: { label: string; help?: string; children: React.ReactNode }) { return (
{label} {children} {help && {help}}
); } function Options({ value: o, onChange }: OptionsProps) { const [more, setMore] = useState(false); const set = (patch: Partial) => onChange({ ...o, ...patch }); return (
set({ initialMeldPoints })} /> set({ turnSeconds: k === 'none' ? null : (Number(k) as 60 | 90 | 120 | 180) })} /> set({ gamesPerMatch })} /> set({ hints })} /> {more && ( <> set({ timeoutValidDraft })} /> set({ invalidTimeoutPenalty })} /> set({ invalidCommitPenalty })} /> set({ jokerPenalty })} /> set({ initialMeldAllowExtend })} /> set({ showDraftToOthers })} /> )}
); } function optionsSummary(o: RummikubOptions): string { const games = o.gamesPerMatch === 'players' ? '인원수만큼' : `${o.gamesPerMatch}판`; const t = o.turnSeconds; const sec = t === null ? null : t % 60 ? `${Math.floor(t / 60)}분 ${t % 60}초` : `${t / 60}분`; return [o.initialMeldPoints ? `첫 등록 ${o.initialMeldPoints}점` : '첫 등록 점수 없음', sec ? `한 차례 ${sec}` : '시간 무제한', games, o.jokerPenalty === 50 ? '조커 50점' : '', o.showDraftToOthers ? '배치 공개' : ''] .filter(Boolean) .join(' · '); } // ---------------------------------------------------------------- rules function Example({ ids }: { ids: string[] }) { const n = normalizeSet({ tileIds: ids }); return ( {ids.map((id) => ( ))} ); } function Rules({ options }: { options?: RummikubOptions }) { const o = options; const meld = o?.initialMeldPoints ?? 30; return (

1부터 13까지 숫자가 적힌 4가지 색 타일(색마다 모양 표시 ● ♥ ◆ ★)이 두 벌씩 104장, 조커 2장이 있어요. 각자 14장을 받고, 내 받침대의 타일을 가장 먼저 모두 내려놓으면 이겨요.

묶음 두 가지

  • 같은 숫자, 다른 색 3~4장
  • 같은 색, 이어지는 숫자 3장 이상 (13 다음에 1은 올 수 없어요)
  • 조커는 아무 타일이나 대신해요

내 차례: 타일을 1장 이상 내고 "확정"을 누르거나, "한 장 가져오기"를 눌러요. 타일을 누른 뒤 놓을 곳(◀ 앞, ▶ 뒤, 새 묶음)을 누르면 옮겨져요. 확정할 때 바닥의 모든 묶음이 올바라야 해요.

첫 등록:{' '} {meld ? `처음 낼 때는 받침대 타일만으로 만든 새 묶음의 숫자 합이 ${meld}점 이상이어야 해요. 조커는 대신하는 숫자로 세요.` : '이 방은 첫 등록 점수가 없어요.'}{' '} {o?.initialMeldAllowExtend ? '첫 등록 차례에도 점수를 채운 뒤에는 바닥 묶음을 고칠 수 있어요.' : '첫 등록 전에는 바닥 묶음을 건드릴 수 없어요.'}

바닥 고치기: 첫 등록 뒤에는 바닥의 묶음을 쪼개고 합치고 옮겨서 내 타일을 끼워 넣을 수 있어요. 예를 들어 빨강 4-5-6-7-8 사이에 내 빨강 6을 넣어 4-5-6과 6-7-8로 나눌 수 있어요. 바닥 타일은 받침대로 가져올 수 없고, 조커를 빼 왔다면 같은 차례에 다시 바닥에 써야 해요.

시간: {o?.turnSeconds === null ? '이 방은 시간 제한이 없어요. 연결이 끊긴 채로 오래 지나면' : `한 차례는 ${o ? `${o.turnSeconds}초` : '1분'}예요. 시간이 다 되면`}{' '} {o?.timeoutValidDraft === 'revert' ? '놓아 둔 타일을 되돌리고 1장을 가져와요' : '올바르게 놓아 둔 타일은 자동으로 확정돼요'}. 묶음이 틀린 채로 끝나면 처음으로 되돌리고 {o?.invalidTimeoutPenalty ?? 3}장을 가져와요.

점수: 누가 다 내려놓으면 나머지는 받침대 숫자 합만큼 빼고(조커 {o?.jokerPenalty ?? 30}점), 이긴 사람이 그만큼 더해요. 남은 타일이 없는데 아무도 못 내면 받침대 합이 가장 적은 사람이 이겨요. 점수는 이 방의 순위에만 써요.

); } const ui: GameUI = { Board: RummikubBoard, Side: RummikubSide, statusText, isMyTurn, Options, optionsSummary, Rules, quickStart, helpNow, }; export default ui;