우노: 공식 규칙 엔진·컴퓨터 상대·화면·도움말·문서·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:
74
apps/server/src/rooms/uno.room.test.ts
Normal file
74
apps/server/src/rooms/uno.room.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/** 우노 with computers in a real room (docs/games/uno.md §9.1): a person and three computers play to the end. */
|
||||
import { afterEach, expect, test } from 'bun:test';
|
||||
import { GAMES } from '@bg/games';
|
||||
import { botProfile, isBotId, type ServerMessage } from '@bg/shared';
|
||||
import type { UnoState } from '@bg/games/uno';
|
||||
import { openDb } from '../db';
|
||||
import { RoomManager } from './manager';
|
||||
import type { Conn, Room } from './room';
|
||||
import { RoomStore } from './store';
|
||||
|
||||
const rooms: Room[] = [];
|
||||
afterEach(() => {
|
||||
for (const r of rooms.splice(0)) r.clearTimer();
|
||||
});
|
||||
|
||||
function practice(options: Record<string, unknown> = {}) {
|
||||
const store = new RoomStore(openDb(':memory:'));
|
||||
let now = 1_000_000;
|
||||
const clock = { now: () => now, advance: (ms: number) => (now += ms) };
|
||||
const users = { publicUser: (id: string) => botProfile(id) ?? { id, nickname: id, avatar: null, kind: 'guest' as const } };
|
||||
const manager = new RoomManager({ store, games: GAMES, users, now: clock.now, botDelay: () => 0 });
|
||||
const room = manager.createPractice('A', 'uno') as Room;
|
||||
rooms.push(room);
|
||||
const msgs: ServerMessage[] = [];
|
||||
const a: Conn = { userId: 'A', send: (m) => msgs.push(m), close: () => {} };
|
||||
room.join(a, 'player');
|
||||
room.addBot('A');
|
||||
room.addBot('A');
|
||||
room.configure('A', { options: { ...(room.config.options as object), ...options } });
|
||||
expect(room.start('A')).toBeNull();
|
||||
return { room, clock, msgs };
|
||||
}
|
||||
|
||||
/** Bots move at once; when the game waits on the person, they play their first legal action (or the clock runs out). */
|
||||
function playToEnd(room: Room, clock: { advance: (ms: number) => void }, humanActs: boolean): number {
|
||||
const def = GAMES.uno!;
|
||||
let cs = 0;
|
||||
let steps = 0;
|
||||
for (; steps < 20_000 && !room.game!.finished; steps++) {
|
||||
if (room.bots.dueAt !== null) {
|
||||
room.bots.fire();
|
||||
continue;
|
||||
}
|
||||
const s = room.game!.state as UnoState;
|
||||
const legal = def.legalActions!(s, 'A');
|
||||
if (humanActs && legal.length && def.activePlayers(s).includes('A')) {
|
||||
room.act('A', ++cs, legal.find((x) => (x as { type: string }).type !== 'catchUno') ?? legal[0]);
|
||||
continue;
|
||||
}
|
||||
clock.advance(61_000);
|
||||
room.onTimer();
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
test('a person and three computers finish a game of 우노 (person plays)', () => {
|
||||
const { room, clock } = practice();
|
||||
expect(room.game!.players.filter(isBotId)).toHaveLength(3);
|
||||
playToEnd(room, clock, true);
|
||||
expect(room.game!.finished).toBe(true);
|
||||
expect(room.status).toBe('finished');
|
||||
});
|
||||
|
||||
test('500 points with house rules: the person only times out, the computers still finish', () => {
|
||||
const { room, clock, msgs } = practice({ scoring: 'to500', stacking: true, drawUntilPlayable: true });
|
||||
playToEnd(room, clock, false);
|
||||
expect(room.game!.finished).toBe(true);
|
||||
const s = room.game!.state as UnoState;
|
||||
expect(s.rounds.length).toBeGreaterThanOrEqual(1);
|
||||
expect(msgs.some((m) => m.t === 'state')).toBe(true);
|
||||
// The person's screen shows card counts only for the computers.
|
||||
const view = JSON.stringify(GAMES.uno!.view(s, 'A'));
|
||||
for (const bot of s.seats.filter(isBotId)) for (const c of s.hands[bot]!) expect(view).not.toContain(`"${c.id}"`);
|
||||
});
|
||||
Reference in New Issue
Block a user