Merge branch 'wip/game-gemblo' into codex/owner/grp_discord_joke-app

# Conflicts:
#	apps/web/src/games/registry.ts
#	apps/web/src/lib/catalog-ui.ts
#	docs/games/README.md
#	e2e/games.e2e.ts
#	packages/games/package.json
#	packages/games/src/bots/index.ts
#	packages/games/src/index.ts
#	packages/shared/src/bots.ts
#	packages/shared/src/catalog.ts
This commit is contained in:
EJClaw
2026-10-15 19:41:49 +09:00
27 changed files with 3961 additions and 25 deletions

View File

@@ -0,0 +1,133 @@
/** 젬블로 그림 도우미: 납작한 육각형 칸, 보석 색과 무늬(색약 배려), 작은 블록 그림. */
import type { BlockColor, PieceId } from '@bg/games/gemblo';
import { pieceOffsets } from '@bg/games/gemblo/board';
export const SQ3 = Math.sqrt(3);
/** Screen centre of (q, r) with hex radius 1. */
export const hx = (q: number, r: number): [number, number] => [1.5 * q, SQ3 * (r + q / 2)];
const CORNERS = Array.from({ length: 6 }, (_, k) => [Math.cos((Math.PI / 3) * k), Math.sin((Math.PI / 3) * k)] as const);
/** Polygon points of a flat-top hex. */
export function hexPoints(cx: number, cy: number, s = 1): string {
return CORNERS.map(([a, b]) => `${(cx + a * s).toFixed(3)},${(cy + b * s).toFixed(3)}`).join(' ');
}
export const GEM: Record<BlockColor, { fill: string; edge: string; light: string }> = {
red: { fill: '#e11d48', edge: '#9f1239', light: '#fda4af' },
yellow: { fill: '#eab308', edge: '#a16207', light: '#fef08a' },
green: { fill: '#16a34a', edge: '#166534', light: '#86efac' },
blue: { fill: '#2563eb', edge: '#1e3a8a', light: '#93c5fd' },
purple: { fill: '#9333ea', edge: '#581c87', light: '#d8b4fe' },
orange: { fill: '#ea580c', edge: '#9a3412', light: '#fdba74' },
gold: { fill: '#a8842c', edge: '#6b5313', light: '#f3dc8f' },
};
/** A different mark per colour so colours can be told apart without seeing colour. */
export function Glyph({ color, cx, cy, s = 0.3 }: { color: BlockColor; cx: number; cy: number; s?: number }) {
const f = 'rgba(255,255,255,0.78)';
switch (color) {
case 'red':
return <circle cx={cx} cy={cy} r={s * 0.8} fill={f} />;
case 'yellow':
return <polygon points={`${cx},${cy - s} ${cx + s * 0.95},${cy + s * 0.7} ${cx - s * 0.95},${cy + s * 0.7}`} fill="rgba(80,50,0,0.55)" />;
case 'green':
return <rect x={cx - s * 0.7} y={cy - s * 0.7} width={s * 1.4} height={s * 1.4} fill={f} />;
case 'blue':
return <polygon points={`${cx},${cy - s} ${cx + s},${cy} ${cx},${cy + s} ${cx - s},${cy}`} fill={f} />;
case 'purple': {
const pts = Array.from({ length: 10 }, (_, k) => {
const a = -Math.PI / 2 + (Math.PI / 5) * k;
const rr = k % 2 ? s * 0.45 : s * 1.05;
return `${(cx + Math.cos(a) * rr).toFixed(3)},${(cy + Math.sin(a) * rr).toFixed(3)}`;
}).join(' ');
return <polygon points={pts} fill={f} />;
}
case 'orange':
return <path d={`M${cx - s} ${cy}H${cx + s}M${cx} ${cy - s}V${cy + s}`} stroke={f} strokeWidth={s * 0.5} strokeLinecap="round" />;
case 'gold':
return <path d={`M${cx - s * 0.8} ${cy + s * 0.8}L${cx + s * 0.8} ${cy - s * 0.8}`} stroke="rgba(60,40,0,0.5)" strokeWidth={s * 0.35} strokeLinecap="round" />;
}
}
/** One gem cell (board and pictures share it). */
export function GemCell({ color, cx, cy, s = 0.94, ghost, bad }: { color: BlockColor; cx: number; cy: number; s?: number; ghost?: boolean; bad?: boolean }) {
const g = GEM[color];
if (bad) return <polygon points={hexPoints(cx, cy, s)} fill="rgba(220,38,38,0.55)" stroke="#7f1d1d" strokeWidth={0.1} strokeDasharray="0.25 0.15" />;
return (
<g opacity={ghost ? 0.6 : 1}>
<polygon points={hexPoints(cx, cy, s)} fill={g.fill} stroke={g.edge} strokeWidth={0.1} />
<polygon points={hexPoints(cx - 0.12, cy - 0.14, s * 0.42)} fill={g.light} opacity={0.55} />
<Glyph color={color} cx={cx} cy={cy + 0.05} />
</g>
);
}
/** Cells of a piece in orientation o, as (q, r) offsets moved so the picture starts at (0, 0). */
export function pieceShape(id: PieceId, o: number): [number, number][] {
return pieceOffsets(id, o);
}
/** Small picture of a block (tray, rules, results). `size` = pixel height of the box. */
export function PieceIcon({ id, orient = 0, color, size = 44, dim, title }: { id: PieceId; orient?: number; color: BlockColor; size?: number; dim?: boolean; title?: string }) {
const cells = pieceShape(id, orient).map(([q, r]) => hx(q, r));
const xs = cells.map((c) => c[0]);
const ys = cells.map((c) => c[1]);
const minX = Math.min(...xs) - 1.05;
const maxX = Math.max(...xs) + 1.05;
const minY = Math.min(...ys) - 0.95;
const maxY = Math.max(...ys) + 0.95;
// Square box so every block in the tray has the same footprint (at least 4.6 units: a 5-cell line fits).
const side = Math.max(maxX - minX, maxY - minY, 4.6);
const cx = (minX + maxX) / 2;
const cy = (minY + maxY) / 2;
return (
<svg viewBox={`${cx - side / 2} ${cy - side / 2} ${side} ${side}`} width={size} height={size} aria-hidden={title ? undefined : true} role={title ? 'img' : undefined} aria-label={title} style={{ opacity: dim ? 0.35 : 1, display: 'block' }}>
{cells.map(([x, y], i) => (
<GemCell key={i} color={color} cx={x} cy={y} />
))}
</svg>
);
}
/** Mini board picture for the rules / 30초 요약: hexes in a small patch with coloured cells. */
export interface MiniCell {
q: number;
r: number;
color?: BlockColor;
mark?: 'start' | 'link' | 'bad' | 'ghost';
}
export function MiniHex({ radius = 3, cells, lines = [], crosses = [], width = 170 }: { radius?: number; cells: MiniCell[]; lines?: [number, number, number, number][]; crosses?: [number, number][]; width?: number }) {
const all: [number, number][] = [];
for (let q = -radius; q <= radius; q++) for (let r = -radius; r <= radius; r++) if (Math.abs(q + r) <= radius) all.push([q, r]);
const w = 3 * radius + 2.2;
const h = SQ3 * (2 * radius + 1) + 0.4;
const byKey = new Map(cells.map((c) => [`${c.q},${c.r}`, c]));
return (
<svg viewBox={`${-w / 2} ${-h / 2} ${w} ${h}`} width={width} height={(width * h) / w} aria-hidden style={{ display: 'block', margin: '0 auto' }}>
<rect x={-w / 2} y={-h / 2} width={w} height={h} rx={0.8} fill="var(--wood)" />
{all.map(([q, r]) => {
const [x, y] = hx(q, r);
const c = byKey.get(`${q},${r}`);
if (c?.color && c.mark !== 'ghost' && c.mark !== 'bad') return <GemCell key={`${q},${r}`} color={c.color} cx={x} cy={y} />;
return (
<g key={`${q},${r}`}>
<polygon points={hexPoints(x, y, 0.94)} fill="rgba(255,255,255,0.5)" />
{c?.mark === 'ghost' && c.color && <GemCell color={c.color} cx={x} cy={y} ghost />}
{c?.mark === 'bad' && <GemCell color="red" cx={x} cy={y} bad />}
{c?.mark === 'start' && <polygon points={hexPoints(x, y, 0.7)} fill="none" stroke={GEM[c.color ?? 'red'].fill} strokeWidth={0.18} />}
{c?.mark === 'link' && <circle cx={x} cy={y} r={0.26} fill={GEM[c.color ?? 'red'].fill} stroke="#fff" strokeWidth={0.08} />}
</g>
);
})}
{lines.map(([q1, r1, q2, r2], i) => {
const [x1, y1] = hx(q1, r1);
const [x2, y2] = hx(q2, r2);
return <line key={`l${i}`} x1={x1 + (x2 - x1) * 0.3} y1={y1 + (y2 - y1) * 0.3} x2={x1 + (x2 - x1) * 0.7} y2={y1 + (y2 - y1) * 0.7} stroke="#111827" strokeWidth={0.16} strokeLinecap="round" />;
})}
{crosses.map(([q, r], i) => {
const [x, y] = hx(q, r);
return <path key={`x${i}`} d={`M${x - 0.35} ${y - 0.35}L${x + 0.35} ${y + 0.35}M${x + 0.35} ${y - 0.35}L${x - 0.35} ${y + 0.35}`} stroke="#dc2626" strokeWidth={0.2} strokeLinecap="round" />;
})}
</svg>
);
}

