diff --git a/apps/web/src/games/poker/help.test.ts b/apps/web/src/games/poker/help.test.ts index aac1b74..c4cea3c 100644 --- a/apps/web/src/games/poker/help.test.ts +++ b/apps/web/src/games/poker/help.test.ts @@ -82,10 +82,16 @@ test('텍사스 홀덤: 노리밋 버튼과 공용 카드, 모두 포기하면 const flop = drive(state, (x) => x.handPhase === 'betting' && x.board.length === 3); expect(help(flop, null)).toContain('가운데 공용 카드 3장이 펼쳐져 있어요'); - const s = applyAction('poker', state, turn, { type: 'nl.fold' }); + const r = applyAction('poker', state, turn, { type: 'nl.fold' }); + expect(view(r, null).handPhase).toBe('reveal'); + expect(help(r, other)).toContain('[카드 공개]'); + expect(help(r, turn)).toContain(`혼자 남은 ${nickOf(other)}이 카드 공개 여부를 고르는 중이에요`); + const shown = applyAction('poker', r, other, { type: 'reveal', show: true }); + expect(help(shown, turn)).toContain('패를 공개했어요('); + const s = applyAction('poker', r, other, { type: 'reveal', show: false }); expect(view(s, null).handPhase).toBe('handEnd'); const w = help(s, other); - expect(w).toContain('다른 사람이 모두 포기해서 내가 모인 칩을 가져갔어요'); + expect(w).toContain('다른 사람이 모두 포기해서 내가 모인 칩을 가져갔어요. 패는 공개하지 않았어요.'); expect(w).toContain('[다음 판으로]'); expect(help(s, null)).toContain(`${nickOf(other)}이 모인 칩을 가져갔어요`); }); diff --git a/apps/web/src/games/poker/help.ts b/apps/web/src/games/poker/help.ts index 10d0d51..9277758 100644 --- a/apps/web/src/games/poker/help.ts +++ b/apps/web/src/games/poker/help.ts @@ -149,6 +149,8 @@ function watchText(v: PokerView, players: Record, me: string return `모두 동시에 바꿀 카드를 고르는 중이에요(${drawName(v)}). 버린 카드는 공개되지 않고, 바꾼 장수만 각 자리에 보여요.${waiting}`; case 'declare': return `남은 사람들이 하이·로우·스윙 중 하나를 몰래 고르는 중이에요. 모두 고르면 한꺼번에 공개돼요.${waiting}`; + case 'reveal': + return `다른 사람이 모두 포기해서 혼자 남은 ${nickOf(players, v.waiting[0])}이 카드 공개 여부를 고르는 중이에요.`; default: return '카드를 나눠 주는 중이에요. 잠시만 기다려 주세요.'; } @@ -161,7 +163,8 @@ function handEndText(v: PokerView, players: Record, me: stri 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) { - lines.push(`다른 사람이 모두 포기해서 ${who(v.winners[0]!)} 모인 칩을 가져갔어요. 이럴 때는 패를 공개하지 않아요.`); + 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}(으)로 ` : ''}이겼어요.`); @@ -245,6 +248,14 @@ export function helpNow(v: PokerView, me: string | null, players: Record )} + {!sd && v.foldShown?.id === seat.id && {v.foldShown.handName}} {sd && ( {sd.handName} @@ -458,6 +460,16 @@ function usePokerFx(v: PokerView, me: string | null, players: Record x.id === fs.id); + const els = seatCardEls(fs.id); + const off = s?.forehead !== undefined ? 1 : 0; + for (let i = 0; i < (s?.hole.length ?? 0); i++) turnOver(els[off + i], t + i * 60); + later(t + 120, sfx.cardFlip); + t += 400; + } // 인디언: my own forehead card is shown at the end of the hand. const myNow = v.seats.find((s) => s.id === me); const myBefore = p.seats.find((s) => s.id === me); @@ -566,7 +578,7 @@ function resultLine(v: PokerView, players: Record): string { for (const a of v.awards) if (a.side !== 'refund') won.set(a.to, (won.get(a.to) ?? 0) + a.amount); if (!won.size) return v.carryOver > 0 ? `동점이라 ${formatChips(v.carryOver)}이 다음 판으로 넘어가요` : '이번 판은 칩을 모두 돌려받았어요'; const parts = [...won].map(([id, amt]) => { - const name = v.showdown?.find((e) => e.id === id)?.handName; + const name = v.showdown?.find((e) => e.id === id)?.handName ?? (v.foldShown?.id === id ? v.foldShown.handName : undefined); return `${nick(players, id)}님이 ${name ? `${name}(으)로 ` : ''}${formatChips(amt)}을 가져갔어요`; }); return parts.join(' / ') + (v.foldWin ? ' (모두 포기)' : ''); @@ -577,7 +589,11 @@ function ResultPanel({ v, players }: { v: PokerView; players: Record 이번 판 결과 - {v.foldWin && 한 명만 남아서 패는 공개하지 않아요.} + {v.foldWin && ( + + {v.foldShown ? `한 명만 남았고, ${nick(players, v.foldShown.id)}님이 패를 공개했어요(${v.foldShown.handName}).` : '한 명만 남았고, 패는 공개하지 않았어요.'} + + )} {v.awards.map((a, i) => { const sd = v.showdown?.find((e) => e.id === a.to); const hand = !sd ? '' : a.side === 'low' ? (sd.lowName ? `로우 ${sd.lowName}` : '') : !a.side || a.side === 'high' || a.side === 'scoop' ? sd.handName : ''; @@ -639,6 +655,12 @@ function MyArea({ v, me, players, act, pending }: AreaProps) { )} )} + {m.canReveal && } + {v.handPhase === 'reveal' && !m.canReveal && v.waiting[0] && ( +

+ {nick(players, v.waiting[0])}님이 카드 공개 여부를 고르는 중이에요. +

+ )} {seat.inHand && v.handPhase === 'betting' && !seat.folded && !seat.allIn && } {v.handPhase === 'handEnd' && } {m.canReady && ( @@ -651,6 +673,25 @@ function MyArea({ v, me, players, act, pending }: AreaProps) { ); } +/** Everyone else folded: show my cards to everyone, or keep them hidden (the default when time runs out). */ +function RevealBox({ v, act, pending }: { v: PokerView; act: (a: unknown) => void; pending: boolean }) { + return ( +
+

+ 모두 포기해서 모인 칩 {formatChips(v.pot)}은 내 거예요. 내 카드를 모두에게 보여 줄까요? 시간이 지나면 공개하지 않아요. +

+
+ + +
+
+ ); +} + function MyCards({ v, seat }: { v: PokerView; seat: SeatView }) { const sd = v.showdown?.find((e) => e.id === seat.id); const best = new Set(sd?.best ?? []); @@ -1094,6 +1135,8 @@ function statusText(v: PokerView, me: string | null, players: Record +

+ 혼자 남으면: 다른 사람이 모두 포기하면 남은 한 명이 모인 칩을 가져가요.{' '} + {mode === 'indian' + ? '인디언 포커는 판이 끝나면 모든 카드가 공개돼요.' + : '이때 남은 사람이 카드를 모두에게 보여 줄지([카드 공개]) 숨길지([공개 안 함]) 골라요. 시간이 지나면 공개하지 않아요.'} +

족보

diff --git a/apps/web/src/games/seotda/board.tsx b/apps/web/src/games/seotda/board.tsx index 4ef9c09..4a329c9 100644 --- a/apps/web/src/games/seotda/board.tsx +++ b/apps/web/src/games/seotda/board.tsx @@ -58,6 +58,7 @@ export const isCard = (c: CardSlot): c is SeotdaCardView => !('hidden' in c); export function totalMsOf(v: SeotdaView): number { const o = v.options; if (v.phase === 'rebuy' || v.handPhase === 'rejoin') return o.decisionSeconds * 1000; + if (v.handPhase === 'reveal') return v.seats.find((s) => s.id === v.reveal?.by)?.away ? 5000 : o.decisionSeconds * 1000; if (v.handPhase === 'handEnd') return 5000; if (o.turnSeconds === null) return 0; if (v.handPhase === 'choose' || v.handPhase === 'open') return (o.turnSeconds + 10) * 1000; @@ -227,7 +228,8 @@ function Seat({ seat, view: v, players, me, deadline, pos, cardW, winner, setRef if (seat.chosen === true) tags.push(['고름', '#15803d']); if (seat.chosen === false) tags.push(['고르는 중', '#475569']); if (seat.opening === false) tags.push(['공개패 고르는 중', '#475569']); - const timed = seat.isTurn || seat.chosen === false || seat.opening === false; + if (v.reveal?.by === seat.id) tags.push(['카드 공개 고르는 중', '#475569']); + const timed = seat.isTurn || seat.chosen === false || seat.opening === false || v.reveal?.by === seat.id; const style = pos ? ({ '--x': `${pos.x}%`, '--y': `${pos.y}%` } as CSSProperties) : undefined; return (
)} - {(seat.isTurn || seat.chosen === false || seat.opening === false) && } + {(seat.isTurn || seat.chosen === false || seat.opening === false || !!v.reveal?.mine) && }
{formatWon(seat.stack)} @@ -440,7 +442,7 @@ function useTableEffects(v: SeotdaView, me: string | null, tableRef: React.RefOb }); // Result: reveal, payout, banner. if (v.handPhase === 'handEnd' && prev.phase !== 'handEnd') { - if (v.showdown) sfx.cardFlip(); + if (v.showdown || v.foldWin?.shown) sfx.cardFlip(); const winners = new Set(); if (v.foldWin) winners.add(v.foldWin.winner); for (const p of v.showdown?.pots ?? []) if (p.type !== 'rematch') for (const w of p.winners) winners.add(w); @@ -574,6 +576,25 @@ function OpenBox({ view: v, me, act, pending }: { view: SeotdaView; me: string; ); } +/** Everyone else died: show my cards to everyone, or keep them hidden (the default when time runs out). */ +function RevealBox({ view: v, act, pending }: { view: SeotdaView; act: (a: unknown) => void; pending: boolean }) { + return ( +
+

+ 모두 다이해서 판돈 {formatWon(v.pot)}은 내 거예요. 내 패를 모두에게 보여 줄까요? 시간이 지나면 공개하지 않아요. +

+
+ + +
+
+ ); +} + function ChooseBox({ view: v, me, act, pending }: { view: SeotdaView; me: string; act: (a: unknown) => void; pending: boolean }) { const seat = v.seats.find((s) => s.id === me)!; const [pick, setPick] = useState([]); @@ -609,7 +630,7 @@ function ChooseBox({ view: v, me, act, pending }: { view: SeotdaView; me: string } export function resultLine(v: SeotdaView, players: Record): string { - if (v.foldWin) return `${nick(players, v.foldWin.winner)}님이 판돈 ${formatWon(v.foldWin.amount)}을 가져갔어요(모두 다이).`; + if (v.foldWin) return `${nick(players, v.foldWin.winner)}님이 판돈 ${formatWon(v.foldWin.amount)}을 가져갔어요(모두 다이${v.foldWin.shown ? ' · 패 공개' : ''}).`; if (!v.showdown) return ''; return v.showdown.pots .map((p) => { @@ -623,12 +644,14 @@ export function resultLine(v: SeotdaView, players: Record): } function ResultPanel({ view: v, players }: { view: SeotdaView; players: Record }) { + const foldName = v.foldWin ? v.seats.find((s) => s.id === v.foldWin!.winner)?.handName : null; return (
{v.next === 'rematch' ? '재경기가 정해졌어요' : '이번 판 결과'} {v.foldWin && ( - {nick(players, v.foldWin.winner)}님이 판돈 {formatWon(v.foldWin.amount)}을 가져갔어요. 모두 다이해서 패는 공개하지 않아요. + {nick(players, v.foldWin.winner)}님이 판돈 {formatWon(v.foldWin.amount)}을 가져갔어요.{' '} + {v.foldWin.shown ? `모두 다이했고, 패를 공개했어요${foldName ? `(${foldName})` : ''}.` : '모두 다이했고, 패는 공개하지 않았어요.'} )} {v.showdown?.pots.map((p, i) => { @@ -735,6 +758,8 @@ export function SeotdaBoard({ view: v, me, players, act, pending, deadline }: Bo
{mySeat && v.handPhase === 'open' && mySeat.opening === false && } {mySeat && v.handPhase === 'open' && mySeat.opening === true &&

공개패를 골랐어요. 다른 사람을 기다리는 중이에요.

} + {v.reveal?.mine && } + {v.reveal && !v.reveal.mine &&

{nick(players, v.reveal.by)}님이 카드 공개 여부를 고르는 중이에요.

} {mySeat && v.handPhase === 'choose' && mySeat.chosen === false && } {mySeat && v.handPhase === 'choose' && mySeat.chosen === true &&

골랐어요. 다른 사람이 고르기를 기다리는 중이에요.

} {mySeat && mySeat.inHand && v.handPhase === 'betting' && !mySeat.folded && } diff --git a/apps/web/src/games/seotda/help.test.ts b/apps/web/src/games/seotda/help.test.ts index d2aeb24..cf187ab 100644 --- a/apps/web/src/games/seotda/help.test.ts +++ b/apps/web/src/games/seotda/help.test.ts @@ -96,10 +96,19 @@ test('섯다: 모두 다이 → 판 결과와 [다음 판으로], 다이한 사 state = applyAction('seotda', state, first, { type: 'die' }); expect(helpNow(view(state, first), first, users)).toContain('이번 판은 다이했어요'); state = applyAction('seotda', state, view(state, null).toAct, { type: 'die' }); - expect(view(state, null).handPhase).toBe('handEnd'); - const t = helpNow(view(state, 'A'), 'A', users); + expect(view(state, null).handPhase).toBe('reveal'); + const winner = view(state, null).reveal.by as string; + const loser = ['A', 'B', 'C'].find((p) => p !== winner)!; + expect(helpNow(view(state, winner), winner, users)).toContain('[카드 공개]'); + expect(helpNow(view(state, loser), loser, users)).toContain('카드 공개 여부를 고르는 중'); + const hidden = applyAction('seotda', state, winner, { type: 'reveal', show: false }); + expect(view(hidden, null).handPhase).toBe('handEnd'); + const t = helpNow(view(hidden, 'A'), 'A', users); expect(t).toContain('모두 다이해서'); + expect(t).toContain('패는 공개하지 않았어요'); expect(t).toContain('[다음 판으로]'); + const shown = applyAction('seotda', state, winner, { type: 'reveal', show: true }); + expect(helpNow(view(shown, loser), loser, users)).toContain('패를 공개했어요('); }); test('섯다: 시작 금액 다시 받기 / 구사 재경기 참가 / 재경기 표시', () => { diff --git a/apps/web/src/games/seotda/help.ts b/apps/web/src/games/seotda/help.ts index 88a02da..a5ef9a8 100644 --- a/apps/web/src/games/seotda/help.ts +++ b/apps/web/src/games/seotda/help.ts @@ -46,7 +46,11 @@ function rematchLine(v: SeotdaView): string { } function resultLine(v: SeotdaView, players: Record): string { - if (v.foldWin) return `모두 다이해서 ${who(players, v.foldWin.winner)}이 판돈 ${won(v.foldWin.amount)}을 가져갔어요. 이때는 패를 공개하지 않아요.`; + 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) => { @@ -68,6 +72,7 @@ function waitingLine(v: SeotdaView, players: Record): string 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 '잠시만 기다려 주세요.'; } @@ -150,6 +155,14 @@ export function helpNow(v: SeotdaView, me: string | null, players: Record{' '} {r.how === 'rematch' ? `재경기로 넘어감 ${formatWon(r.amount)}` - : `${r.winners.map((id) => nick(players, id)).join('·')} ${formatWon(r.amount)}${r.name ? ` · ${r.name}` : ''}${r.how === 'fold' ? ' · 모두 다이' : r.how === 'ttaengjabi' ? ' · 땡잡이' : r.how === 'amhaeng' ? ' · 암행어사' : r.how === 'limit' ? ' · 나눔' : r.how === 'tie' ? ' · 같은 족보 나눔' : ''}`} + : `${r.winners.map((id) => nick(players, id)).join('·')} ${formatWon(r.amount)}${r.name ? ` · ${r.name}` : ''}${r.how === 'fold' ? (r.shown ? ' · 모두 다이 · 패 공개' : ' · 모두 다이') : r.how === 'ttaengjabi' ? ' · 땡잡이' : r.how === 'amhaeng' ? ' · 암행어사' : r.how === 'limit' ? ' · 나눔' : r.how === 'tie' ? ' · 같은 족보 나눔' : ''}`} ))} @@ -255,6 +255,7 @@ function isMyTurn(v: SeotdaView, me: string | null): boolean { if (v.handPhase === 'choose') return v.seats.find((s) => s.id === me)?.chosen === false; if (v.handPhase === 'open') return v.seats.find((s) => s.id === me)?.opening === false; if (v.handPhase === 'rejoin') return !!v.rejoin?.mine; + if (v.handPhase === 'reveal') return !!v.reveal?.mine; return false; } @@ -269,6 +270,8 @@ function statusText(v: SeotdaView, me: string | null, players: Record) { set({ maxRematches })} /> - + set({ decisionSeconds })} /> @@ -450,7 +453,7 @@ function Rules({ options }: { options?: SeotdaOptions }) { : o?.dealMode === 'twoRounds' ? ' 1장 받고 베팅, 1장 더 받고 베팅한 뒤 남은 사람끼리 패를 공개해요.' : ' 2장을 한 번에 받고 한 번 베팅한 뒤 남은 사람끼리 패를 공개해요.'}{' '} - 모두 다이하고 한 명만 남으면 그 사람이 패를 보여 주지 않고 판돈을 가져가요. + 모두 다이하고 한 명만 남으면 그 사람이 판돈을 가져가요. 이때 남은 사람이 패를 모두에게 보여 줄지([카드 공개]) 숨길지([공개 안 함]) 골라요. 시간이 지나면 공개하지 않아요.

베팅(괄호는 숫자 키): 콜(7) 앞사람만큼, 다이(8) 포기, 삥(4) 기본금만큼, 체크(5) 안 걸고 넘김, 따당(1) 앞사람이 건 돈의 두 배, 하프(0) 맞춘 뒤 판돈의 절반을 더 diff --git a/docs/games/poker.md b/docs/games/poker.md index f043638..88f0066 100644 --- a/docs/games/poker.md +++ b/docs/games/poker.md @@ -93,7 +93,7 @@ - 블라인드형(홀덤·오마하): 딜러 다음 좌석 SB(`floor(baseUnit/2)`, 최소 1), 그다음 BB(`baseUnit`). 2인(헤즈업)일 때는 딜러가 SB, 상대가 BB. - 칩이 강제 베팅보다 적으면 가진 칩을 전부 내고 올인 상태가 된다. 5. 모드별 카드 분배와 베팅 라운드(5.4) 진행. -6. 베팅 도중 한 명만 남으면 그 사람이 모든 팟을 가져가고 카드는 공개하지 않는다. +6. 베팅 도중 한 명만 남으면 그 사람이 모든 팟을 가져간다. 그 전에 남은 사람이 카드를 모두에게 공개할지 고른다(`phase=reveal`, `reveal { show }`, 2026-10-14). 공개하면 숨긴 카드가 모두에게 보이고(7포커 초이스에서 버린 카드는 계속 비밀) 족보 이름과 "패를 공개했어요" 기록이 남는다. 시간 초과·방 나감은 공개 안 함. 인디언 포커는 판이 끝나면 어차피 모두 공개라 묻지 않고, 다른 사람이 모두 나가 볼 사람이 없을 때도 묻지 않는다. 7. 마지막 라운드 후 2명 이상 남으면 쇼다운(6장) → 팟 분배. 8. 핸드 종료 단계(`handEnd`): 결과를 4초간 보여 준다. 참가자는 "다음 판" 버튼으로 준비 완료할 수 있고, 전원 준비 또는 시간 초과 시 다음 단계로. 9. 칩 0이 된 플레이어 처리(5.6 리바이·탈락), 종료 조건 확인(6.7), 아니면 다음 핸드. @@ -458,7 +458,7 @@ interface Award { potIndex: number; to: PlayerId; amount: number; side?: 'high' interface HandState { handNo: number; - phase: 'choice' | 'betting' | 'draw' | 'declare' | 'showdown' | 'handEnd'; + phase: 'choice' | 'betting' | 'draw' | 'declare' | 'reveal' | 'showdown' | 'handEnd'; street: number; dealerSeat: number; deck: Card[]; // 남은 덱(절대 클라이언트로 안 나감) @@ -515,6 +515,7 @@ interface PokerState { | `nl.allIn` | - | NL/PL, 내 차례 | 스택 > 0. PL에서 스택이 팟리밋보다 크면 거부(최대 레이즈로 안내) | | `draw` | `{ cardIds: number[] }` | 바둑이/드로우, `phase=draw`, 미제출 참가자(동시, 올인 포함) | 중복 없음, 모두 내 손패, 개수: 바둑이 0~4, 드로우 `any` 0~5 / `three` 0~3(A를 남기면 0~4) | | `declare` | `{ side: 'high'\|'low'\|'swing' }` | 하이로우, `phase=declare`, 남은 참가자(동시) | 미선언 | +| `reveal` | `{ show: boolean }` | `phase=reveal`, 혼자 남은 사람 | 항상 | | `ready` | - | `phase=handEnd`, 참가자 | 아직 준비 안 함 | | `rebuy` | `{ accept: boolean }` | `phase=rebuy`, `rebuyPending`에 있는 사람 | 남은 리바이 횟수 > 0 | | `leave` | - | 아무 때나(서버가 방 퇴장 시 주입) | 이미 `left` 아님 | @@ -558,6 +559,7 @@ interface PokerState { `deadline(state)`: - 베팅: `turnSeconds`(자리 비움이면 5초). 무제한(`null`)이면 시계 없음(자리 비움만 짧은 시계). 연결이 끊긴 사람은 방의 유예 시간 뒤 자동 행동. - 7포커 초이스·교환·선언: `turnSeconds + 10`초(동시 단계, 모두에게 같은 마감). 무제한이면 마감 없음(기다리는 사람이 모두 자리 비움일 때만 짧은 시계). +- 혼자 남은 사람의 카드 공개 선택: 베팅과 같은 시계(`turnSeconds`, 자리 비움이면 짧은 시계, 무제한이면 마감 없음). - `handEnd`: 4초. 리바이 결정: 15초. `onTimeout(state, player)`: @@ -570,6 +572,7 @@ interface PokerState { | 바둑이 교환 | 패를 바꾸지 않음(패스) | | 드로우 교환 | 패스 | | 하이로우 선언 | 하이 | +| 카드 공개(혼자 남음) | `{ show: false }`(자리 비움 횟수에 넣지 않음) | | `handEnd` | `ready` | | 리바이 | `{ accept: false }` | diff --git a/docs/games/seotda.md b/docs/games/seotda.md index f860b5c..f9cdb92 100644 --- a/docs/games/seotda.md +++ b/docs/games/seotda.md @@ -87,7 +87,7 @@ 5. 남은 사람에게 1장씩 더 나눠 준다(비공개). 6. 2차 베팅(선이 다이했으면 선 다음 좌석의 남은 사람부터). 7. 2명 이상 남으면 쇼다운: 남은 사람의 패를 동시에 공개하고 6장 규칙으로 판정. -8. 도중에 1명만 남으면 그 사람이 판돈을 가져가고 패는 공개하지 않는다. +8. 도중에 1명만 남으면 그 사람이 판돈을 가져간다. 그 전에 남은 사람이 패를 모두에게 공개할지 고른다(`phase=reveal`, `reveal { show }`, 2026-10-14). 공개하면 모든 사람·관전자 화면에 그 패(3장 섯다는 고른 2장, 아직 안 골랐으면 손패 전부)와 족보 이름이 보이고 판 기록에 "패 공개"가 남는다. 시간 초과(`decisionSeconds`, 자리 비움이면 5초)·방 나감·컴퓨터 기본값은 공개 안 함. 다른 사람이 모두 나가 볼 사람이 없으면 묻지 않고 공개하지 않는다. 9. 판 종료 결과를 5초간 보여 준 뒤 다음 판(리바이·탈락·종료 확인 포함). `dealMode=oneRound`(기본): 3~6 대신 2장을 한 번에 나눠 주고 베팅 1회 후 쇼다운. @@ -100,7 +100,7 @@ 3. 1구 베팅(선부터). 4. 남은 사람에게 1장 더(비공개, 손에 3장). 5. 2구 베팅. -6. 2명 이상 남으면 최종 패 고르기(동시 진행): 각자 3장 중 2장을 고른다. 시간이 지나면 가장 센 조합. 2구 베팅에서 한 사람만 남으면 고르지 않고 끝난다. +6. 2명 이상 남으면 최종 패 고르기(동시 진행): 각자 3장 중 2장을 고른다. 시간이 지나면 가장 센 조합. 2구 베팅에서 한 사람만 남으면 고르지 않고 끝난다(카드 공개를 고르면 손패 3장을 모두 보여 준다). 7. 쇼다운(고른 2장으로 판정). 버린 1장은 공개패가 아니면 끝까지 아무에게도 보이지 않는다(공개패를 버리면 다른 사람 화면에서 그 패가 빠진다). 옵션: `threeOpen=끔`이면 2단계가 없다. `threePick=beforeBet`이면 4단계 직후에 2장을 고르고(뒷면 2장만 남김) 그다음 마지막 베팅 → 쇼다운(2026-10-13 이전의 3장 섯다 흐름). 진행 중이던 방(상태 버전 2)은 버전 3으로 옮길 때 예전 흐름(공개패 없음, 베팅 전 고르기)을 그대로 쓴다. @@ -355,7 +355,7 @@ type SpecialKind = 'ttaengjabi' | 'amhaeng' | 'gusa' | 'mungGusa'; interface SeotdaHand { handNo: number; // 재경기는 같은 handNo rematchNo: number; // 0 = 본 판, 1..3 = 재경기 차수 - phase: 'dealing' | 'open' | 'betting' | 'choose' | 'rejoin' | 'showdown' | 'handEnd'; + phase: 'dealing' | 'open' | 'betting' | 'choose' | 'reveal' | 'rejoin' | 'showdown' | 'handEnd'; opened: Record; // 3장 섯다 공개패 dealerSeat: number; // 선 deck: HwatuCard[]; // 남은 덱(비공개) @@ -401,6 +401,7 @@ interface SeotdaState { | `open` | `{ cardId: number }` | `phase=open`(3장 섯다 공개패), 남은 참가자(동시) | 내 손패 2장 중 하나, 아직 미공개. 시간 초과·나감 = 낮은 월 | | `choose` | `{ cardIds: [number, number] }` | `phase=choose`(3장 섯다), 남은 참가자(동시, 올인 포함) | 두 id가 내 손패에 있고 서로 다름, 아직 미선택 | | `rejoin` | `{ accept: boolean }` | `phase=rejoin`, `rejoinPending`에 있는 사람 | `accept=true`면 스택 ≥ 재참가 비용 | +| `reveal` | `{ show: boolean }` | `phase=reveal`, 혼자 남은 사람 | 항상 | | `ready` | - | `phase=handEnd` | 미준비 | | `rebuy` | `{ accept: boolean }` | `phase=rebuy`, 대상자 | 남은 리바이 횟수 > 0 | | `leave` | - | 서버가 퇴장 시 주입 | - | @@ -432,13 +433,14 @@ interface SeotdaState { ### 8.5 타이머·시간 초과·연결 끊김 시 자동 행동 -`deadline`: 베팅 `turnSeconds`(자리 비움 5초), 3장 선택 `turnSeconds + 10`초(동시), 재참가 15초, `handEnd` 5초, 리바이 15초. `turnSeconds=null`(무제한)이면 베팅·3장 선택에는 마감이 없다(자리 비움도 생기지 않음). 재참가·리바이·판 결과 화면은 그대로 시간이 흐른다. +`deadline`: 베팅 `turnSeconds`(자리 비움 5초), 3장 선택 `turnSeconds + 10`초(동시), 재참가·카드 공개 `decisionSeconds`(기본 15초, 카드 공개는 자리 비움이면 5초), `handEnd` 5초, 리바이 15초. `turnSeconds=null`(무제한)이면 베팅·3장 선택에는 마감이 없다(자리 비움도 생기지 않음). 재참가·리바이·판 결과 화면은 그대로 시간이 흐른다. | 단계 | `onTimeout` 자동 행동 | |---|---| | 베팅 | `opened=false`면 `check`, 아니면 `die` | | 3장 선택 | 일반값이 가장 높은 2장 조합. 같으면 특수패(땡잡이·암행어사·구사) 조합, 그것도 같으면 카드 id 합이 작은 조합 | | 재참가 | `{ accept: false }` | +| 카드 공개(혼자 남음) | `{ show: false }`(자리 비움 횟수에 넣지 않음) | | `handEnd` | `ready` | | 리바이 | `{ accept: false }` | diff --git a/packages/games/src/poker/bot.test.ts b/packages/games/src/poker/bot.test.ts index 9ab680d..2ef604c 100644 --- a/packages/games/src/poker/bot.test.ts +++ b/packages/games/src/poker/bot.test.ts @@ -32,6 +32,21 @@ describe('poker bot', () => { expect(decide(s, 'A', 0.9).type).toBe('nl.fold'); }); + test('everyone else folded: shows a monster now and then, never a weak hand', () => { + const lone = (deck: string) => { + let s = mk({ mode: 'holdem', baseUnit: 10 }, 3, deckOf(deck)); + s = act(s, 'C', { type: 'nl.fold' }); + s = act(s, 'A', { type: 'nl.fold' }); + expect(s.hand!.phase).toBe('reveal'); + return s; + }; + const weak = lone('7D 3S AS 2C 8H AH'); // B: 3♠ 8♥ + for (const r of [0.05, 0.5, 0.95]) expect(decide(weak, 'B', r)).toEqual({ type: 'reveal', show: false }); + const aces = lone('7D AS 9S 2C AH 9H'); // B: A♠ A♥ + expect(decide(aces, 'B', 0.1)).toEqual({ type: 'reveal', show: true }); + expect(decide(aces, 'B', 0.9)).toEqual({ type: 'reveal', show: false }); + }); + test('7포커 초이스: keeps the pair and opens the other card', () => { // order A B C, four cards each round-robin → A: K♠ 2♣ 9♦ K♥. const s = mk({ mode: 'sevenPoker' }, 3, deckOf('KS 3C 4D 2C 5S 6H 9D 7C 8S KH TC JD')); diff --git a/packages/games/src/poker/bot.ts b/packages/games/src/poker/bot.ts index a676175..fbe01bb 100644 --- a/packages/games/src/poker/bot.ts +++ b/packages/games/src/poker/bot.ts @@ -224,6 +224,8 @@ export const pokerBot: BotStrategy = ({ me, view, legal, return top; } const { s, low } = strength(view, seat); + // Everyone else folded: usually keep the cards hidden; now and then show off a strong hand. + if (t === 'reveal') return { type: 'reveal', show: s >= 0.8 && random() < 0.5 }; if (t === 'declare') { const high = korStrength(bestKorean([...known(seat.hole), ...known(seat.up)])); const side = low?.made && high >= 0.84 && low.s >= 0.75 ? 'swing' : low?.made && low.s > high ? 'low' : 'high'; diff --git a/packages/games/src/poker/hand.ts b/packages/games/src/poker/hand.ts index 9123b30..a1676a8 100644 --- a/packages/games/src/poker/hand.ts +++ b/packages/games/src/poker/hand.ts @@ -194,7 +194,7 @@ export function advance(s: PokerState, ctx: Ctx): void { const plan = planFor(s.options); for (let guard = 0; guard < 64; guard++) { const h = s.hand!; - if (h.settled) return; + if (h.settled || h.phase === 'reveal') return; if (handDecided(h.bet)) return settleFold(s, ctx); if (h.waiting) { if (!stepComplete(h, plan[h.step]!)) return; @@ -448,6 +448,29 @@ function settleFold(s: PokerState, ctx: Ctx): void { const h = s.hand!; h.bet = returnUncalled(h.bet).state; const cs = contenderIds(h); + // One player left with hidden cards and someone still at the table: they decide whether to show the cards first + // (인디언 shows every card at the end anyway). + const watched = s.seats.some((x) => x.id !== cs[0] && x.status !== 'left' && x.status !== 'eliminated'); + if (cs.length === 1 && watched && s.options.mode !== 'indian' && h.players[cs[0]!]!.hole.length > 0) { + h.phase = 'reveal'; + h.waiting = true; + return; + } + payFold(s, ctx); +} + +/** The last player's answer in the reveal phase, then the payout. */ +export function decideReveal(s: PokerState, ctx: Ctx, show: boolean): void { + const h = s.hand!; + const w = contenderIds(h)[0]!; + h.foldShown = show; + log(s, w, show ? `패를 공개했어요 · ${evaluate(s.options, h.players[w]!, h.board).high.name}` : '패를 공개하지 않았어요'); + payFold(s, ctx); +} + +function payFold(s: PokerState, ctx: Ctx): void { + const h = s.hand!; + const cs = contenderIds(h); const total = potTotal(h.bet); const penalty = h.penalties.reduce((a, p) => a + p.amount, 0); h.potTotal = total + s.carryOver + penalty; @@ -725,6 +748,8 @@ export function waitingFor(s: PokerState): PlayerId[] { return cs.filter((id) => h.players[id]!.drawPending === null); case 'declare': return cs.filter((id) => !h.players[id]!.declare); + case 'reveal': + return cs; default: return []; } @@ -758,6 +783,10 @@ export function deadlineWindow(s: PokerState): number { if (isAway(h.order[h.bet.turn]!)) return o.awaySeconds * 1000; return o.turnSeconds === null ? 0 : o.turnSeconds * 1000; } + case 'reveal': + // Same clock as a betting turn of that player. + if (waitingFor(s).every(isAway)) return o.awaySeconds * 1000; + return o.turnSeconds === null ? 0 : o.turnSeconds * 1000; case 'choice': case 'draw': case 'declare': diff --git a/packages/games/src/poker/index.ts b/packages/games/src/poker/index.ts index 8eee67b..d542c75 100644 --- a/packages/games/src/poker/index.ts +++ b/packages/games/src/poker/index.ts @@ -21,6 +21,7 @@ import { chipsOnTable, closeHand, decideRebuy, + decideReveal, deadlineSig, doBet, finishGame, @@ -194,6 +195,9 @@ function validate(s: PokerState, actor: PlayerId, a: PokerAction): Validation { if (h.phase !== 'declare' || !h.waiting) return fail('지금은 선언할 때가 아니에요.'); if (!inPlay(h, actor)) return fail('이번 판에서 이미 다이했어요.'); return hp.declare ? fail('이미 선언했어요.') : ok; + case 'reveal': + if (h.phase !== 'reveal' || !inPlay(h, actor)) return fail('지금은 카드 공개를 고를 때가 아니에요.'); + return ok; default: if (!isBetType(a.type)) return fail('알 수 없는 행동이에요.'); return validateBetAction(s, actor, a as PokerClientAction & { type: BetActionType }); @@ -210,6 +214,8 @@ function applyTimeout(s: PokerState, ctx: Ctx, actor: PlayerId): void { for (const id of h.order) h.players[id]!.ready = true; return closeHand(s, ctx); } + // Not showing is the default answer, not a missed turn. + if (h.phase === 'reveal') return decideReveal(s, ctx, false); seat.timeoutsInRow++; if (seat.timeoutsInRow === 2) log(s, actor, '시간 초과가 이어져 자리 비움으로 표시했어요'); const hp = h.players[actor]!; @@ -236,7 +242,9 @@ function applyLeave(s: PokerState, ctx: Ctx, actor: PlayerId): void { if (s.phase === 'rebuy' && s.rebuyPending.includes(actor)) decideRebuy(s, ctx, actor, false); else if (s.phase === 'playing' && s.hand) { const h = s.hand; - if (!h.settled) forceFold(s, ctx, actor); + if (h.phase === 'reveal') { + if (inPlay(h, actor)) decideReveal(s, ctx, false); + } else if (!h.settled) forceFold(s, ctx, actor); else if (h.players[actor] && !h.players[actor]!.ready) { h.players[actor]!.ready = true; if (h.order.every((id) => h.players[id]!.ready)) closeHand(s, ctx); @@ -283,6 +291,9 @@ function apply(prev: PokerState, actor: PlayerId, a: PokerAction, { rng, now }: hp!.declare = a.side; advance(s, ctx); break; + case 'reveal': + decideReveal(s, ctx, a.show); + break; default: doBet(s, ctx, actor, toBetAction(a)); } @@ -315,6 +326,8 @@ function legalActions(s: PokerState, p: PlayerId): PokerAction[] { } case 'declare': return (['high', 'low', 'swing'] as Side[]).map((side) => ({ type: 'declare', side })); + case 'reveal': + return [{ type: 'reveal', show: true }, { type: 'reveal', show: false }]; case 'betting': { const korean = s.betStyle === 'korean'; const out: PokerAction[] = []; @@ -338,7 +351,8 @@ function secretsOf(s: PokerState, player: PlayerId): string[] { const h = s.hand; if (h) { const hp = h.players[player]; - const revealed = !!h.showdown?.some((e) => e.id === player) || (s.options.mode === 'indian' && h.settled); + const revealed = + !!h.showdown?.some((e) => e.id === player) || (s.options.mode === 'indian' && h.settled) || (!!h.foldShown && inPlay(h, player)); if (hp) { if (!revealed) out.push(...hp.hole); if (hp.choice) out.push(...hp.choice); diff --git a/packages/games/src/poker/poker.test.ts b/packages/games/src/poker/poker.test.ts index 79c5ec4..df6eca1 100644 --- a/packages/games/src/poker/poker.test.ts +++ b/packages/games/src/poker/poker.test.ts @@ -508,6 +508,8 @@ describe('no-limit / pot-limit (§5.3)', () => { let s = mk({ mode: 'holdem' }, 3, { dealerSeat: 2 }); s = act(s, 'C', { type: 'nl.fold' }); s = act(s, 'A', { type: 'nl.fold' }); + expect(s.hand!.phase).toBe('reveal'); + s = act(s, 'B', { type: 'reveal', show: false }); expect(s.hand!.phase).toBe('handEnd'); expect(s.hand!.foldWin).toBe(true); expect(s.hand!.showdown).toBeNull(); @@ -598,6 +600,97 @@ describe('바둑이 / 5카드 드로우 (§5.4.5, §5.4.6)', () => { }); }); +// ------------------------------------------------------------------ fold win: show or keep the cards + +describe('혼자 남으면 카드 공개를 골라요', () => { + /** Hold'em, order A(SB) B(BB) C: C and A fold, B (9♠ 9♥) is the last one in. */ + const lone = () => { + let s = mk({ mode: 'holdem' }, 3, { dealerSeat: 2, deck: deckOf('7D 9S AS 2C 9H AH') }); + s = act(s, 'C', { type: 'nl.fold' }); + s = act(s, 'A', { type: 'nl.fold' }); + return s; + }; + + test('only the last player decides, on the betting clock; the pot waits until then', () => { + const s = lone(); + expect(s.hand!.phase).toBe('reveal'); + expect(poker.activePlayers(s)).toEqual(['B']); + expect(poker.legalActions!(s, 'B')).toEqual([{ type: 'reveal', show: true }, { type: 'reveal', show: false }]); + expect(poker.legalActions!(s, 'A')).toEqual([]); + expect(reason(s, 'A', { type: 'reveal', show: true })).toBe('지금은 카드 공개를 고를 때가 아니에요.'); + expect(reason(s, 'A', { type: 'ready' })).toBe('아직 판이 끝나지 않았어요.'); + expect(reason(mk({ mode: 'holdem' }, 3), 'A', { type: 'reveal', show: true })).toBe('지금은 카드 공개를 고를 때가 아니에요.'); + expect([view(s, 'B').my.canReveal, view(s, 'A').my.canReveal]).toEqual([true, false]); + expect(s.deadlineAt! - clock).toBe(s.options.turnSeconds! * 1000); + expect(s.hand!.settled).toBe(false); + expect(view(s, null).pot).toBe(10); // BB's uncalled 5 already back + expect(chipsBalanced(s)).toBe(true); + expect(view(s, 'A').seats[1]!.hole).toEqual([null, null]); + }); + + test('show: everyone (spectators too) sees the cards and the hand; the log says so', () => { + const s = act(lone(), 'B', { type: 'reveal', show: true }); + expect(s.hand!.phase).toBe('handEnd'); + expect([stack(s, 'A'), stack(s, 'B'), stack(s, 'C')]).toEqual([995, 1005, 1000]); + const name = evaluate(s.options, s.hand!.players.B!, []).high.name; + for (const v of ['A', 'C', null]) { + expect(view(s, v).seats[1]!.hole).toEqual(['9S', '9H']); + expect(view(s, v).foldShown).toEqual({ id: 'B', handName: name }); + expect(view(s, v).seats[0]!.hole).toEqual(v === 'A' ? ['7D', '2C'] : [null, null]); + } + expect(s.log.some((e) => e.by === 'B' && e.msg === `패를 공개했어요 · ${name}`)).toBe(true); + expect(poker.secretsOf!(s, 'B')).not.toContain('9S'); + }); + + test('hide: nobody else sees the cards, as before', () => { + const s = act(lone(), 'B', { type: 'reveal', show: false }); + expect(s.hand!.foldWin).toBe(true); + expect(s.hand!.showdown).toBeNull(); + for (const v of ['A', 'C', null]) { + expect(view(s, v).seats[1]!.hole).toEqual([null, null]); + expect(view(s, v).foldShown).toBeNull(); + expect(JSON.stringify(view(s, v))).not.toContain('"9S"'); + } + expect(s.log.some((e) => e.by === 'B' && e.msg === '패를 공개하지 않았어요')).toBe(true); + expect(poker.secretsOf!(s, 'B')).toContain('9S'); + }); + + test('time runs out or the player leaves: cards stay hidden (not counted as a missed turn)', () => { + const s = act(lone(), 'B', { type: 'timeout' }); + expect(s.hand!.phase).toBe('handEnd'); + expect(s.hand!.foldShown).toBe(false); + expect(s.seats[1]!.timeoutsInRow).toBe(0); + const t = act(lone(), 'B', { type: 'leave' }); + expect(t.hand!.phase).toBe('handEnd'); + expect(t.hand!.foldShown).toBe(false); + expect(view(t, 'A').seats[1]!.hole).toEqual([null, null]); + expect(chipsBalanced(t)).toBe(true); + }); + + test('7포커: the hidden cards are shown, the 초이스 discard stays secret', () => { + let s = mk({ mode: 'sevenPoker' }, 3, { dealerSeat: 2 }); + for (const p of [...view(s, null).waiting]) s = act(s, p, poker.legalActions!(s, p)[0]!); + while (s.hand!.phase === 'betting') s = act(s, toAct(s)!, { type: 'k.die' }); + expect(s.hand!.phase).toBe('reveal'); + const w = poker.activePlayers(s)[0]!; + s = act(s, w, { type: 'reveal', show: true }); + const other = ['A', 'B', 'C'].find((p) => p !== w)!; + const seat = view(s, other).seats.find((x) => x.id === w)!; + expect(seat.hole).toEqual(s.hand!.players[w]!.hole); + expect(JSON.stringify(view(s, other))).not.toContain(`"${s.hand!.players[w]!.discarded}"`); + expect(poker.secretsOf!(s, w)).toContain(s.hand!.players[w]!.discarded!); + }); + + test('nobody asked when nobody else is at the table, or in 인디언 (every card is shown anyway)', () => { + let s = mk({ mode: 'holdem' }, 2, { dealerSeat: 1 }); + s = act(s, 'B', { type: 'leave' }); + expect(s.phase).toBe('finished'); + let ind = mk({ mode: 'indian', indianCards: 2 }, 3, { dealerSeat: 2 }); + while (ind.hand!.phase === 'betting' && ind.hand!.no === 1) ind = act(ind, toAct(ind)!, { type: 'nl.fold' }); + expect(ind.hand!.phase).toBe('handEnd'); + }); +}); + // ------------------------------------------------------------------ indian describe('인디언 포커 (§5.4.7)', () => { @@ -802,11 +895,13 @@ describe('between hands: rebuy, elimination, levels, dealer, end (§5.6, §5.7, expect(s.hand!.order).toEqual(['B', 'C', 'A']); s = act(s, 'A', { type: 'nl.fold' }); s = act(s, 'B', { type: 'nl.fold' }); + s = act(s, 'C', { type: 'reveal', show: false }); s = readyAll(s); expect(s.hand!.dealerSeat).toBe(1); let w = mk({ mode: 'holdem', dealerRule: 'winner' }, 3, { dealerSeat: 0 }); w = act(w, 'A', { type: 'nl.fold' }); w = act(w, 'B', { type: 'nl.fold' }); + w = act(w, 'C', { type: 'reveal', show: true }); expect(w.lastWinner).toBe('C'); w = readyAll(w); expect(w.hand!.dealerSeat).toBe(2); @@ -816,6 +911,7 @@ describe('between hands: rebuy, elimination, levels, dealer, end (§5.6, §5.7, let s = mk({ mode: 'holdem' }, 3, { dealerSeat: 0 }); s = act(s, 'A', { type: 'nl.fold' }); s = act(s, 'B', { type: 'nl.fold' }); + s = act(s, 'C', { type: 'timeout' }); expect(view(s, 'A').my.canReady).toBe(true); s = act(s, 'A', { type: 'ready' }); expect(reason(s, 'A', { type: 'ready' })).toBe('이미 준비했어요.'); diff --git a/packages/games/src/poker/types.ts b/packages/games/src/poker/types.ts index 4251459..ddc555a 100644 --- a/packages/games/src/poker/types.ts +++ b/packages/games/src/poker/types.ts @@ -6,7 +6,8 @@ import type { PokerMode, PokerOptions } from './options'; export type Side = 'high' | 'low' | 'swing'; export type SeatStatus = 'playing' | 'busted' | 'eliminated' | 'left'; -export type HandPhase = 'deal' | 'choice' | 'betting' | 'draw' | 'declare' | 'handEnd'; +/** `reveal`: everyone else folded — the last player decides whether to show the cards before taking the pot. */ +export type HandPhase = 'deal' | 'choice' | 'betting' | 'draw' | 'declare' | 'reveal' | 'handEnd'; const card = z.string().min(2).max(2); @@ -27,6 +28,7 @@ export const pokerActionSchema = z.discriminatedUnion('type', [ z.object({ type: z.literal('nl.allIn') }), z.object({ type: z.literal('draw'), cardIds: z.array(card).max(5) }), z.object({ type: z.literal('declare'), side: z.enum(['high', 'low', 'swing']) }), + z.object({ type: z.literal('reveal'), show: z.boolean() }), z.object({ type: z.literal('ready') }), z.object({ type: z.literal('rebuy'), accept: z.boolean() }), ]); @@ -109,6 +111,8 @@ export interface HandState { /** Chips have been paid out (stacks are final for this hand). */ settled: boolean; foldWin: boolean; + /** Fold win: the last player showed the cards (absent before 2026-10-14 = not shown). */ + foldShown?: boolean; showdown: ShowdownEntry[] | null; awards: Award[] | null; winners: PlayerId[]; @@ -254,6 +258,7 @@ export interface PokerView { drawMax: number; drawAceBonus: boolean; canDeclare: boolean; + canReveal: boolean; canReady: boolean; canRebuy: boolean; rebuysLeft: number | null; @@ -262,6 +267,8 @@ export interface PokerView { awards: Award[] | null; winners: PlayerId[]; foldWin: boolean; + /** Fold win where the last player showed the cards: who, and the hand those cards make. */ + foldShown: { id: PlayerId; handName: string } | null; indianUsed: CardId[]; log: LogEntry[]; stats: PokerStats; diff --git a/packages/games/src/poker/view.ts b/packages/games/src/poker/view.ts index 725b676..fb85ef7 100644 --- a/packages/games/src/poker/view.ts +++ b/packages/games/src/poker/view.ts @@ -8,7 +8,8 @@ import { bestIntl, bestOmaha } from './eval/international'; import { bestKorean } from './eval/korean'; import { bestLow } from './eval/low'; import { evalBadugi } from './eval/badugi'; -import { bossOf, idxOf, inPlay, rebuysLeft, seatOf, waitingFor } from './hand'; +import { bossOf, contenderIds, idxOf, inPlay, rebuysLeft, seatOf, waitingFor } from './hand'; +import { evaluate } from './showdown'; import { isSeven, streetName } from './modes'; import type { BetActionType, HandPlayer, LegalBetView, PokerState, PokerView, SeatView } from './types'; @@ -66,6 +67,14 @@ export function drawLimitFor(s: PokerState): { max: number; aceBonus: boolean } return s.options.drawLimit === 'three' ? { max: 3, aceBonus: true } : { max: 5, aceBonus: false }; } +/** Fold win where the last player showed the cards: who, and their hand. */ +function foldShownOf(s: PokerState): PokerView['foldShown'] { + const h = s.hand; + if (!h?.foldShown) return null; + const id = contenderIds(h)[0]!; + return { id, handName: evaluate(s.options, h.players[id]!, h.board).high.name }; +} + export function buildView(s: PokerState, viewer: PlayerId | null): PokerView { const o = s.options; const h = s.hand; @@ -79,7 +88,7 @@ export function buildView(s: PokerState, viewer: PlayerId | null): PokerView { const hp = h?.players[seat.id]; const bp = h && hp ? h.bet.players[idxOf(h, seat.id)] : undefined; const mine = viewer === seat.id; - const shown = !!h && (mine || revealedIds.has(seat.id) || (o.mode === 'indian' && h.settled)); + const shown = !!h && (mine || revealedIds.has(seat.id) || (o.mode === 'indian' && h.settled) || (!!h.foldShown && inPlay(h, seat.id))); const v: SeatView = { id: seat.id, seat: i, @@ -190,6 +199,7 @@ export function buildView(s: PokerState, viewer: PlayerId | null): PokerView { drawMax: dl.max, drawAceBonus: dl.aceBonus, canDeclare: contesting && h!.phase === 'declare' && h!.waiting && !hp!.declare, + canReveal: !!(h && h.phase === 'reveal' && viewer && inPlay(h, viewer) && me?.status !== 'left'), canReady: !!(s.phase === 'playing' && h?.phase === 'handEnd' && hp && !hp.ready && me?.status !== 'left'), canRebuy: s.phase === 'rebuy' && !!viewer && s.rebuyPending.includes(viewer), rebuysLeft: left, @@ -198,6 +208,7 @@ export function buildView(s: PokerState, viewer: PlayerId | null): PokerView { awards: h?.awards ? h.awards.map((a) => ({ ...a })) : null, winners: h ? [...h.winners] : [], foldWin: !!h?.foldWin, + foldShown: foldShownOf(s), indianUsed: [...s.indianUsed], log: s.log.slice(-VIEW_LOG).map((e) => ({ ...e })), stats: structuredClone(s.stats), diff --git a/packages/games/src/seotda/bot.test.ts b/packages/games/src/seotda/bot.test.ts index c76b72e..3219880 100644 --- a/packages/games/src/seotda/bot.test.ts +++ b/packages/games/src/seotda/bot.test.ts @@ -151,6 +151,22 @@ describe('seotda bot', () => { expect(decide(s, 'A')).toEqual({ type: 'open', cardId: P(5) }); }); + test('혼자 남으면: 약한 패는 공개하지 않고, 땡 이상은 가끔 공개해요', () => { + const lone = (a: number[]) => { + let s = rig(make(), { A: a, B: [P(5), P(6)], C: [P(2), P(7)] }); + s = act(s, 'A', { type: 'half' }); + s = act(s, 'B', { type: 'die' }); + s = act(s, 'C', { type: 'die' }); + expect(s.hand!.phase).toBe('reveal'); + return s; + }; + const weak = lone([P(2), P(3)]); + for (const r of [0.05, 0.5, 0.95]) expect(decide(weak, 'A', r)).toEqual({ type: 'reveal', show: false }); + const strong = lone([S(3), S(8)]); + expect(decide(strong, 'A', 0.1)).toEqual({ type: 'reveal', show: true }); + expect(decide(strong, 'A', 0.9)).toEqual({ type: 'reveal', show: false }); + }); + test('3장 섯다: keeps the best pair of its three cards', () => { let s = make({ cardMode: 'three', threeOpen: false, threePick: 'beforeBet' }); s = rig(s, { A: [P(4), P(9)], B: [P(5), P(7)], C: [P(2), P(3)] }, [P(6), S(2), S(5)]); diff --git a/packages/games/src/seotda/bot.ts b/packages/games/src/seotda/bot.ts index f85ed0e..ae2f7c6 100644 --- a/packages/games/src/seotda/bot.ts +++ b/packages/games/src/seotda/bot.ts @@ -13,7 +13,7 @@ */ import type { BotStrategy } from '../bots/types'; import { humanBest, pick, typeOf } from '../bots/policy'; -import type { HandRules } from './hands'; +import { bestChoice, evalSeotda, type HandRules } from './hands'; import { deckOf, type BetType, type SeotdaAction, type SeotdaView } from './index'; import { cardsKey, odds, strengthPercentile, type Odds, type RangeWeight } from './odds'; @@ -204,6 +204,13 @@ export const seotdaBot: BotStrategy = ({ me, view: v, const join = (v.pot + r.cost) / k - r.cost > 0 && r.cost <= (mine?.stack ?? 0) / 3; return legal.find((a) => a.type === 'rejoin' && a.accept === join) ?? first; } + case 'reveal': { + // Everyone else died: usually keep the cards hidden; now and then show off a 땡 or better. + const cards = myCardsOf(v, me); + const pair = v.myChosen ?? (cards.length === 3 ? bestChoice(cards, rules) : cards.length === 2 ? (cards as [number, number]) : null); + const strong = !!pair && evalSeotda(pair[0], pair[1], rules).value >= 901; + return { type: 'reveal', show: strong && random() < 0.5 }; + } case 'open': { // 3장 섯다 공개패: show the card that tells the others least — the one whose month leaves my best hands hidden. const opens = legal.filter((a): a is Extract => a.type === 'open'); diff --git a/packages/games/src/seotda/index.ts b/packages/games/src/seotda/index.ts index 1f0d678..67be301 100644 --- a/packages/games/src/seotda/index.ts +++ b/packages/games/src/seotda/index.ts @@ -130,7 +130,7 @@ export const seotdaOptionsSchema = z .meta({ title: '한 판의 재경기 최대 횟수(넘으면 나눠 가짐)', labels: { 1: '1번', 2: '2번', 3: '3번', 5: '5번' } }), decisionSeconds: lit(10, 15, 30) .default(15) - .meta({ title: '재참가·리바이 답 시간', labels: { 10: '10초', 15: '15초', 30: '30초' } }), + .meta({ title: '재참가·리바이·카드 공개 답 시간', labels: { 10: '10초', 15: '15초', 30: '30초' } }), }) .superRefine((o, ctx) => { if (o.baseUnit * 20 > o.startingChips) { @@ -151,6 +151,7 @@ export const seotdaActionSchema = z.discriminatedUnion('type', [ z.object({ type: z.literal('choose'), cardIds: z.tuple([z.number().int(), z.number().int()]) }), z.object({ type: z.literal('open'), cardId: z.number().int() }), z.object({ type: z.literal('rejoin'), accept: z.boolean() }), + z.object({ type: z.literal('reveal'), show: z.boolean() }), z.object({ type: z.literal('ready') }), z.object({ type: z.literal('rebuy'), accept: z.boolean() }), ]); @@ -204,8 +205,11 @@ export interface SeotdaHand { handNo: number; /** 0 = 본 판, 1.. = 재경기 차수. */ rematchNo: number; - /** `open`: 3장 섯다 공개패 고르기 (before the first bet). */ - phase: 'open' | 'betting' | 'choose' | 'rejoin' | 'handEnd'; + /** + * `open`: 3장 섯다 공개패 고르기 (before the first bet). `reveal`: everyone else died — the last player decides whether + * to show the cards before taking the pot. + */ + phase: 'open' | 'betting' | 'choose' | 'reveal' | 'rejoin' | 'handEnd'; dealer: PlayerId; /** Participants of this (re)match, from the dealer clockwise. */ order: PlayerId[]; @@ -229,7 +233,8 @@ export interface SeotdaHand { rejoinCost: number; rejoined: PlayerId[]; showdown: { hands: ShowdownHand[]; pots: PotOutcome[] } | null; - foldWin: { winner: PlayerId; amount: number } | null; + /** `shown`: the winner showed the cards (absent before 2026-10-14 = not shown). */ + foldWin: { winner: PlayerId; amount: number; shown?: boolean } | null; next: 'rematch' | 'nextHand' | null; ready: PlayerId[]; lastAction: Record; @@ -253,6 +258,8 @@ export interface HandRecord { amount: number; name: string | null; how: PotOutcome['reason'] | 'rematch'; + /** Fold win: the winner showed the cards. */ + shown?: boolean; } export interface SeotdaFinal { @@ -318,7 +325,7 @@ export interface SeotdaSeatView { isTurn: boolean; ready: boolean; lastAction: { type: BetType; amount: number } | null; - /** Shown after showdown only. */ + /** Shown after showdown only (or when a fold winner showed the cards). */ handName: string | null; /** Money won or lost in the finished hand (result screen only). */ handDelta: number | null; @@ -353,6 +360,8 @@ export interface SeotdaView { myOpened: number | null; myDiscard: SeotdaCardView | null; rejoin: { pending: PlayerId[]; cost: number; mine: boolean; canAfford: boolean } | null; + /** Everyone else died: `by` decides whether to show the cards. */ + reveal: { by: PlayerId; mine: boolean } | null; rebuy: { pending: PlayerId[]; mine: boolean; left: number | null } | null; showdown: { hands: (Omit & { cards: SeotdaCardView[] })[]; pots: PotOutcome[] } | null; foldWin: SeotdaHand['foldWin']; @@ -627,7 +636,19 @@ function enterHandEnd(s: SeotdaState): void { h.ready = []; } -function settleFold(s: SeotdaState, events: GameEvent[]): void { +/** Cards a fold winner shows: the chosen pair (3장 섯다, the discard stays secret), else every card in hand. */ +const foldCards = (h: SeotdaHand, id: PlayerId): number[] => h.chosen[id] ?? h.cards[id] ?? []; + +/** 족보 of the cards a fold winner showed (best pair of three; none for a single card). */ +function foldHandName(h: SeotdaHand, id: PlayerId, rules: HandRules): string | null { + const cs = foldCards(h, id); + if (cs.length < 2) return null; + const pair = cs.length === 2 ? (cs as [number, number]) : bestChoice(cs, rules); + return evalSeotda(pair[0], pair[1], rules).name; +} + +/** `shown`: the winner chose to show the cards (reveal phase). */ +function settleFold(s: SeotdaState, events: GameEvent[], shown: boolean): void { const h = s.hand!; const winner = contendersOf(h)[0] ?? h.order[0]!; const amount = carriedTotal(h) + livePot(h); @@ -635,12 +656,13 @@ function settleFold(s: SeotdaState, events: GameEvent[]): void { clearBetting(s); pay(s, { [winner]: amount }); syncBackStacks(s); - h.foldWin = { winner, amount }; + h.foldWin = { winner, amount, shown }; h.next = 'nextHand'; s.lastWinner = winner; noteBiggest(s, h.handNo, amount, [winner]); - pushHistory(s, { handNo: h.handNo, rematchNo: h.rematchNo, winners: [winner], amount, name: null, how: 'fold' }); - events.push({ type: 'foldWin', winner, amount }); + const name = shown ? foldHandName(h, winner, rulesOf(s.options)) : null; + pushHistory(s, { handNo: h.handNo, rematchNo: h.rematchNo, winners: [winner], amount, name, how: 'fold', shown }); + events.push({ type: 'foldWin', winner, amount, shown }); enterHandEnd(s); } @@ -907,7 +929,10 @@ function progress(s: SeotdaState, rng: Rng, events: GameEvent[]): void { h.betting = withoutCarry(b, (core) => returnUncalled(core).state); syncStacks(s); if (handDecided(h.betting)) { - settleFold(s, events); + // One player left and someone still at the table: they decide whether to show the cards first. + const lone = contendersOf(h); + if (lone.length === 1 && s.seats.some((x) => x.id !== lone[0] && !x.left && x.status !== 'eliminated')) h.phase = 'reveal'; + else settleFold(s, events, false); continue; } // 3장 섯다(한게임): 2장 → 공개패 1장 → 1구 베팅 → 1장 더 → 2구 베팅 → 3장 중 2장 고르기 → 공개. @@ -958,6 +983,13 @@ function progress(s: SeotdaState, rng: Rng, events: GameEvent[]): void { } return; } + case 'reveal': { + if (seatOf(s, contendersOf(h)[0]!)!.left) { + settleFold(s, events, false); + continue; + } + return; + } case 'rejoin': { for (const id of [...h.rejoinPending]) if (seatOf(s, id)!.left) decideRejoin(s, id, false, events); if (h.rejoinPending.length === 0) { @@ -1025,6 +1057,7 @@ function refreshDeadline(s: SeotdaState, now: number): void { ms = o.turnSeconds === null ? null : seatOf(s, id)!.away ? AWAY_MS : o.turnSeconds * 1000; } else if (h.phase === 'choose' || h.phase === 'open') ms = o.turnSeconds === null ? null : (o.turnSeconds + 10) * 1000; else if (h.phase === 'rejoin') ms = o.decisionSeconds * 1000; + else if (h.phase === 'reveal') ms = seatOf(s, contendersOf(h)[0]!)!.away ? AWAY_MS : o.decisionSeconds * 1000; else if (h.phase === 'handEnd') ms = HAND_END_MS; } if (key !== s.waitKey) { @@ -1046,6 +1079,8 @@ function waiting(s: SeotdaState): PlayerId[] { return contendersOf(h).filter((id) => !h.chosen[id]); case 'open': return contendersOf(h).filter((id) => h.opened[id] === null); + case 'reveal': + return contendersOf(h); case 'rejoin': return [...h.rejoinPending]; case 'handEnd': @@ -1215,6 +1250,10 @@ export const seotda: GameDefinition l.type === t) ? t : 'die', events); } else if (phase === 'choose') chooseFor(s, actor, bestChoice(h!.cards[actor]!, rulesOf(s.options)), events); else if (phase === 'open') openFor(s, actor, autoOpen(h!.cards[actor]!), events); + else if (phase === 'reveal') settleFold(s, events, false); else if (phase === 'rejoin') decideRejoin(s, actor, false, events); else if (phase === 'handEnd') h!.ready.push(actor); else decideRebuy(s, actor, false, events); @@ -1295,6 +1338,7 @@ export const seotda: GameDefinition x.id) ?? []); + const foldShown = h?.foldWin?.shown ? h.foldWin.winner : null; const seats: SeotdaSeatView[] = s.seats.map((x) => { const better = b?.players.find((p) => p.id === x.id) ?? null; const inHand = !!h && h.order.includes(x.id); @@ -1303,7 +1347,8 @@ export const seotda: GameDefinition y.id === x.id)!.cards; slots = pair.map((c) => cardView(h, c)); - } else if (h && x.id === viewer) slots = cards.map((c) => cardView(h, c)); + } else if (h && x.id === foldShown) slots = foldCards(h, x.id).map((c) => cardView(h, c)); + else if (h && x.id === viewer) slots = cards.map((c) => cardView(h, c)); else { // 3장 섯다: the 공개패 is face up for everyone; after choosing, others see the two kept cards (the discard stays // secret, so a 공개패 that was thrown away is no longer shown). @@ -1331,7 +1376,7 @@ export const seotda: GameDefinition y.id === x.id)?.name ?? null, + handName: h?.showdown?.hands.find((y) => y.id === x.id)?.name ?? (h && x.id === foldShown ? foldHandName(h, x.id, rules) : null), handDelta: h?.phase === 'handEnd' && h.next === 'nextHand' && inHand ? x.stack - x.stackAtHandStart : null, }; }); @@ -1396,6 +1441,7 @@ export const seotda: GameDefinition= h.rejoinCost } : null, + reveal: h?.phase === 'reveal' ? { by: contendersOf(h)[0]!, mine: !!me && contendersOf(h)[0] === me } : null, rebuy: s.phase === 'rebuy' ? { @@ -1458,6 +1504,8 @@ export const seotda: GameDefinition ({ type: 'open', cardId: c }) as SeotdaAction); + case 'reveal': + return contendersOf(h).includes(p) ? [{ type: 'reveal', show: true }, { type: 'reveal', show: false }] : []; case 'rejoin': if (!h.rejoinPending.includes(p)) return []; return st.stack >= h.rejoinCost ? [{ type: 'rejoin', accept: true }, { type: 'rejoin', accept: false }] : [{ type: 'rejoin', accept: false }]; @@ -1473,6 +1521,7 @@ export const seotda: GameDefinition x.id === player)?.cards ?? []); const shown = h.opened?.[player]; if (shown !== null && shown !== undefined) revealed.add(shown); + if (h.foldWin?.shown && h.foldWin.winner === player) for (const c of foldCards(h, player)) revealed.add(c); const key = (c: number) => `h${h.handNo}r${h.rematchNo}c${c}`; const own = (h.cards[player] ?? []).filter((c) => !revealed.has(c)).map(key); return [...own, ...h.deck.map(key)]; diff --git a/packages/games/src/seotda/seotda.test.ts b/packages/games/src/seotda/seotda.test.ts index d48d8ee..3fbee02 100644 --- a/packages/games/src/seotda/seotda.test.ts +++ b/packages/games/src/seotda/seotda.test.ts @@ -76,6 +76,11 @@ const reject = (s: SeotdaState, p: string, a: SeotdaAction) => { const v = seotda.validate(s, p, a); return v.ok ? null : v.reason; }; +/** Everyone dies until the hand ends; the last player keeps the cards hidden. */ +function foldOut(s: SeotdaState): SeotdaState { + while (s.hand!.phase !== 'handEnd') s = act(s, seotda.activePlayers(s)[0]!, s.hand!.phase === 'reveal' ? { type: 'reveal', show: false } : { type: 'die' }); + return s; +} function readyAll(s: SeotdaState): SeotdaState { for (const p of seotda.activePlayers(s)) s = act(s, p, { type: 'ready' }); return s; @@ -291,12 +296,14 @@ describe('betting flow', () => { expect(seotda.view(s, 'B').seats.find((x) => x.id === 'A')!.handName).toBe('장땡'); }); - test('fold to one: winner takes the pot (uncalled bet back), no cards revealed', () => { + test('fold to one: winner keeps the cards hidden and takes the pot (uncalled bet back)', () => { let s = make({ dealMode: 'oneRound' }); s = act(s, 'A', { type: 'half' }); // 15 s = act(s, 'B', { type: 'die' }); s = act(s, 'C', { type: 'die' }); - expect(s.hand!.foldWin).toEqual({ winner: 'A', amount: 30 }); // A's uncalled 15 came back first + expect(s.hand!.phase).toBe('reveal'); + s = act(s, 'A', { type: 'reveal', show: false }); + expect(s.hand!.foldWin).toEqual({ winner: 'A', amount: 30, shown: false }); // A's uncalled 15 came back first expect(stack(s, 'A')).toBe(1020); expect(s.hand!.showdown).toBeNull(); const bView = seotda.view(s, 'B'); @@ -311,6 +318,7 @@ describe('betting flow', () => { let s = make({ dealMode: 'oneRound', dealerRule: 'rotate' }); s = act(s, 'A', { type: 'die' }); s = act(s, 'B', { type: 'die' }); + s = act(s, 'C', { type: 'reveal', show: false }); s = readyAll(s); expect(s.hand!.dealer).toBe('B'); }); @@ -337,6 +345,103 @@ describe('betting flow', () => { }); }); +describe('모두 다이하고 혼자 남으면 카드 공개를 골라요', () => { + /** A 38광땡 bets 하프, B and C die: A decides. */ + function lone(opts: OldOpts = {}): SeotdaState { + let s = make({ dealMode: 'oneRound', ...opts }); + s = rig(s, { A: [S(3), S(8)], B: [P(5), P(6)], C: [P(2), P(7)] }); + s = act(s, 'A', { type: 'half' }); + s = act(s, 'B', { type: 'die' }); + s = act(s, 'C', { type: 'die' }); + return s; + } + const cardsOf = (s: SeotdaState, viewer: string | null, id = 'A') => seotda.view(s, viewer).seats.find((x) => x.id === id)!.cards; + + test('only the last player decides; the pot waits until then', () => { + const s = lone(); + expect(s.hand!.phase).toBe('reveal'); + expect(seotda.activePlayers(s)).toEqual(['A']); + expect(seotda.legalActions!(s, 'A')).toEqual([{ type: 'reveal', show: true }, { type: 'reveal', show: false }]); + expect(seotda.legalActions!(s, 'B')).toEqual([]); + expect(reject(s, 'B', { type: 'reveal', show: true })).toBe('지금은 카드 공개를 고를 때가 아니에요.'); + expect(reject(s, 'A', { type: 'ready' })).toBe('아직 판이 끝나지 않았어요.'); + expect(reject(make(), 'A', { type: 'reveal', show: true })).toBe('지금은 카드 공개를 고를 때가 아니에요.'); + expect(s.hand!.foldWin).toBeNull(); + expect(stack(s, 'A')).toBe(990); // uncalled 하프 back, pot not paid yet + expect(chipsTotal(s)).toBe(total(s)); + const v = seotda.view(s, 'B'); + expect(v.reveal).toEqual({ by: 'A', mine: false }); + expect(seotda.view(s, 'A').reveal).toEqual({ by: 'A', mine: true }); + expect(v.pot).toBe(30); + expect(cardsOf(s, 'B')).toEqual([{ hidden: true }, { hidden: true }]); + }); + + test('show: everyone (spectators too) sees the cards and the 족보, and the record says so', () => { + const r = actE(lone(), 'A', { type: 'reveal', show: true }); + const s = r.state; + expect(r.events).toContainEqual({ type: 'foldWin', winner: 'A', amount: 30, shown: true }); + expect(s.hand!.phase).toBe('handEnd'); + expect(stack(s, 'A')).toBe(1020); + for (const viewer of ['B', 'C', null]) { + expect(cardsOf(s, viewer).map((c) => ('id' in c ? c.id : null))).toEqual([S(3), S(8)]); + expect(seotda.view(s, viewer).seats.find((x) => x.id === 'A')!.handName).toBe('38광땡'); + } + expect(cardsOf(s, 'C', 'B')).toEqual([{ hidden: true }, { hidden: true }]); + expect(seotda.view(s, null).foldWin).toEqual({ winner: 'A', amount: 30, shown: true }); + expect(s.history.at(-1)).toMatchObject({ how: 'fold', shown: true, name: '38광땡' }); + expect(seotda.secretsOf!(s, 'A')).not.toContain(`h1r0c${S(3)}`); + }); + + test('hide: nobody else sees the cards, as before', () => { + const s = act(lone(), 'A', { type: 'reveal', show: false }); + expect(s.hand!.phase).toBe('handEnd'); + expect(s.hand!.foldWin).toEqual({ winner: 'A', amount: 30, shown: false }); + for (const viewer of ['B', 'C', null]) { + expect(cardsOf(s, viewer)).toEqual([{ hidden: true }, { hidden: true }]); + expect(seotda.view(s, viewer).seats.find((x) => x.id === 'A')!.handName).toBeNull(); + expect(JSON.stringify(seotda.view(s, viewer))).not.toContain(`h1r0c${S(3)}`); + } + expect(seotda.secretsOf!(s, 'A')).toContain(`h1r0c${S(3)}`); + expect(s.history.at(-1)).toMatchObject({ how: 'fold', shown: false, name: null }); + }); + + test('time runs out (재참가·리바이·카드 공개 답 시간) or the player leaves: cards stay hidden', () => { + let s = lone(); + expect(s.deadlineAt).toBe(clock + 15_000); + expect(seotda.timeoutPlayers!(s)).toEqual(['A']); + s = act(s, 'A', { type: 'timeout' }); + expect(s.hand!.foldWin!.shown).toBe(false); + expect(s.seats[0]!.timeoutsInRow).toBe(0); // not a missed turn + expect(cardsOf(s, 'B')).toEqual([{ hidden: true }, { hidden: true }]); + const t = act(lone(), 'A', seotda.onLeave!(lone(), 'A')!); + expect(t.hand!.phase).toBe('handEnd'); + expect(t.hand!.foldWin!.shown).toBe(false); + }); + + test('3장 섯다 after choosing: the chosen pair is shown, the thrown card stays secret', () => { + let s = make({ cardMode: 'three', threeOpen: false, threePick: 'beforeBet' }); + s = rig(s, { A: [S(1), S(8)], B: [P(5), P(6)], C: [P(2), P(7)] }, [P(3), P(9), P(10)]); + for (const p of ['A', 'B', 'C']) s = act(s, p, { type: 'check' }); + for (const p of ['A', 'B', 'C']) s = act(s, p, { type: 'timeout' }); // best pairs + expect(s.hand!.chosen.A).toEqual([S(1), S(8)]); + s = act(s, 'A', { type: 'half' }); + s = act(s, 'B', { type: 'die' }); + s = act(s, 'C', { type: 'die' }); + s = act(s, 'A', { type: 'reveal', show: true }); + expect(cardsOf(s, 'B').map((c) => ('id' in c ? c.id : null))).toEqual([S(1), S(8)]); + expect(seotda.view(s, 'B').seats.find((x) => x.id === 'A')!.handName).toBe('18광땡'); + expect(JSON.stringify(seotda.view(s, 'B'))).not.toContain(`"id":${P(3)},`); + expect(seotda.secretsOf!(s, 'A')).toContain(`h1r0c${P(3)}`); + }); + + test('a saved fold win from before this choice (no `shown`) stays hidden', () => { + const s = act(lone(), 'A', { type: 'reveal', show: true }); + delete s.hand!.foldWin!.shown; + expect(cardsOf(s, 'B')).toEqual([{ hidden: true }, { hidden: true }]); + expect(seotda.view(s, 'B').seats.find((x) => x.id === 'A')!.handName).toBeNull(); + }); +}); + describe('재경기', () => { test('구사 재경기: 모인 칩 유지, 학교 재징수 없음, 쇼다운 생존자만', () => { let s = make({ dealMode: 'oneRound' }); @@ -569,8 +674,15 @@ describe('3장 섯다 (한게임 기본: 2장 → 공개패 1장 → 1구 베팅 s = act(s, 'A', { type: 'half' }); s = act(s, 'B', { type: 'die' }); s = act(s, 'C', { type: 'die' }); + expect(s.hand!.phase).toBe('reveal'); + expect(s.hand!.chosen.A).toBeNull(); + s = act(s, 'A', { type: 'reveal', show: true }); expect(s.hand!.phase).toBe('handEnd'); expect(s.hand!.foldWin!.winner).toBe('A'); + // Not chosen yet: the three cards are shown, named by their best pair (1·8 광 → 18광땡). + const c = seotda.view(s, 'C').seats.find((x) => x.id === 'A')!; + expect(c.cards.map((x) => ('id' in x ? x.id : null))).toEqual([S(1), S(8), S(4)]); + expect(c.handName).toBe('18광땡'); }); test('시간 무제한이면 공개패 고르기에도 마감이 없어요', () => { @@ -593,6 +705,7 @@ describe('timeouts, away, leaving', () => { s = act(s, 'A', { type: 'timeout' }, 64_000); expect(s.hand!.lastAction.A!.type).toBe('die'); expect(s.seats[0]!.away).toBe(true); + s = act(s, 'B', { type: 'reveal', show: false }, 65_000); // Next hand (result screen times out): A is away → 5 s limit on A's turn; a real action clears it. for (const p of seotda.activePlayers(s)) s = act(s, p, { type: 'timeout' }, 70_000); const h = s.hand!; @@ -624,7 +737,7 @@ describe('timeouts, away, leaving', () => { expect(s.hand!.betting!.players.find((p) => p.id === 'B')!.status).toBe('folded'); expect(seotda.activePlayers(s)).toEqual(['C']); s = act(s, 'C', { type: 'leave' }); - expect(s.hand!.foldWin!.winner).toBe('A'); + expect(s.hand!.foldWin).toEqual({ winner: 'A', amount: 30, shown: false }); // nobody left to show the cards to s = readyAll(s); expect(s.phase).toBe('finished'); const r = seotda.result(s)!; @@ -637,7 +750,7 @@ describe('rebuy, elimination, scores', () => { /** Ends the current hand by folds, then sets stacks before the hand-end processing. */ function toHandEnd(opts: OldOpts, players = ['A', 'B', 'C']): SeotdaState { let s = make({ dealMode: 'oneRound', ...opts }, players); - while (s.hand!.phase !== 'handEnd') s = act(s, seotda.activePlayers(s)[0]!, { type: 'die' }); + s = foldOut(s); return s; } @@ -653,7 +766,7 @@ describe('rebuy, elimination, scores', () => { expect([s.phase, stack(s, 'B'), s.seats[1]!.rebuys]).toEqual(['playing', 990, 1]); // refilled, then paid the next 학교 expect(chipsTotal(s)).toBe(total(s)); // Last hand: no rebuy question, the game ends. - while (s.hand!.phase !== 'handEnd') s = act(s, seotda.activePlayers(s)[0]!, { type: 'die' }); + s = foldOut(s); s.handsPlayed = 9; s = readyAll(s); expect(s.phase).toBe('finished'); @@ -697,7 +810,7 @@ describe('rebuy, elimination, scores', () => { test('학교 doubles every N hands (capped at startingChips / 5)', () => { let s = make({ dealMode: 'oneRound', schoolUpEvery: 5, startingChips: 500, baseUnit: 20 }); for (let i = 0; i < 10; i++) { - while (s.hand!.phase !== 'handEnd') s = act(s, seotda.activePlayers(s)[0]!, { type: 'die' }); + s = foldOut(s); s = readyAll(s); } expect(s.baseUnit).toBe(80); @@ -783,8 +896,9 @@ describe('한게임 방식 (원 단위, 기본 설정)', () => { s = act(s, 'A', { type: 'half' }); // 1만 5천원 s = act(s, 'B', { type: 'die' }); s = act(s, 'C', { type: 'die' }); + s = act(s, 'A', { type: 'reveal', show: false }); const v = seotda.view(s, null); - expect(v.foldWin).toEqual({ winner: 'A', amount: 30_000 }); + expect(v.foldWin).toEqual({ winner: 'A', amount: 30_000, shown: false }); expect(v.seats.map((x) => x.handDelta)).toEqual([20_000, -10_000, -10_000]); });