M9: 초보자 도움 틀 — 30초 규칙 요약 카드, 게임 중 [?] 지금 할 수 있는 것, 오목 내용
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
26
apps/web/src/games/omok/help.test.ts
Normal file
26
apps/web/src/games/omok/help.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
|
||||
import { GAMES } from '@bg/games';
|
||||
import { helpNow } from './help';
|
||||
|
||||
const users = usersOf(['A', 'B']);
|
||||
const view = (s: unknown, who: string | null) => GAMES.omok!.view(s, who) as any;
|
||||
|
||||
test('오목: 내 차례 / 상대 차례 / 관전 / 첫 수 가운데', () => {
|
||||
const { state } = setupGame('omok', 2, { colorAssignment: 'hostBlack', ruleSet: 'renju' });
|
||||
expect(helpNow(view(state, 'A'), 'A', users)).toContain('첫 수는 판 한가운데');
|
||||
expect(helpNow(view(state, 'B'), 'B', users)).toContain('상대(호랑이님) 차례예요');
|
||||
expect(helpNow(view(state, null), null, users)).toContain('호랑이님(흑) 차례예요');
|
||||
const s2 = applyAction('omok', state, 'A', { type: 'place', x: 7, y: 7 });
|
||||
const t = helpNow(view(s2, 'B'), 'B', users);
|
||||
expect(t).toContain('내 차례예요(백)');
|
||||
expect(t).toContain('5개');
|
||||
});
|
||||
|
||||
test('오목: 무르기 요청을 받으면 수락/거절 안내', () => {
|
||||
const { state } = setupGame('omok', 2, { colorAssignment: 'hostBlack', ruleSet: 'free' });
|
||||
let s = applyAction('omok', state, 'A', { type: 'place', x: 7, y: 7 });
|
||||
s = applyAction('omok', s, 'A', { type: 'requestUndo' });
|
||||
expect(helpNow(view(s, 'B'), 'B', users)).toContain('[수락]');
|
||||
expect(helpNow(view(s, 'A'), 'A', users)).toContain('무르기 요청');
|
||||
});
|
||||
25
apps/web/src/games/omok/help.ts
Normal file
25
apps/web/src/games/omok/help.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/** 오목 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
|
||||
import type { OmokView } from '@bg/games/omok';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
|
||||
const COLOR_KO = { black: '흑', white: '백' } as const;
|
||||
|
||||
export function helpNow(v: OmokView, _me: string | null, players: Record<string, PublicUser>): string {
|
||||
const goal = '가로·세로·대각선 중 한 줄로 내 돌 5개를 먼저 이으면 이겨요.';
|
||||
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
|
||||
const turnNick = players[v.players[v.turn]]?.nickname ?? COLOR_KO[v.turn];
|
||||
if (!v.myColor) return `${turnNick}님(${COLOR_KO[v.turn]}) 차례예요. ${goal}`;
|
||||
const mine = COLOR_KO[v.myColor];
|
||||
if (v.undo.pending && v.undo.pending.by !== v.myColor) return '상대가 무르기를 부탁했어요. [수락]을 누르면 돌이 되돌아가고, [거절]을 누르면 그대로 계속해요.';
|
||||
if (v.draw.pendingBy && v.draw.pendingBy !== v.myColor) return '상대가 무승부를 제안했어요. [수락]하면 이 판은 비기고 끝나요. 계속하려면 [거절]을 눌러 주세요.';
|
||||
if (v.myColor !== v.turn) {
|
||||
const waiting = v.undo.pending ? ' 내 무르기 요청에 상대가 답하기를 기다리는 중이에요.' : v.draw.pendingBy ? ' 내 무승부 제안에 상대가 답하기를 기다리는 중이에요.' : '';
|
||||
return `상대(${turnNick}님) 차례예요. 상대가 돌을 놓을 때까지 기다려 주세요.${waiting} 나는 ${mine}이에요.`;
|
||||
}
|
||||
if (v.moveCount === 0 && v.firstMoveCenter) return `내 차례예요(${mine}). 첫 수는 판 한가운데에만 놓을 수 있어요.`;
|
||||
const lines = [`내 차례예요(${mine}). 빈 곳을 눌러 돌을 놓아요. ${goal}`];
|
||||
if (v.hints?.urgent.length) lines.push('빨간 동그라미 자리를 막지 않으면 상대가 다음에 5개를 이어요!');
|
||||
else if (v.hints?.warn.length) lines.push('노란 점선 동그라미는 상대가 4개를 만들 수 있는 자리예요. 막는 게 좋아요.');
|
||||
if (v.forbidden.length) lines.push('빨간 ✕ 자리는 금수라서 둘 수 없어요.');
|
||||
return lines.join('\n');
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import { Avatar, ConfirmSheet, Sheet } from '../../components/ui';
|
||||
import { TurnTimer, useServerNow } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
|
||||
type Color = 'black' | 'white';
|
||||
const COLOR_KO: Record<Color, string> = { black: '흑', white: '백' };
|
||||
@@ -483,6 +485,8 @@ const ui: GameUI<OmokView, OmokOptions> = {
|
||||
Options,
|
||||
optionsSummary,
|
||||
Rules,
|
||||
quickStart,
|
||||
helpNow,
|
||||
};
|
||||
|
||||
export default ui;
|
||||
|
||||
47
apps/web/src/games/omok/quick.tsx
Normal file
47
apps/web/src/games/omok/quick.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
/** 오목 30초 규칙 요약 (docs/07 §5). */
|
||||
import type { QuickCard } from '../types';
|
||||
|
||||
function MiniBoard({ stones, marks = [] }: { stones: [number, number, 'b' | 'w'][]; marks?: [number, number][] }) {
|
||||
const n = 7;
|
||||
return (
|
||||
<svg viewBox="-0.7 -0.7 7.4 7.4" width={170} height={170} aria-hidden>
|
||||
<rect x={-0.7} y={-0.7} width={7.4} height={7.4} rx={0.4} fill="#e9c27a" />
|
||||
{Array.from({ length: n }, (_, i) => (
|
||||
<g key={i} stroke="#7a5a2a" strokeWidth={0.05}>
|
||||
<line x1={0} y1={i} x2={n - 1} y2={i} />
|
||||
<line x1={i} y1={0} x2={i} y2={n - 1} />
|
||||
</g>
|
||||
))}
|
||||
{stones.map(([x, y, c]) => (
|
||||
<circle key={`${x}-${y}`} cx={x} cy={y} r={0.44} fill={c === 'b' ? '#151515' : '#fbfbf8'} stroke={c === 'b' ? '#000' : '#666'} strokeWidth={0.06} />
|
||||
))}
|
||||
{marks.map(([x, y]) => (
|
||||
<g key={`m${x}-${y}`} stroke="#b91c1c" strokeWidth={0.12}>
|
||||
<line x1={x - 0.25} y1={y - 0.25} x2={x + 0.25} y2={y + 0.25} />
|
||||
<line x1={x + 0.25} y1={y - 0.25} x2={x - 0.25} y2={y + 0.25} />
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export const quickStart: QuickCard[] = [
|
||||
{
|
||||
pic: <MiniBoard stones={[[3, 3, 'b'], [4, 3, 'w'], [3, 4, 'b'], [2, 2, 'w']]} />,
|
||||
alt: '바둑판 위에 검은 돌과 흰 돌이 번갈아 놓여 있어요',
|
||||
title: '번갈아 한 개씩 놓아요',
|
||||
text: '흑이 먼저 시작해요. 내 차례에 빈 곳(줄이 만나는 점)을 누르면 돌이 놓여요.',
|
||||
},
|
||||
{
|
||||
pic: <MiniBoard stones={[[1, 5, 'b'], [2, 4, 'b'], [3, 3, 'b'], [4, 2, 'b'], [5, 1, 'b'], [2, 3, 'w'], [4, 4, 'w']]} />,
|
||||
alt: '검은 돌 5개가 대각선으로 이어져 있어요',
|
||||
title: '5개를 이으면 이겨요',
|
||||
text: '가로·세로·대각선 어느 쪽이든 내 돌 5개를 먼저 한 줄로 이으면 이겨요.',
|
||||
},
|
||||
{
|
||||
pic: <MiniBoard stones={[[2, 3, 'b'], [3, 3, 'b'], [4, 4, 'b'], [4, 5, 'b'], [1, 1, 'w'], [5, 1, 'w']]} marks={[[4, 3]]} />,
|
||||
alt: '빨간 ✕ 표시가 있는 자리는 둘 수 없어요',
|
||||
title: '✕ 자리는 못 둬요',
|
||||
text: '규칙에 따라 둘 수 없는 자리(금수)는 ✕로 보여 줘요. 상대가 4개를 이으면 꼭 막아요.',
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user