View File

@@ -0,0 +1,27 @@
import { expect, test } from 'bun:test';
import { GAMES } from '@bg/games';
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
import { helpNow } from './help';
const users = usersOf(['A', 'B', 'C', 'D', 'E']);
const view = (s: unknown, who: string | null) => GAMES.gemblo!.view(s, who) as any;
test('젬블로: 내 차례(첫 블록) / 남의 차례 / 관전', () => {
const { state } = setupGame('gemblo', 2, { seatOrder: 'joinOrder' }); // A: 빨강·초록, B: 노랑·파랑
const mine = helpNow(view(state, 'A'), 'A', users);
expect(mine).toContain('내 차례예요. 빨강 블록을 하나 놓아요(남은 72칸)');
expect(mine).toContain('시작점을 덮어야');
expect(mine).toContain('이음점');
expect(helpNow(view(state, 'B'), 'B', users)).toContain('호랑이님(빨강) 차례예요. 기다려 주세요');
expect(helpNow(view(state, null), null, users)).toContain('구경하고 있어요');
});
test('젬블로: 두 번째 블록부터는 이음점 안내, 무르기 요청, 5명 장애물 고르기', () => {
let { state } = setupGame('gemblo', 2, { seatOrder: 'joinOrder', undo: '1' });
state = applyAction('gemblo', state, 'A', { type: 'place', pieceId: 'i5', orient: 0, q: -9, r: -3 });
state = applyAction('gemblo', state, 'A', { type: 'requestUndo' });
expect(helpNow(view(state, 'B'), 'B', users)).toContain('무르기를 부탁했어요');
const five = setupGame('gemblo', 5, { seatOrder: 'joinOrder', fivePlayerObstacles: 'draft' }).state;
expect(helpNow(view(five, 'A'), 'A', users)).toContain('장애물로 놓을 블록을 하나 골라요');
expect(helpNow(view(five, 'B'), 'B', users)).toContain('호랑이님이 장애물 블록을 고르고 있어요');
});

