hand.three를 (재)경기마다 두고 view.threeCard로 알림. 값이 없는 예전 상태는 방의 cardMode를 따름. 컴퓨터 판단·도움말·규칙 화면·문서도 맞춤, 엔진 테스트 2개 추가. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
188 lines
13 KiB
TypeScript
188 lines
13 KiB
TypeScript
/** 섯다 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view (never other players' cards). */
|
|
import type { BetType, SeotdaSeatView, SeotdaView } from '@bg/games/seotda';
|
|
import { formatWon } from '@bg/games/seotda/money';
|
|
import type { PublicUser } from '@bg/shared/lite';
|
|
|
|
/** Same order, labels and number keys as the bet buttons in board.tsx (한게임 섯다 배치). */
|
|
const BET_ORDER: BetType[] = ['call', 'die', 'half', 'ping', 'check', 'ddadang', 'quarter', 'full'];
|
|
const BET_KEY: Record<BetType, string> = { call: '7', die: '8', ping: '4', check: '5', ddadang: '1', half: '0', quarter: '2', full: '9' };
|
|
const BET_KO: Record<BetType, string> = { check: '체크', ping: '삥', call: '콜', ddadang: '따당', quarter: '쿼터', half: '하프', full: '풀', die: '다이' };
|
|
const RAISES: BetType[] = ['ping', 'ddadang', 'quarter', 'half', 'full'];
|
|
const STRENGTH_KO = { high: '센 패', mid: '중간 패', low: '약한 패' } as const;
|
|
const REMATCH_KO = { gusa: '구사', mungGusa: '멍텅구리구사', tie: '같은 족보(동점)' } as const;
|
|
const REASON_KO = { gusa: '구사', mungGusa: '멍텅구리구사', tie: '동점' } as const;
|
|
|
|
const won = (n: number) => formatWon(Math.max(0, n));
|
|
|
|
function who(players: Record<string, PublicUser>, id: string): string {
|
|
return `${players[id]?.nickname ?? '다른 사람'}님`;
|
|
}
|
|
|
|
/** Which betting round this is, in plain words. */
|
|
function roundText(v: SeotdaView): string {
|
|
const o = v.options;
|
|
if (o.cardMode === 'three' && !v.threeCard) return '재경기는 2장 섯다로 해요. 2장을 한 번에 받고 한 번만 베팅한 뒤 남은 사람끼리 패를 공개해요.';
|
|
if (o.cardMode === 'three')
|
|
return v.street === 0
|
|
? '2장을 받고 하는 첫 베팅이에요. 끝나면 1장을 더 받아 3장 중 쓸 2장을 골라요.'
|
|
: '고른 2장으로 하는 마지막 베팅이에요. 끝나면 남은 사람끼리 패를 공개해요.';
|
|
if (o.dealMode === 'oneRound') return '2장을 받고 한 번만 베팅해요. 끝나면 남은 사람끼리 패를 공개해요.';
|
|
return v.street === 0
|
|
? '1장을 받고 하는 첫 베팅이에요. 끝나면 1장을 더 받아요.'
|
|
: '2장째를 받고 하는 마지막 베팅이에요. 끝나면 남은 사람끼리 패를 공개해요.';
|
|
}
|
|
|
|
/** My current hand as the view gives it (hints option on). */
|
|
function handLine(v: SeotdaView, seat: SeotdaSeatView): string {
|
|
const h = v.myHand;
|
|
if (!h) return seat.cards.length > 0 ? "이 방은 족보 이름을 따로 보여 주지 않아요. 아래 '족보'판을 보고 내 패를 맞춰 보세요." : '';
|
|
if (h.special) return h.hint;
|
|
if (h.value === null) return `지금은 ${h.name}만 받았어요. ${h.hint}`;
|
|
return `지금 내 족보: ${h.name}${h.strength ? `(${STRENGTH_KO[h.strength]})` : ''}. 아래 족보판에 보라색으로 표시돼요.`;
|
|
}
|
|
|
|
function rematchLine(v: SeotdaView): string {
|
|
if (v.rematchNo === 0 || !v.rematchReason) return '';
|
|
return `재경기 ${v.rematchNo}회차(${REMATCH_KO[v.rematchReason]})예요. 판돈은 그대로 두고, 기본금은 다시 내지 않아요.${v.options.cardMode === 'three' ? ' 재경기는 2장 섯다로 해요(공개패 없음).' : ''}`;
|
|
}
|
|
|
|
function resultLine(v: SeotdaView, players: Record<string, PublicUser>): string {
|
|
if (v.foldWin) {
|
|
const name = v.seats.find((s) => s.id === v.foldWin!.winner)?.handName;
|
|
const shown = v.foldWin.shown ? `패를 공개했어요${name ? `(${name})` : ''}.` : '패는 공개하지 않았어요.';
|
|
return `모두 다이해서 ${who(players, v.foldWin.winner)}이 판돈 ${won(v.foldWin.amount)}을 가져갔어요. ${shown}`;
|
|
}
|
|
if (!v.showdown) return '이번 판이 끝났어요.';
|
|
return v.showdown.pots
|
|
.map((p) => {
|
|
const names = p.winners.map((id) => players[id]?.nickname ?? '다른 사람').join('·') + '님';
|
|
const name = v.showdown!.hands.find((h) => h.id === p.winners[0])?.name ?? '';
|
|
if (p.type === 'rematch') return `${REASON_KO[p.reason as keyof typeof REASON_KO] ?? '동점'} 재경기: ${names}이 다시 겨뤄요. 판돈은 그대로 남아요.`;
|
|
if (p.type === 'split') return `${names}이 ${won(p.amount)}을 나눠 가졌어요.`;
|
|
return `${names}이 ${name ? `${name}(으)로 ` : ''}${won(p.amount)}을 가져갔어요.`;
|
|
})
|
|
.join('\n');
|
|
}
|
|
|
|
function waitingLine(v: SeotdaView, players: Record<string, PublicUser>): string {
|
|
if (v.handPhase === 'betting') {
|
|
const oneRound = !v.threeCard && (v.options.cardMode === 'three' || v.options.dealMode === 'oneRound');
|
|
const round = oneRound ? '베팅' : v.street === 0 ? '첫 베팅' : '마지막 베팅';
|
|
return v.toAct ? `${who(players, v.toAct)} 차례예요(${round}).` : '카드를 나눠 주는 중이에요.';
|
|
}
|
|
if (v.handPhase === 'choose') return `모두 3장 중 쓸 2장을 몰래 고르는 중이에요. 다 고르면 ${v.street === 1 && v.options.threePick === 'end' ? '패를 공개해요' : '마지막 베팅을 해요'}.`;
|
|
if (v.handPhase === 'open') return '모두 받은 2장 중 모두에게 보여 줄 패 1장(공개패)을 고르는 중이에요. 다 고르면 첫 베팅을 해요.';
|
|
if (v.handPhase === 'rejoin') return '구사 재경기 전에, 다이했던 사람이 다시 들어올지 고르는 중이에요.';
|
|
if (v.handPhase === 'reveal' && v.reveal) return `모두 다이해서 혼자 남은 ${who(players, v.reveal.by)}이 카드 공개 여부를 고르는 중이에요.`;
|
|
if (v.handPhase === 'handEnd') return resultLine(v, players);
|
|
return '잠시만 기다려 주세요.';
|
|
}
|
|
|
|
/** Spectators, eliminated or left players: describe the table neutrally (no hidden cards). */
|
|
function watching(v: SeotdaView, players: Record<string, PublicUser>, prefix = ''): string {
|
|
if (v.phase === 'rebuy') {
|
|
const ids = v.rebuy?.pending ?? [];
|
|
const names = ids.length ? ids.map((id) => players[id]?.nickname ?? '다른 사람').join('·') + '님이' : '원을 모두 잃은 사람이';
|
|
return `${prefix}${names} 시작 금액을 다시 받을지 고르는 중이에요.`;
|
|
}
|
|
return [prefix + waitingLine(v, players), v.handPhase === 'betting' ? `판돈은 ${won(v.pot)}이에요.` : '', rematchLine(v)].filter(Boolean).join('\n');
|
|
}
|
|
|
|
function myBetting(v: SeotdaView, seat: SeotdaSeatView): string {
|
|
const legal = new Map(v.legal.map((l) => [l.type, l]));
|
|
const buttons = BET_ORDER.filter((t) => (t !== 'full' || v.options.maxRaise === 'full') && legal.has(t));
|
|
const lines = [`내 차례예요. ${roundText(v)}`];
|
|
const hand = handLine(v, seat);
|
|
if (hand) lines.push(hand);
|
|
lines.push(`누를 수 있는 버튼: ${buttons.map((t) => `[${BET_KO[t]}]`).join(' ')}. 버튼 아래 적힌 금액이 바로 판돈에 들어가요. PC에서는 버튼 왼쪽 위 숫자 키(${buttons.map((t) => `${BET_KO[t]} ${BET_KEY[t]}`).join(', ')})로도 걸 수 있어요.`);
|
|
const tips: string[] = [];
|
|
if (v.forcedHalf) tips.push(`이 방은 베팅 규칙 ${v.options.betRule}이라 첫 베팅에서 앞쪽 사람은 [하프]나 [다이]만 할 수 있어요.`);
|
|
const call = legal.get('call');
|
|
if (call) tips.push(`앞사람이 걸었어요. [콜]은 그만큼(${won(call.amount)}) 맞추는 거예요.`);
|
|
else if (legal.has('ping')) tips.push(`[체크]는 걸지 않고 넘기고, [삥]은 기본금만큼 ${won(v.baseUnit)}을 걸어요.`);
|
|
if (!buttons.some((t) => RAISES.includes(t)) && seat.lastAction) tips.push('이번 라운드에 이미 한 번 해서 더 올릴 수는 없어요(올리기는 한 라운드에 한 번).');
|
|
if (v.legal.some((l) => l.allIn)) tips.push('가진 금액이 모자라면 가진 만큼 다 내는 올인이 돼요.');
|
|
tips.push('패가 약하면 [다이]로 이번 판을 포기할 수 있어요.');
|
|
lines.push(tips.join(' '));
|
|
return lines.join('\n');
|
|
}
|
|
|
|
export function helpNow(v: SeotdaView, me: string | null, players: Record<string, PublicUser>): string {
|
|
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + "\n'최종 순위'에서 순위를 볼 수 있어요. 결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.";
|
|
const seat = me ? v.seats.find((s) => s.id === me) : undefined;
|
|
if (!seat) return watching(v, players);
|
|
if (seat.status === 'eliminated') return watching(v, players, '나는 탈락해서 구경만 할 수 있어요.\n');
|
|
if (seat.left) return watching(v, players, '게임에서 나갔어요.\n');
|
|
|
|
if (v.phase === 'rebuy') {
|
|
if (!v.rebuy?.mine) return watching(v, players) + ' 잠시 기다려 주세요.';
|
|
const left = v.rebuy.left !== null ? `(남은 횟수 ${v.rebuy.left}번)` : '';
|
|
return [
|
|
`가진 원을 모두 잃었어요. [다시 받기]를 누르면 놀이용 시작 금액 ${won(v.options.startingChips)}을 다시 받고 계속해요${left}.`,
|
|
'[그만하기]를 누르면 탈락하고 구경만 해요. 다시 받은 만큼 최종 점수에서 빠져요.',
|
|
'시간 안에 고르지 않으면 그만하는 것으로 처리돼요.',
|
|
].join('\n');
|
|
}
|
|
|
|
const notIn = v.rematchNo > 0 ? '이번 재경기에는 참가하지 않아요. 끝날 때까지 기다려 주세요.' : '이번 판에는 참가하지 않아요. 다음 판을 기다려 주세요.';
|
|
switch (v.handPhase) {
|
|
case 'betting': {
|
|
const re = rematchLine(v);
|
|
if (!seat.inHand) return [notIn, watching(v, players)].join('\n');
|
|
if (seat.folded) return `이번 판은 다이했어요. 다음 판을 기다려 주세요. 내 패는 나만 볼 수 있어요.\n${waitingLine(v, players)}`;
|
|
if (v.toAct === me) return [re, myBetting(v, seat)].filter(Boolean).join('\n');
|
|
const hand = handLine(v, seat);
|
|
if (seat.allIn) return ['올인했어요(가진 금액을 다 걸었어요). 더 걸지 않고 결과를 기다리면 돼요.', hand, re].filter(Boolean).join('\n');
|
|
return [`${waitingLine(v, players)} 내 차례가 올 때까지 기다려 주세요.`, hand, re].filter(Boolean).join('\n');
|
|
}
|
|
case 'choose': {
|
|
if (seat.chosen === null) return seat.folded ? '이번 판은 다이했어요. 다음 판을 기다려 주세요.' : [notIn, watching(v, players)].join('\n');
|
|
if (seat.chosen) {
|
|
const name = v.myHand ? `(${v.myHand.name})` : '';
|
|
return `쓸 패 2장을 골랐어요${name}. 다른 사람이 다 고를 때까지 기다려 주세요. 다 고르면 ${v.options.threePick === 'end' ? '패를 공개해요' : '마지막 베팅을 해요'}.`;
|
|
}
|
|
const lines = ["3장 중 쓸 패 2장을 눌러 고르면 아래 버튼이 '○○(으)로 정하기'로 바뀌어요. 그 버튼을 눌러 정해 주세요. 남는 1장은 아무에게도 보이지 않아요."];
|
|
const best = v.options.hints ? v.myCombos?.find((c) => c.best) : undefined;
|
|
if (best) lines.push(`조합 버튼을 누르면 그 2장이 골라져요. [${best.name} (추천)]이 가장 센 조합이에요.`);
|
|
lines.push('모두 동시에 몰래 고르고, 시간이 지나면 가장 센 조합으로 저절로 골라져요.');
|
|
return lines.join('\n');
|
|
}
|
|
case 'open': {
|
|
if (seat.opening === null) return seat.folded ? '이번 판은 다이했어요. 다음 판을 기다려 주세요.' : [notIn, watching(v, players)].join('\n');
|
|
if (seat.opening) return '공개패를 골랐어요. 다른 사람이 다 고르면 첫 베팅을 해요.';
|
|
return [
|
|
'받은 2장 중 모두에게 보여 줄 패 1장을 눌러 고르고 [○월 패 공개하기]를 눌러 주세요.',
|
|
'센 패(광, 같은 월)는 숨기고 평범한 패를 보여 주면 상대가 내 패를 짐작하기 어려워요.',
|
|
'시간이 지나면 낮은 월의 패가 저절로 공개돼요.',
|
|
].join('\n');
|
|
}
|
|
case 'reveal': {
|
|
if (!v.reveal?.mine) return `${waitingLine(v, players)} 잠시 기다려 주세요.`;
|
|
return [
|
|
`다른 사람이 모두 다이해서 판돈 ${won(v.pot)}은 내 거예요.`,
|
|
'[카드 공개]를 누르면 모두에게 내 패를 보여 주고, [공개 안 함]을 누르면 아무도 내 패를 못 봐요.',
|
|
'시간이 지나면 공개하지 않는 것으로 처리돼요.',
|
|
].join('\n');
|
|
}
|
|
case 'rejoin': {
|
|
if (!v.rejoin?.mine) return `${waitingLine(v, players)} 잠시 기다려 주세요.`;
|
|
const cost = won(v.rejoin.cost);
|
|
return [
|
|
`구사 재경기가 열려요. 다이했던 나도 판돈에 ${cost}을 더 내면 다시 들어갈 수 있어요.`,
|
|
v.rejoin.canAfford ? `[${cost} 내고 참가] 또는 [참가 안 함]을 눌러 주세요.` : '보유 금액이 모자라서 참가할 수 없어요. [참가 안 함]을 눌러 주세요.',
|
|
'시간이 지나면 참가하지 않는 것으로 처리돼요.',
|
|
].join('\n');
|
|
}
|
|
case 'handEnd': {
|
|
const lines = [resultLine(v, players)];
|
|
if (seat.status === 'playing') {
|
|
const label = v.next === 'rematch' ? '재경기 시작' : '다음 판으로';
|
|
lines.push(seat.ready ? '다른 사람을 기다리는 중이에요.' : `[${label}] 버튼을 누르거나 잠시 기다리면 넘어가요.`);
|
|
}
|
|
return lines.join('\n');
|
|
}
|
|
default:
|
|
return '잠시만 기다려 주세요.';
|
|
}
|
|
}
|