/** 포커 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. Chips are play points only. */ import type { BetActionType, LegalBetView, PokerMode, PokerView, SeatView } from '@bg/games/poker'; import type { PublicUser } from '@bg/shared/lite'; /** Button labels exactly as the betting bar renders them (index.tsx BET_KO). */ const BET_KO: Record = { 'k.check': '체크', 'k.ping': '삥', 'k.call': '콜', 'k.ddadang': '따당', 'k.quarter': '쿼터', 'k.half': '하프', 'k.full': '풀', 'k.die': '다이', 'nl.fold': '폴드', 'nl.check': '체크', 'nl.call': '콜', 'nl.raise': '레이즈', 'nl.allIn': '올인', }; /** Button order of the betting bar. */ const ORDER: BetActionType[] = ['k.die', 'k.check', 'k.ping', 'k.call', 'k.ddadang', 'k.quarter', 'k.half', 'k.full', 'nl.fold', 'nl.check', 'nl.call', 'nl.raise', 'nl.allIn']; const KOREAN_RAISE: Partial> = { 'k.ping': '기본 칩만큼', 'k.ddadang': '앞사람이 건 만큼의 두 배', 'k.quarter': '모인 칩의 4분의 1만큼 더', 'k.half': '모인 칩의 절반만큼 더', 'k.full': '모인 칩만큼 더', }; const MODE_KO: Record = { holdem: '텍사스 홀덤', omaha: '오마하', sevenPoker: '7포커', sevenHiLo: '7포커 하이로우', badugi: '바둑이', fiveDraw: '5카드 드로우', indian: '인디언 포커', }; const SIDE_KO = { high: '하이', low: '로우', swing: '스윙' } as const; const DRAW_NAMES = ['아침', '점심', '저녁']; const chips = (n: number) => `${Math.max(0, Math.round(n)).toLocaleString('ko-KR')} 칩`; const nickOf = (players: Record, id: string | null | undefined) => { const n = id ? players[id]?.nickname : undefined; return n ? `${n}님` : '다른 사람'; }; const namesOf = (players: Record, ids: string[]) => ids.map((id) => nickOf(players, id)).join(', '); const btn = (t: BetActionType) => `[${BET_KO[t]}]`; /** "지금 내 족보" from the hints option (the view sends null when hints are off or the mode has none). */ function handLine(v: PokerView): string | null { const { handName, lowName } = v.my; if (!handName) return null; const low = lowName ? (lowName === '로우 없음' ? ' · 로우 없음' : ` · 로우 ${lowName}`) : ''; return `지금 내 족보: ${handName}${low}`; } /** What this betting round is about, per mode. `mine` = written for a seated player in the hand. */ function modeLine(v: PokerView, mine: boolean, players: Record, me: string | null): string { const n = v.board.length; switch (v.mode) { case 'holdem': case 'omaha': { const board = n === 0 ? '공용 카드는 아직 없어요(SB·BB 표시는 미리 칩을 낸 블라인드예요).' : `가운데 공용 카드 ${n}장이 펼쳐져 있어요${n === 5 ? '(다 나왔어요)' : ''}.`; const make = v.mode === 'holdem' ? `${mine ? '내' : '각자'} 카드 2장과 공용 카드를 합쳐 가장 좋은 5장을 만들어요.` : `${mine ? '내' : '각자'} 카드 4장 중 꼭 2장 + 공용 카드 3장으로 5장을 만들어요.`; return `${board} ${make}`; } case 'sevenPoker': case 'sevenHiLo': { const boss = v.seats.find((s) => s.boss); const parts: string[] = []; if (boss) parts.push(boss.id === me ? '공개 카드가 가장 좋아서 내가 보스(먼저 베팅)예요.' : `보스(공개 카드가 가장 좋은 사람, 먼저 베팅)는 ${nickOf(players, boss.id)}이에요.`); if (v.street === 3) parts.push(`마지막 7번째 카드는 ${mine ? '나만' : '본인만'} 보는 히든 카드예요.`); if (v.mode === 'sevenHiLo' && v.street === 3) parts.push('이 베팅이 끝나면 하이·로우·스윙을 선언해요.'); return parts.join(' '); } case 'badugi': return v.street < 3 ? `이 베팅이 끝나면 ${DRAW_NAMES[v.street] ?? ''} 교환(카드 바꾸기)이 있어요. 숫자도 무늬도 겹치지 않는 낮은 카드일수록 좋아요.` : '마지막 베팅이에요. 끝나면 패를 비교해요(낮을수록 좋아요).'; case 'fiveDraw': return v.street === 0 ? '이 베팅이 끝나면 카드를 한 번 바꿀 수 있어요.' : '카드를 바꾼 뒤 마지막 베팅이에요.'; case 'indian': { const hand = v.options.indianCards === 2 && v.street === 1 ? ` 손 카드는 ${mine ? '나만' : '본인만'} 보고, 이마 + 손 2장으로 겨뤄요.` : ''; return mine ? `내 이마 카드는 나만 못 봐요. 다른 사람 이마 카드와 베팅을 보고 내 카드를 짐작해요.${hand}` : `구경할 때는 이마 카드가 판이 끝나야 보여요.${hand}`; } } } const roundName = (v: PokerView) => { const s = v.streetName || '베팅'; return s.endsWith('베팅') ? s : `${s} 베팅`; }; function myBetting(v: PokerView, players: Record, me: string): string[] { const legal = new Map(v.my.legal.map((l) => [l.type, l])); const usable = ORDER.filter((t) => legal.has(t)); const lines = [`내 차례예요. 지금은 ${roundName(v)}이에요. 누를 수 있는 버튼: ${usable.map(btn).join(' ')}`]; const call = legal.get('k.call') ?? legal.get('nl.call'); const check = legal.has('k.check') || legal.has('nl.check'); const fold = v.betStyle === 'korean' ? '[다이]' : '[폴드]'; if (call?.allIn) lines.push(`가진 칩이 모자라서 [콜]하면 올인이에요. 이번 판을 포기하려면 ${fold}.`); else if (call) lines.push(`앞사람에게 맞추려면 ${chips(v.my.toCall)}이 필요해요([콜]). 이번 판을 포기하려면 ${fold}.`); else if (check) lines.push('칩을 더 내지 않고 넘기려면 [체크]를 누르세요.'); if (v.betStyle === 'korean') { const raises = usable.filter((t) => KOREAN_RAISE[t]); if (raises.length) lines.push(`올리기: ${raises.map((t) => `${btn(t)} ${KOREAN_RAISE[t]}`).join(' · ')}. 버튼 아래 숫자만큼 칩이 바로 나가요.`); else if (!call?.allIn) lines.push('한국식 베팅은 한 라운드에 한 번만 올릴 수 있고, 체크나 콜을 한 뒤에는 못 올려요.'); } else { const raise = legal.get('nl.raise'); if (raise && raise.minTo !== undefined && raise.maxTo !== undefined) { lines.push(`[레이즈]를 누르면 올릴 칩(이번 라운드 총 ${chips(raise.minTo)}~${chips(raise.maxTo)})을 고르고 [확인]을 눌러요.`); } if (legal.has('nl.allIn')) lines.push('[올인]은 가진 칩을 모두 걸어요.'); } const hand = handLine(v); if (hand) lines.push(hand); const mode = modeLine(v, true, players, me); if (mode) lines.push(mode); return lines; } function bettingWatch(v: PokerView, players: Record, me: string | null, mine: boolean): string[] { const who = v.toAct ? `${nickOf(players, v.toAct)} 차례예요(${roundName(v)}).` : `${roundName(v)}이에요.`; const lines = [mine ? `${who} 기다려 주세요.` : `${who} 지금 모인 칩은 ${chips(v.pot)}이에요.`]; if (mine) { const hand = handLine(v); if (hand) lines.push(hand); } const mode = modeLine(v, mine, players, me); if (mode) lines.push(mode); return lines; } /** Neutral description of the current step (spectators, players out of this hand). */ function watchText(v: PokerView, players: Record, me: string | null): string { const waiting = v.waiting.length ? ` 아직 고르는 사람: ${namesOf(players, v.waiting)}.` : ''; switch (v.handPhase) { case 'betting': return bettingWatch(v, players, me, false).join('\n'); case 'choice': return `모두 동시에 받은 4장 중 버릴 카드 1장과 모두에게 보여 줄 카드 1장을 고르는 중이에요. 다 고르면 보여 줄 카드가 한꺼번에 공개돼요.${waiting}`; case 'draw': return `모두 동시에 바꿀 카드를 고르는 중이에요(${drawName(v)}). 버린 카드는 공개되지 않고, 바꾼 장수만 각 자리에 보여요.${waiting}`; case 'declare': return `남은 사람들이 하이·로우·스윙 중 하나를 몰래 고르는 중이에요. 모두 고르면 한꺼번에 공개돼요.${waiting}`; case 'reveal': return `다른 사람이 모두 포기해서 혼자 남은 ${nickOf(players, v.waiting[0])}이 카드 공개 여부를 고르는 중이에요.`; default: return '카드를 나눠 주는 중이에요. 잠시만 기다려 주세요.'; } } const drawName = (v: PokerView) => (v.mode === 'badugi' ? `${DRAW_NAMES[v.street - 1] ?? ''} 교환`.trim() : '교환'); function handEndText(v: PokerView, players: Record, me: string | null, seat: SeatView | undefined): string { const lines: string[] = []; const sdName = (id: string) => (v.mode === 'sevenHiLo' ? undefined : v.showdown?.find((e) => e.id === id)?.handName); const who = (id: string) => (id === me ? '내가' : `${nickOf(players, id)}이`); if (v.foldWin && v.winners.length === 1) { const shown = v.foldShown ? `패를 공개했어요(${v.foldShown.handName}).` : '패는 공개하지 않았어요.'; lines.push(`다른 사람이 모두 포기해서 ${who(v.winners[0]!)} 모인 칩을 가져갔어요. ${shown}`); } else if (v.winners.length === 1) { const name = sdName(v.winners[0]!); lines.push(`이번 판은 ${who(v.winners[0]!)} ${name ? `${name}(으)로 ` : ''}이겼어요.`); } else if (v.winners.length > 1) { lines.push(`이번 판에 칩을 가져간 사람: ${v.winners.map((id) => (id === me ? '나' : nickOf(players, id))).join(', ')}.`); } else if (v.carryOver > 0) { lines.push(`동점이라 모인 칩 ${chips(v.carryOver)}이 다음 판으로 넘어가요.`); } else { lines.push('이번 판이 끝났어요. 건 칩은 돌려받았어요.'); } lines.push('누가 칩을 얼마나 가져갔는지는 [이번 판 결과]에 나와요.'); if (v.mode === 'indian') lines.push(`판이 끝나서 ${seat?.inHand ? '내 이마 카드를 포함해 ' : ''}모든 카드가 공개됐어요.`); const last = v.options.endCondition === 'hands' && v.handNo >= v.options.handLimit; if (v.my.canReady) lines.push(`[다음 판으로]를 누르면 준비 완료예요. 모두 누르거나 시간이 지나면 ${last ? '최종 순위가 나와요' : '다음 판이 시작돼요'}.`); else if (seat?.inHand && seat.ready) lines.push('준비했어요. 다른 사람을 기다리는 중이에요.'); else if (last) lines.push('마지막 판이었어요. 곧 최종 순위가 나와요.'); return lines.join('\n'); } export function helpNow(v: PokerView, me: string | null, players: Record): string { if (v.phase === 'finished') { return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n[최종 순위]에서 순위를 볼 수 있고, 결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.'; } const seat = me ? v.seats.find((s) => s.id === me) : undefined; const modeName = `${MODE_KO[v.mode]} ${Math.max(1, v.handNo)}${v.options.endCondition === 'hands' ? `/${v.options.handLimit}` : ''}판`; if (v.phase === 'rebuy') { if (v.my.canRebuy) { const left = v.my.rebuysLeft !== null ? ` (남은 횟수 ${v.my.rebuysLeft}번)` : ''; return `칩을 모두 잃었어요. [칩 다시 받기]를 누르면 놀이용 칩 ${chips(v.options.startingChips)}을 다시 받고 계속해요${left}. 다시 받은 만큼 최종 점수에서 빠져요.\n[그만하기]를 누르면 탈락하고 구경만 해요.`; } const pending = v.seats.filter((s) => s.rebuyPending).map((s) => s.id); return `${pending.length ? namesOf(players, pending) : '칩이 떨어진 사람'}이 칩을 다시 받을지 고르는 중이에요. 잠시 기다려 주세요.`; } if (v.handPhase === 'handEnd') return handEndText(v, players, me, seat); const away = seat?.away ? "\n시간을 두 번 넘겨 '자리 비움'이 됐어요. 직접 버튼을 누르면 풀려요." : ''; if (!seat) return `${modeName}이에요. ${watchText(v, players, me)}`; if (!seat.inHand) { const why = seat.status === 'eliminated' ? '탈락해서 이제 구경만 해요.' : seat.status === 'left' ? '방을 나가서 이번 판에는 빠졌어요.' : '이번 판에는 참가하지 않아요. 다음 판을 기다려 주세요.'; return `${why}\n${watchText(v, players, me)}`; } if (seat.folded) { return `이번 판은 포기했어요(${v.betStyle === 'korean' ? '다이' : '폴드'}). 다음 판을 기다려 주세요. 내 카드는 나만 볼 수 있어요.\n${watchText(v, players, me)}${away}`; } const m = v.my; const hand = handLine(v); const withHand = (lines: string[]) => (hand ? [...lines, hand] : lines).join('\n') + away; switch (v.handPhase) { case 'betting': { if (me && v.toAct === me) return myBetting(v, players, me).join('\n') + away; const lines = bettingWatch(v, players, me, true); if (seat.allIn) lines.splice(1, 0, '나는 올인해서 이번 판에는 더 걸 수 없어요. 카드는 끝까지 받고, 건 만큼까지 겨뤄요.'); return lines.join('\n') + away; } case 'choice': if (m.canChoose) { return withHand([ '7포커 초이스: 받은 4장 중 ① 버릴 카드 1장을 먼저 누르고(✕ 표시) ② 모두에게 보여 줄 카드 1장을 누른 뒤 [확인]을 눌러요. 잘못 골랐으면 [다시 고르기].', '버린 카드는 아무도 못 보고, 남는 2장은 나만 봐요. 모두 동시에 골라요.', ]); } return withHand(['골랐어요. 모두 고르면 보여 줄 카드가 한꺼번에 공개돼요. 기다려 주세요.']); case 'draw': if (m.canDraw) { const limit = m.drawAceBonus ? '3장까지 바꿀 수 있어요(A를 남기면 4장).' : `${m.drawMax}장까지 바꿀 수 있어요.`; const tip = v.mode === 'badugi' ? ' 숫자나 무늬가 겹치는 카드, 높은 카드를 바꾸면 좋아요.' : ''; return withHand([ `${drawName(v)}: 바꿀 카드를 눌러 위로 올린 뒤 [2장 바꾸기]처럼 장수가 적힌 버튼을 누르세요. 안 바꾸려면 아무것도 고르지 말고 [패스(안 바꾸기)].`, `${limit} 모두 동시에 내고, 버린 카드는 공개되지 않아요.${tip}`, ]); } return withHand(['바꿀 카드를 냈어요. 모두 내면 새 카드를 받아요. 기다려 주세요.']); case 'declare': if (m.canDeclare) { return withHand([ '[하이]·[로우]·[스윙] 중 하나를 누르세요. 하이는 높은 족보, 로우는 낮은 패로 겨뤄요. 스윙은 둘 다 이겨야 모두 가져가고, 하나라도 지면 못 받아요.', '모두 고른 뒤 한꺼번에 공개되고, 하이 1등과 로우 1등이 칩을 반씩 나눠요.', ]); } return withHand([`${m.declare ? `${SIDE_KO[m.declare]}(으)로 선언했어요. ` : ''}다른 사람이 선언할 때까지 기다려 주세요.`]); case 'reveal': if (m.canReveal) { return [ `다른 사람이 모두 포기해서 모인 칩 ${chips(v.pot)}은 내 거예요.`, '[카드 공개]를 누르면 모두에게 내 카드를 보여 주고, [공개 안 함]을 누르면 아무도 내 카드를 못 봐요. 시간이 지나면 공개하지 않아요.', ].join('\n'); } return `${watchText(v, players, me)}${away}`; default: return `${watchText(v, players, me)}${away}`; } }