View File

@@ -0,0 +1,57 @@
/** 젬블로 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
import type { GembloView } from '@bg/games/gemblo';
import { COLOR_KO } from '@bg/games/gemblo/board';
import type { PublicUser } from '@bg/shared/lite';
export function helpNow(v: GembloView, me: string | null, players: Record<string, PublicUser>): string {
const nick = (id: string | null) => (id ? `${players[id]?.nickname ?? '다른 사람'}님` : '다른 사람');
const mine = v.players.find((p) => p.id === me) ?? null;
const myColors = mine ? mine.colors.map((i) => v.colors[i]!) : [];
const myText = myColors.length ? `내 색은 ${myColors.map((c) => `${COLOR_KO[c.color]}(남은 ${c.leftCells}칸${c.done ? ', 끝' : ''})`).join(', ')}이에요.` : '';
const goal = '같은 색끼리는 변이 닿으면 안 되고, 내 블록 꼭짓점에서 선을 따라 한 칸 떨어진 곳(이음점)에 이어 놓아요. 끝날 때 남은 칸이 적을수록 이겨요.';
if (v.phase === 'finished') {
const r = v.result;
if (!r) return '게임이 끝났어요.';
const place = mine ? r.ranking.findIndex((g) => g.includes(mine.id)) : -1;
const tail = place === 0 ? ' 내가 1등이에요!' : place > 0 ? ` 나는 ${place + 1}등이에요.` : '';
return `게임이 끝났어요. ${r.summary}.${tail} 판 아래에 색마다 남은 블록이 보여요.`;
}
if (!mine) {
const turn = v.phase === 'playing' ? `${nick(v.turnPlayer)}(${COLOR_KO[v.colors[v.turn]!.color]}) 차례예요.` : `${nick(v.turnPlayer)}이 장애물을 ${v.phase === 'obstacleDraft' ? '고르는' : '놓는'} 중이에요.`;
return `구경하고 있어요. ${turn}\n${goal}`;
}
if (mine.out) return `게임에서 빠졌어요(${mine.out === 'resign' ? '기권' : '시간패'}). 남은 사람들이 끝낼 때까지 지켜볼 수 있어요.\n${myText}`;
const u = v.undo.pending;
if (u && u.by !== mine.id && !u.accepted.includes(mine.id)) {
return `${nick(u.by)}이 무르기를 부탁했어요. [수락]하면 방금 놓은 블록 하나가 되돌려지고, [거절]하면 그대로 계속해요.`;
}
if (v.phase === 'obstacleDraft') {
if (v.turnPlayer === mine.id) return '5명 게임 준비예요. 남는 색 블록 15개를 장애물로 써요. 아래 목록에서 장애물로 놓을 블록을 하나 골라요(한 사람이 3개씩).';
return `5명 게임 준비 중이에요. ${nick(v.turnPlayer)}이 장애물 블록을 고르고 있어요. 다 고르면 차례로 하나씩 판에 놓아요.`;
}
if (v.phase === 'obstaclePlace') {
if (v.turnPlayer === mine.id)
return '내가 고른 장애물을 판에 놓을 차례예요. 맨 바깥 줄에는 못 놓고, 바깥에서 두 번째 줄 칸을 하나 이상 덮으면서 판 가운데 쪽으로 뻗어야 해요. 두 시작점 사이마다 장애물은 3개까지예요.';
return `${nick(v.turnPlayer)}이 장애물을 놓고 있어요. 장애물을 마지막에 놓은 사람부터 게임을 시작해요.`;
}
const c = v.colors[v.turn]!;
if (v.turnPlayer !== mine.id) {
const wait = u && (u.by === mine.id || u.accepted.includes(mine.id)) ? '\n무르기 요청에 다른 사람이 답하기를 기다리는 중이에요.' : '';
return `${nick(v.turnPlayer)}(${COLOR_KO[c.color]}) 차례예요. 기다려 주세요.\n${myText}${wait}`;
}
const lines = [`내 차례예요. ${COLOR_KO[c.color]} 블록을 하나 놓아요(남은 ${c.leftCells}칸).`];
if (c.placed === 0) lines.push('첫 블록은 판에 테두리로 표시된 내 시작점을 덮어야 해요.');
else lines.push(goal);
lines.push('아래에서 블록을 고르고 판의 칸을 눌러 미리 본 뒤 [놓기]를 눌러요. ⟲ ⟳로 돌리고' + (v.allowFlip ? ' ↔로 뒤집어요.' : '요(이 방은 뒤집기 금지).'));
if (v.showHints && v.legal) lines.push(`판의 내 색 점 ${v.legal.bridgePoints.length}개가 이음점이에요. 점을 누르면 그 점을 덮는 방법이 바로 나오고, 다시 누르면 다음 방법이에요.`);
if (v.legal) {
const locked = c.left.length - v.legal.placeable.length;
if (locked > 0) lines.push(`🔒 표시 블록 ${locked}개는 지금 놓을 곳이 없어요.`);
}
return lines.join('\n');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
/** 젬블로 30초 규칙 요약 (docs/07 §5). Small hex patches drawn inline. */
import type { QuickCard } from '../types';
import { MiniHex } from './draw';
export const quickStart: QuickCard[] = [
{
pic: <MiniHex cells={[{ q: 0, r: 0, color: 'red' }, { q: 0, r: 1, color: 'red' }, { q: 2, r: -1, mark: 'link', color: 'red' }, { q: 1, r: 2, mark: 'link', color: 'red' }, { q: -1, r: -1, mark: 'link', color: 'red' }]} lines={[[0, 0, 2, -1], [0, 1, 1, 2], [0, 0, -1, -1]]} />,
alt: '빨간 블록의 꼭짓점에서 선을 따라 한 칸 떨어진 곳에 빨간 점이 찍혀 있어요',
title: '선으로 한 칸 떨어져 이어요',
text: '첫 블록은 내 시작점을 덮고, 그다음부터는 내 블록 꼭짓점에서 선을 따라 한 칸 떨어진 곳(내 색 점)에 이어 놓아요.',
},
{
pic: <MiniHex cells={[{ q: 0, r: 0, color: 'red' }, { q: 0, r: 1, mark: 'bad' }, { q: 1, r: 0, color: 'blue' }, { q: 1, r: 1, color: 'blue' }]} />,
alt: '빨간 블록 바로 옆 칸은 빨갛게 막혀 있고, 파란 블록은 빨간 블록 옆에 붙어 있어요',
title: '같은 색끼리는 닿으면 안 돼요',
text: '같은 색 블록끼리는 변이 닿으면 안 돼요. 다른 색과는 붙어도 괜찮아요. 서로 다른 두 블록 사이의 틈은 지나갈 수 있어요.',
},
{
pic: <MiniHex radius={2} cells={[{ q: -1, r: 0, color: 'green' }, { q: -1, r: 1, color: 'green' }, { q: 0, r: 0, color: 'yellow' }, { q: 1, r: -1, color: 'red' }, { q: 1, r: 0, color: 'red' }, { q: 0, r: 1, color: 'blue' }, { q: 0, r: -1, color: 'purple' }]} />,
alt: '여러 색 보석 블록이 판을 채우고 있어요',
title: '남은 칸이 적으면 승리',
text: '놓을 곳이 없으면 그 색은 끝나요. 모두 끝나면 못 놓은 블록의 칸 수가 가장 적은 사람이 이겨요. 큰 블록부터 쓰세요!',
},
];

