우노: 공식 규칙 엔진·컴퓨터 상대·화면·도움말·문서·E2E
- 규칙 모듈 packages/games/src/uno: 108장(원카드 색깔 카드 덱·점수 재사용, 원카드 코드는 그대로), 7장씩, 공식 시작 카드 처리(드로우4 다시 섞기, 드로우2·스킵·리버스, 와일드는 첫 사람이 색 고르기), 색·숫자·기호 맞추기, 낼 카드가 있어도 뽑기 + 뽑은 카드 바로 내기, 2명 리버스=스킵, 와일드 드로우4 도전(공식: 몰래 낼 수 있고 성공 4장/실패 6장, 손패는 도전한 사람만) 또는 쉬운 규칙, "우노!" 외치기(내면서 또는 직후, 다음 차례 행동 전까지 누구나 잡기 2장), 공식 점수(한 판/500점), 하우스 룰(드로우 카드 쌓기, 낼 수 있을 때까지 뽑기, 기본 끄기). 시간 초과는 낼 수 있는 카드 자동 (와일드는 많이 가진 색), 나가기·자리 비움 처리. - 컴퓨터 상대(bot.ts): 레벨별 우노 깜빡함·잡기 확률, 드로우 카드 아끼기, 드로우4 거짓말/도전 판단, 색 고르기. - 테스트: 규칙 시나리오, 무작위 대국(유출·보존·결정성), 컴퓨터, 방에서 사람 1 + 컴퓨터 3 끝까지. - 화면 apps/web/src/games/uno: 지금 색 링·칩, 방향·다음 사람, 남은 장수, 우노 버튼(준비/외치기), 잡기 버튼, 도전·시작 색·판 결과 창, 30초 요약, 지금 할 수 있는 것. - 등록(GAMES, 카탈로그, BOT_GAMES/BOT_STRATEGIES, 화면 레지스트리, 아이콘·카드 탭), docs/games/uno.md, E2E 계획(PC 1 + 휴대폰 2, 끝까지, 잡기·도전 화면). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
81
apps/web/src/games/uno/help.test.ts
Normal file
81
apps/web/src/games/uno/help.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
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', 'C']);
|
||||
const view = (s: unknown, who: string | null) => GAMES.uno!.view(s, who) as any;
|
||||
const nickOf = (id: string) => users[id]!.nickname;
|
||||
const R = (v: number, c = 'a') => ({ id: `R${v}${c}`, kind: 'num', color: 'R', value: v });
|
||||
|
||||
/** A plain turn for the first seat with a red 5 on the table. */
|
||||
function plain() {
|
||||
const { state } = setupGame('uno', 3);
|
||||
state.discard = [R(5)];
|
||||
state.color = 'R';
|
||||
state.phase = { kind: 'turn' };
|
||||
state.current = 'A';
|
||||
state.pending = 0;
|
||||
state.unoWindow = null;
|
||||
return state;
|
||||
}
|
||||
|
||||
test('우노: 내 차례 / 상대 차례 / 관전', () => {
|
||||
const state = plain();
|
||||
const mine = helpNow(view(state, 'A'), 'A', users);
|
||||
expect(mine).toContain('내 차례예요');
|
||||
expect(mine).toContain('지금 색(빨강)');
|
||||
expect(mine).toMatch(/초록 테두리|낼 수 있는 카드가 없어요/);
|
||||
expect(helpNow(view(state, 'B'), 'B', users)).toContain(`${nickOf('A')}님 차례예요. 기다려 주세요`);
|
||||
const spec = helpNow(view(state, null), null, users);
|
||||
expect(spec).toContain(`${nickOf('A')}님 차례예요`);
|
||||
expect(spec).not.toContain('내 차례');
|
||||
});
|
||||
|
||||
test('우노: 2장일 때 우노 안내, 안 외친 사람 잡기', () => {
|
||||
const state = plain();
|
||||
state.hands.A = [R(1), R(2)];
|
||||
expect(helpNow(view(state, 'A'), 'A', users)).toContain('[우노!]를 눌러 두면');
|
||||
state.hands.B = [R(3)];
|
||||
state.unoWindow = { player: 'B', declared: false };
|
||||
expect(helpNow(view(state, 'B'), 'B', users)).toContain('[우노!] 버튼을 빨리 눌러요');
|
||||
expect(helpNow(view(state, 'C'), 'C', users)).toContain(`${nickOf('B')}님이 1장 남았는데`);
|
||||
});
|
||||
|
||||
test('우노: 와일드 드로우4 도전, 쌓인 카드, 시작 색', () => {
|
||||
const state = plain();
|
||||
state.phase = { kind: 'wild4', by: 'A', target: 'B', prevColor: 'R', illegal: false };
|
||||
state.pending = 4;
|
||||
state.current = 'B';
|
||||
const t = helpNow(view(state, 'B'), 'B', users);
|
||||
expect(t).toContain('[도전하기]');
|
||||
expect(t).toContain('6장을 먹어요');
|
||||
expect(helpNow(view(state, 'A'), 'A', users)).toContain('도전할지 고르는 중');
|
||||
expect(helpNow(view(state, null), null, users)).toContain('도전할지 고르는 중');
|
||||
|
||||
const st = setupGame('uno', 3, { stacking: true }).state;
|
||||
st.discard = [{ id: 'RDa', kind: 'draw2', color: 'R' }];
|
||||
st.color = 'R';
|
||||
st.phase = { kind: 'turn' };
|
||||
st.current = 'A';
|
||||
st.pending = 2;
|
||||
st.hands.A = [R(1)];
|
||||
expect(helpNow(view(st, 'A'), 'A', users)).toContain('[2장 뽑기]');
|
||||
|
||||
const sc = plain();
|
||||
sc.phase = { kind: 'startColor' };
|
||||
sc.color = null;
|
||||
expect(helpNow(view(sc, 'A'), 'A', users)).toContain('처음 낼 색');
|
||||
expect(helpNow(view(sc, 'B'), 'B', users)).toContain('시작 색을 고르는 중');
|
||||
});
|
||||
|
||||
test('우노: 끝나면 결과 안내', () => {
|
||||
const def = GAMES.uno!;
|
||||
let { state: s } = setupGame('uno', 2);
|
||||
for (let i = 0; i < 3000 && !def.result(s); i++) {
|
||||
const actor = def.activePlayers(s)[0]!;
|
||||
s = applyAction('uno', s, actor, def.legalActions!(s, actor)[0]);
|
||||
}
|
||||
expect(def.result(s)).toBeTruthy();
|
||||
expect(helpNow(view(s, 'A'), 'A', usersOf(['A', 'B']))).toContain('게임이 끝났어요');
|
||||
});
|
||||
Reference in New Issue
Block a user