diff --git a/apps/web/src/games/blackjack/board.tsx b/apps/web/src/games/blackjack/board.tsx index 5fe6a89..245848e 100644 --- a/apps/web/src/games/blackjack/board.tsx +++ b/apps/web/src/games/blackjack/board.tsx @@ -51,19 +51,23 @@ const CSS = ` .bj-total.bj { background: linear-gradient(160deg, #fde047, #f59e0b); color: #5a2a00; border-color: #fff7c2; } .bj-total.d21 { background: #15803d; } .bj-cards { display: flex; align-items: flex-end; justify-content: center; min-height: 20px; } -.bj-cards > * + * { margin-left: calc(var(--cw) * -0.42); } +.bj-cards > * + * { margin-left: calc(var(--cw) * -1 * var(--ov, .42)); } .bj-card-in { animation: bj-in .42s cubic-bezier(.2,.8,.3,1.1) both; } @keyframes bj-in { from { transform: translate(var(--fx, 260px), var(--fy, -260px)) rotate(-24deg) scale(.6); opacity: 0; } 30% { opacity: 1; } to { transform: none; opacity: 1; } } .bj-card-flip { animation: bj-flip .46s ease both; } @keyframes bj-flip { from { transform: perspective(500px) rotateY(90deg); } to { transform: perspective(500px) rotateY(0); } } -.bj-seat { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -100%); z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 5px; } -.bj-seat .hands { display: flex; gap: 14px; align-items: flex-end; } +.bj-seat { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -100%); z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 5px; + width: max-content; max-width: var(--mw, 40%); } +.bj-name .nm { min-width: 0; } +/* Split hands wrap inside the seat's share of the table instead of running into the neighbours. */ +.bj-seat .hands { display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 100%; } +.bj-seat .hrow { display: flex; gap: 10px; align-items: flex-end; justify-content: center; } .bj-hand { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 6px 4px; border-radius: 14px; border: 2px solid transparent; transition: border-color .2s, background .2s; } .bj-hand.on { border-color: var(--focus); background: rgba(245,158,11,.14); box-shadow: 0 0 18px rgba(245,158,11,.35); } -.bj-hand .meta { display: flex; gap: 5px; align-items: center; } +.bj-hand .meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px 5px; align-items: center; } .bj-tag { font-weight: 900; font-size: .8rem; border-radius: 6px; padding: 0 7px; color: #fff; white-space: nowrap; } .bj-bet { display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; font-weight: 800; background: rgba(255,255,255,.92); color: #1c1e21; border-radius: 999px; padding: 0 8px 0 3px; font-variant-numeric: tabular-nums; white-space: nowrap; } -.bj-name { display: flex; align-items: center; gap: 6px; background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px 3px 3px; box-shadow: var(--shadow), 0 3px 10px rgba(0,0,0,.2); +.bj-name { display: flex; align-items: center; gap: 6px; max-width: 100% !important; background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px 3px 3px; box-shadow: var(--shadow), 0 3px 10px rgba(0,0,0,.2); font-size: .82rem; font-weight: 800; white-space: nowrap; max-width: 220px; border: 2px solid transparent; } .bj-name .nm { overflow: hidden; text-overflow: ellipsis; } .bj-name .ch { color: var(--warning); font-variant-numeric: tabular-nums; } @@ -118,7 +122,7 @@ const CSS = ` .bj-print, .bj-shoe { display: none; } .bj-dealer { position: relative; left: auto; top: auto; transform: none; } .bj-seats { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 10px; } - .bj-seat { position: relative; left: auto; top: auto; transform: none; } + .bj-seat { position: relative; left: auto; top: auto; transform: none; width: auto; max-width: 100%; } .bj-seat.me { order: 99; flex-basis: 100%; } .bj-dock { flex-direction: column; gap: 10px; padding: 10px; } .bj-me { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 6px 10px; } @@ -231,7 +235,7 @@ function HandBox({ h, active, width, q, final }: { h: HandView; active: boolean; h.outcome === 'win' || h.outcome === 'blackjack' || h.outcome === 'bonus' ? '#16a34a' : h.outcome === 'lose' || h.status === 'bust' ? '#dc2626' : h.outcome === 'push' ? '#6b7280' : '#b45309'; return (
-
+
{cards.map((c) => ( ))} @@ -253,16 +257,23 @@ function HandBox({ h, active, width, q, final }: { h: HandView; active: boolean; ); } -function Seat({ seat, v, me, players, pos, width, q, final }: { seat: SeatView; v: BlackjackView; me: string | null; players: Record; pos: { x: number; y: number } | null; width: number; q: ReturnType; final: boolean }) { +function Seat({ seat, v, me, players, pos, width, rows, maxW, q, final }: { seat: SeatView; v: BlackjackView; me: string | null; players: Record; pos: { x: number; y: number } | null; width: number; rows: number; maxW: number; q: ReturnType; final: boolean }) { const u = userOf(players, seat.id); const isTurn = v.phase === 'playing' && v.turn === seat.id; - const style = pos ? ({ '--x': `${pos.x}%`, '--y': `${pos.y}%` } as CSSProperties) : undefined; + const style = { ...(pos ? { '--x': `${pos.x}%`, '--y': `${pos.y}%` } : {}), '--mw': `${maxW}px` } as CSSProperties; + const hands = seat.hands ?? []; + const per = Math.ceil(hands.length / rows); return (
{seat.hands ? (
- {seat.hands.map((h, i) => ( - + {Array.from({ length: rows }, (_, r) => ( +
+ {hands.slice(r * per, r * per + per).map((h, j) => { + const i = r * per + j; + return ; + })} +
))}
) : v.phase === 'betting' && seat.status === 'playing' ? ( @@ -272,7 +283,7 @@ function Seat({ seat, v, me, players, pos, width, q, final }: { seat: SeatView; 0 ? 'plus' : seat.net < 0 ? 'minus' : 'zero'}`}>{seat.net > 0 ? `+${formatChips(seat.net)}` : seat.net < 0 ? `-${formatChips(-seat.net)}` : '본전'} )}
- + {maxW >= 130 && } {u.nickname} {seat.id === me ? ' (나)' : ''} @@ -285,8 +296,39 @@ function Seat({ seat, v, me, players, pos, width, q, final }: { seat: SeatView; ); } -/** Seats along the front arc of the table, left to right; I sit in the middle. Dealing goes right → left (first base on the right). */ -function arcSlots(v: BlackjackView, me: string | null): { id: string; x: number; y: number }[] { +/** How much each card of a hand hides the one before (more cards → tighter fan). */ +const overlapOf = (cards: number) => (cards >= 5 ? 0.68 : cards === 4 ? 0.58 : 0.42); + +/** Width a hand needs, in card widths (first card whole, the rest the visible part). */ +const handUnits = (h: HandView) => 1 + (h.cards.length - 1) * (1 - overlapOf(h.cards.length)); + +/** + * Card width that fits `hands` (in `rows` rows) into `avail` px: hand padding 16 px, gap 10 px. Never bigger than + * `base`, never smaller than 26 px. + */ +function fitCardWidth(hands: HandView[], avail: number, base: number, rows: number): number { + if (!hands.length) return base; + const per = Math.ceil(hands.length / rows); + let worst = 0; + let cnt = 1; + for (let r = 0; r < rows; r++) { + const row = hands.slice(r * per, r * per + per); + const u = row.reduce((a, h) => a + handUnits(h), 0); + if (u > worst) { + worst = u; + cnt = row.length; + } + } + const w = (avail - cnt * 16 - (cnt - 1) * 10) / worst; + return Math.max(26, Math.min(base, Math.floor(w))); +} + +/** + * Seats along the front of the table, left to right, I sit in the middle (dealing goes right → left, first base on + * the right). Each seat gets a share of the width by weight — mine and split seats more — so neighbours never run + * into each other; the shallow arc puts the middle lowest. `share` is in % of the table width. + */ +function seatLayout(v: BlackjackView, me: string | null): { id: string; x: number; y: number; share: number }[] { const ids = (v.order.length ? v.order : v.seats.map((s) => s.id)).filter((id) => v.seats.some((s) => s.id === id)); for (const s of v.seats) if (!ids.includes(s.id)) ids.push(s.id); let ltr = [...ids].reverse(); @@ -294,11 +336,18 @@ function arcSlots(v: BlackjackView, me: string | null): { id: string; x: number; const mid = Math.floor(n / 2); const mi = me ? ltr.indexOf(me) : -1; if (mi >= 0) ltr = ltr.map((_, i) => ltr[(i + mi - mid + n) % n]!); - // Few players sit close together at the front; more players spread along the arc. - const span = Math.min(140, 38 * (n - 1)); + const handsOf = (id: string) => Math.max(1, v.seats.find((s) => s.id === id)?.hands?.length ?? 1); + const weight = (id: string) => (id === me ? Math.min(3.2, Math.max(1.8, 1.1 * Math.ceil(handsOf(id) / (handsOf(id) >= 3 ? 2 : 1)))) : Math.min(2, Math.max(1, 0.8 * handsOf(id)))); + const ws = ltr.map(weight); + const total = ws.reduce((a, b) => a + b, 0); + const span = Math.min(90, 18 * total); + let acc = 50 - span / 2; return ltr.map((id, i) => { - const a = ((n === 1 ? 90 : 90 + span / 2 - (i * span) / (n - 1)) * Math.PI) / 180; - return { id, x: 50 + 42 * Math.cos(a), y: 50 + 45 * Math.sin(a) }; + const share = (span * ws[i]!) / total; + const x = acc + share / 2; + acc += share; + const t = (x - 50) / 45; + return { id, x, y: 96 - 24 * t * t, share }; }); } @@ -527,7 +576,7 @@ function Dock({ v, me, players, act, pending, deadline, mine, final }: { v: Blac )}

{seat.hands && ( - )} @@ -593,10 +642,22 @@ export function BlackjackBoard({ view: v, me, players, act, pending, deadline }: const d = v.dealer; const dealerCards = d.cards.map((c) => c ?? holeKey(v)).filter((k) => q.shown(k)); const dealerReal = d.cards.filter((c): c is string => !!c && q.shown(c)); - const slots = arcSlots(v, me); - const n = slots.length; - const otherW = phone ? 40 : n > 5 ? 48 : 56; + const slots = seatLayout(v, me); + const otherW = phone ? 40 : 56; const myW = phone ? 56 : 76; + const dealerW = phone ? 56 : 66; + // Table width for fitting cards into each seat's share (phone: my seat a full row, others two per row). + const tableRef = useRef(null); + const [[tableW, tableH], setTableSize] = useState([990, 520]); + useLayoutEffect(() => { + const el = tableRef.current; + if (!el) return undefined; + const measure = () => setTableSize([el.clientWidth, el.clientHeight]); + const ro = new ResizeObserver(measure); + ro.observe(el); + measure(); + return () => ro.disconnect(); + }, []); // Sounds + my result once the cards are down. const sounded = useRef(new Set()); const allKeys = [...v.seats.flatMap((s) => s.hands?.flatMap((h) => h.cards) ?? []), ...d.cards.map((c) => c ?? holeKey(v))]; @@ -639,14 +700,22 @@ export function BlackjackBoard({ view: v, me, players, act, pending, deadline }: }, [v.turn]); // eslint-disable-line react-hooks/exhaustive-deps const dealerDone = dealerCards.length === d.cards.length; - const seatEls = slots.map(({ id, x, y }) => { + const seatEls = slots.map(({ id, x, y, share }) => { const seat = v.seats.find((s) => s.id === id)!; - return ; + const hands = seat.hands ?? []; + const rows = hands.length >= 3 ? 2 : 1; + const avail = Math.floor(phone ? (id === me ? tableW - 24 : (tableW - 34) / 2) : (tableW * share) / 100 - 8); + // Height too (PC): the seat grows upward from its spot and must stay below the dealer's cards + // (dealer row ≈ 40 + 1.4 × dealer card; per hand row: 1.4 × card + 50 for padding and the total line; name + result ≈ 64). + const roomH = (tableH * y) / 100 - (40 + dealerW * 1.4 + 12) - 64; + const capH = phone ? 999 : Math.floor((roomH / rows - 50) / 1.4); + const width = Math.max(26, Math.min(capH, fitCardWidth(hands, avail, id === me ? myW : otherW, rows))); + return ; }); return (
-
+
BLACKJACK @@ -668,12 +737,12 @@ export function BlackjackBoard({ view: v, me, players, act, pending, deadline }: )} {!d.revealed && d.cards.length > 1 && dealerDone && + ?}
-
+
{d.cards.length === 0 && 베팅이 끝나면 카드를 나눠 줘요} {d.cards.map((c, i) => { const k = c ?? holeKey(v); if (!q.shown(k)) return null; - return ; + return ; })}
diff --git a/docs/games/blackjack.md b/docs/games/blackjack.md index e33b435..c0a33c6 100644 --- a/docs/games/blackjack.md +++ b/docs/games/blackjack.md @@ -98,10 +98,11 @@ ## 9. UI/UX - 2026-10-17 다시 만듦(`apps/web/src/games/blackjack/board.tsx`): 모든 것을 가운데 판에서 보고 누른다(옆 패널은 칩 순위와 놀이용 칩 안내만). - 테이블: 판 폭(최대 1180px)을 다 쓰는 반원 테이블. 위에 딜러 카드와 합, 오른쪽 위에 카드 슈(남은 벌 수), 가운데에 "BLACKJACK · 블랙잭 3:2 · 딜러 규칙" 인쇄. 참가자는 앞쪽 호를 따라 앉고(사람이 적으면 앞 가운데로 모임, 나눠 주는 순서는 오른쪽 → 왼쪽), 내 자리는 가운데 앞에 큰 카드로. 자리마다 손패(합 뱃지·건 칩·결과 뱃지), 판이 끝나면 +/- 칩, 이름표(아바타·칩). 차례 손패는 노란 테두리. + - 자리 폭: 자리마다 테이블 폭을 나눠 받고(내 자리·스플릿한 자리는 더 넓게), 그 폭과 딜러 카드 아래 높이 안에 들어가게 카드 크기를 줄인다(최소 26px). 손패가 3개 이상이면 두 줄. 폭이 좁으면 아바타는 빼고 이름만. 7명 + 스플릿, 혼자 4손패, 폰 390px 7명·4손패에서 자리끼리·딜러와 겹치지 않고 테이블 밖으로 나가지 않는 것을 확인(2026-10-17). - 아래 조작판(흰 카드): 내 얼굴·칩·남은 시간 / 단계별 조작 / 판 정보(판 수·배당·S17/H17·슈·단축키). 내 차례면 파란 테두리와 "내 차례" 띠. - 베팅: 숫자를 바로 적기(Enter로 걸기, 범위·단위가 틀리면 빨간 안내 후 가장 가까운 금액), −/+ 버튼, 판 위 마우스 휠(Shift는 10배)·↑↓ 키, 칩 버튼(+1·5·10·50단위), 최소·절반·최대·지난 베팅(이 기기에 저장), 막대(slider). - 행동: 히트 H · 스탠드 S · 더블 D · 스플릿 P · 서렌더 R(키보드 단축키, 할 수 있는 것만 보임). 인슈어런스 걸기/안 함, 판 결과와 [다음 판]도 같은 자리. - - 카드 한 장씩: 서버가 여러 장을 한꺼번에 보내도(처음 나눠 주기, 딜러 차례) 화면은 실제 나눠 주는 순서(모두 1장 → 딜러 → 모두 2장 → 딜러 홀 카드)로 `BJ_DEAL_STEP_MS`(450ms) 간격으로 슈에서 날아와 놓이고, 딜러 홀 카드는 뒤집히며 펼쳐진다. 합은 놓인 카드만으로 세고, 승패·+/-는 카드가 다 놓인 뒤에 보인다. 엔진은 처음 나눠 주기와 딜러 차례에 그만큼(장당 450ms)을 다음 제한 시간에 더한다(`animLagMs`). 새 판이 시작되면 밀린 카드는 바로 보인다. 블랙잭·딜러 버스트 배너, 버스트 흔들림, 이기면 효과음. + - 카드 한 장씩: 서버가 여러 장을 한꺼번에 보내도(처음 나눠 주기, 딜러 차례) 화면은 실제 나눠 주는 순서(모두 1장 → 딜러 → 모두 2장 → 딜러 홀 카드)로 `BJ_DEAL_STEP_MS`(450ms) 간격으로 슈에서 날아와 놓이고, 딜러 홀 카드는 뒤집히며 펼쳐진다. 합은 놓인 카드만으로 세고, 승패·+/-와 [다음 판] 버튼은 카드가 다 놓인 뒤에 보이거나 눌린다(혼자 하는 판도 결과를 건너뛰지 못함). 엔진은 처음 나눠 주기와 딜러 차례에 그만큼(장당 450ms)을 다음 제한 시간에 더한다(`animLagMs`). 새 판이 시작되면 밀린 카드는 바로 보인다. 블랙잭·딜러 버스트 배너, 버스트 흔들림, 이기면 효과음. - 초보자 도움: 30초 요약 3장(목표·행동·배당), `[?] 지금 할 수 있는 것`이 단계와 내 패에 맞춰 안내. ## 10. 테스트 체크리스트 diff --git a/packages/games/src/blackjack/blackjack.test.ts b/packages/games/src/blackjack/blackjack.test.ts index 9c84eda..323a0d4 100644 --- a/packages/games/src/blackjack/blackjack.test.ts +++ b/packages/games/src/blackjack/blackjack.test.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from 'bun:test'; import { SeededRng, playoutSeeds, randomPlayout, seedN, type CardId, type RngState } from '@bg/engine'; import { + BJ_DEAL_STEP_MS, blackjack, buildShoe, chipsNonNegative, @@ -113,6 +114,23 @@ describe('flow', () => { expect(s.rounds['A']!.hands[0]!.status).toBe('bust'); // +QD = 30 }); + test('카드 연출 시간: 처음 나눠 주기와 딜러 차례만큼 다음 제한 시간이 늘어요(혼자 하는 판도 결과를 건너뛰지 않음)', () => { + // A: KS, 7D (17). Dealer: 5H + 6C, then draws 2S, 3D, 4C → 20. + const shoe: CardId[] = ['KS', '5H', '7D', '6C', '2S', '3D', '4C']; + let s = make({ insurance: false }, ['A'], shoe); + s = blackjack.apply(s, 'A', { type: 'bet', amount: 100 }, { rng: rng(), now: 1000 }).state; + expect(s.phase).toBe('playing'); + // 4 cards dealt × 450 ms on top of the 20 s turn. + expect(s.deadlineMs).toBe(20_000 + 4 * BJ_DEAL_STEP_MS); + expect(s.deadlineAt).toBe(1000 + 20_000 + 4 * BJ_DEAL_STEP_MS); + s = blackjack.apply(s, 'A', { type: 'stand' }, { rng: rng(), now: 2000 }).state; + expect(s.phase).toBe('handEnd'); + expect(s.dealer).toHaveLength(5); + // Hole card turn + 3 drawn cards, then the usual result time. + expect(s.deadlineMs).toBe(s.options.handEndSeconds * 1000 + 4 * BJ_DEAL_STEP_MS); + expect(s.animLagMs).toBe(0); + }); + test('전체 흐름: 한 판을 끝까지', () => { let s = make({ insurance: false, handLimit: 5 }); let now = 1;