View File

@@ -0,0 +1,24 @@
/** 젬블로 소리: 보석 블록 "딸깍". Short and soft; the site volume is applied by feedback.ts. */
import { noise, tone } from '../../lib/feedback';
export const gmSound = {
/** A block set down: a glassy click with a little shimmer. */
place: () => {
noise(28, 0.12, 0, 'bandpass', 3400, 2.2);
tone(1760, 70, 'triangle', 0.07, 4);
tone(2640, 90, 'sine', 0.035, 24);
},
/** A spot where the block can't go (small and low). */
refuse: () => tone(190, 120, 'triangle', 0.08, 0, { slideTo: 140 }),
/** A colour has nowhere left to go: a short falling pair. */
out: () => {
tone(523, 110, 'triangle', 0.06);
tone(392, 160, 'triangle', 0.06, 110);
},
/** All 18 blocks of a colour placed: a quick sparkle. */
allPlaced: () => [1319, 1568, 1976, 2637].forEach((f, i) => tone(f, 110, 'sine', 0.05, 60 + i * 55)),
/** Rotating / flipping the block in hand. */
turn: () => tone(1100, 30, 'triangle', 0.05),
/** Moves taken back (무르기). */
undo: () => tone(700, 160, 'sine', 0.06, 0, { slideTo: 420 }),
};

View File

@@ -9,7 +9,7 @@ import { assertCleanText, eachView, seatIds, usersOf } from './help-kit.test-uti
const IDS = Object.keys(GAME_UI);
test('모든 게임에 도움말이 있어요', () => {
expect(IDS).toHaveLength(35);
expect(IDS).toHaveLength(36);
for (const id of IDS) {
const src = readFileSync(join(import.meta.dir, id, 'index.tsx'), 'utf8');
expect(src, id).toMatch(/\bquickStart,/);

View File

@@ -37,6 +37,7 @@ export const GAME_UI: Record<string, () => Promise<{ default: GameUI }>> = {
'magical-athlete': () => import('./magical-athlete'),
blackjack: () => import('./blackjack'),
'six-nimmt': () => import('./six-nimmt'),
gemblo: () => import('./gemblo'),
};
const cache = new Map<string, GameUI>();

View File

@@ -34,6 +34,7 @@ export const GAME_ICON: Record<string, string> = {
'magical-athlete': '🏃',
blackjack: '🂡',
'six-nimmt': '🐮',
gemblo: '💠',
};
/** Shown on the home screen so users know what's coming (docs/12-roadmap.md). */
@@ -41,7 +42,7 @@ export const UPCOMING: string[] = [];
/** Tabs on the game picker (docs/07 §3.3). Games not listed here only show under 전체. */
export const GAME_GROUPS: { key: string; label: string; ids: string[] }[] = [
{ key: 'board', label: '판·주사위', ids: ['omok', 'connect-four', 'othello', 'chess', 'janggi', 'baduk', 'quoridor', 'yut', 'marble', 'yacht', 'las-vegas', 'magical-athlete', 'clue'] },
{ key: 'board', label: '판·주사위', ids: ['omok', 'connect-four', 'othello', 'chess', 'janggi', 'baduk', 'quoridor', 'yut', 'marble', 'yacht', 'las-vegas', 'magical-athlete', 'clue', 'gemblo'] },
{ key: 'cards', label: '카드·패', ids: ['seotda', 'poker', 'blackjack', 'one-card', 'uno', 'gostop', 'dalmuti', 'splendor', 'cockroach-poker', 'ninety-nine', 'old-maid', 'mahjong', 'rummikub', 'davinci-code', 'six-nimmt'] },
{ key: 'party', label: '여럿이 파티', ids: ['bang', 'halli-galli', 'dobble', 'catchmind', 'mafia', 'liar', 'apple'] },
];