새 게임 젝스님트: 숫자 카드를 동시에 몰래 내고 작은 수부터 줄 끝에 붙이기, 여섯 번째 카드면 앞의 다섯 장(소머리 = 벌점)을 가져가는 2~10명 카드 게임
- 엔진 packages/games/src/six-nimmt/(options·rules·types·index·bot): 104장 소머리(합 171), 규칙 1~4, 동시에 몰래 고르기(모두 고르기 전엔 바꾸기 가능, 마지막 사람이 고르면 공개), 작은 카드 줄 고르기·양쪽 끝 같은 차이 자리 고르기에서 멈춤, 라운드 합산·66점(또는 라운드 수) 종료·20라운드 안전장치 - 옵션 전부: 카드 구성(104장/인원×10+4 섞기/펼쳐 골라 가기 프로 2~6명), 양쪽 끝 붙이기, 작은 카드 자동, 30주년판 특별 카드 4종(짝홀·산 오르기·점프하는 소 연쇄·숫자 뒤집기), 끝 점수/라운드 수, 나온 카드 표, 제한 시간 - 시간 초과·나가기: 지금 줄 기준 가장 안전한 카드·소머리 적은 줄, 3번이면 자리 비움(5초), 나간 사람은 바로 자동, 1명 남으면 끝 - 컴퓨터: 카드마다 상대 카드를 흉내 내어 가져갈 소머리 평균(1단계 4번 → 60단계 48번), humanBest 실수, 41단계 이상 숫자 뒤집기·대기 카드 보고 줄 고르기 - 화면 apps/web/src/games/six-nimmt/: 소머리 색 카드, 줄 4개 + 빨간 6번째 칸, 공개 카드 줄과 한 장씩 놓이는 재생(줄 빛남·흔들림·"+🐮" 배너·음매 소리), 손패 미리 보기("2번 줄 3번째"/"⚠ 가져감"/"⬇ 너무 작음"), 뒤집기 토글, 줄 고르기 버튼(추천), 프로 뽑기, 라운드 결과 창, 최종 표, 점수표·나온 카드 표·기록, 휴대폰 320px, 도움말·30초 요약 - 등록: GAMES·BOT_STRATEGIES·BOT_GAMES·CATALOG·GAME_UI·GAME_ICON·카드·패 탭, docs/games/README.md, 설계 문서에 정한 것 기록 - 테스트: 규칙 46개(문서 §10 예시 전부, 무작위 대국 옵션 7종 JSON 왕복·결정성·정보 누출·카드 총수·onTimeout 합법), 컴퓨터 25개(옵션 7종 × 2·5·10명, 60단계 대 1단계), 도움말 2개, 방 통합 4개, E2E six-nimmt·six-nimmt-pro Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
129
apps/server/src/rooms/six-nimmt.room.test.ts
Normal file
129
apps/server/src/rooms/six-nimmt.room.test.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* 젝스님트 through a real Room (docs/games/six-nimmt.md §10): practice games against computers played to the end from
|
||||
* the person's own screen, with the simultaneous secret pick, the row choice, the pro draft and timeouts on the clock.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { GAMES } from '@bg/games';
|
||||
import type { SixNimmtAction, SixNimmtState, SixNimmtView } from '@bg/games/six-nimmt';
|
||||
import { botProfile, isBotId, type ServerMessage } from '@bg/shared';
|
||||
import { openDb } from '../db';
|
||||
import { RoomManager } from './manager';
|
||||
import { Room, type Conn } from './room';
|
||||
import { RoomStore } from './store';
|
||||
|
||||
const rooms: Room[] = [];
|
||||
afterEach(() => {
|
||||
for (const r of rooms.splice(0)) r.clearTimer();
|
||||
});
|
||||
|
||||
function harness() {
|
||||
const db = openDb(':memory:');
|
||||
const store = new RoomStore(db);
|
||||
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 conn = (userId: string) => {
|
||||
const msgs: ServerMessage[] = [];
|
||||
const c: Conn & { msgs: ServerMessage[] } = { userId, msgs, send: (m) => msgs.push(m), close: () => {} };
|
||||
return c;
|
||||
};
|
||||
return { db, clock, manager, conn };
|
||||
}
|
||||
|
||||
type StateMsg = Extract<ServerMessage, { t: 'state' }>;
|
||||
const views = (c: { msgs: ServerMessage[] }) => c.msgs.filter((m): m is StateMsg => m.t === 'state').map((m) => m.view as SixNimmtView);
|
||||
|
||||
/** What the person presses, read only from their own screen (the safest-looking card, or the fewest-bulls row). */
|
||||
function personMove(v: SixNimmtView, me: string, n: number): SixNimmtAction | null {
|
||||
if (v.phase === 'draft') return v.draft!.at === me ? { type: 'DRAFT', card: v.draft!.pool[n % v.draft!.pool.length]! } : null;
|
||||
if (v.phase === 'select') {
|
||||
if (v.players[me]!.picked || !v.my) return null;
|
||||
const hand = [...v.my.hand].sort((a, b) => (a.preview?.takes ?? 0) - (b.preview?.takes ?? 0));
|
||||
return { type: 'SELECT', card: hand[n % 2 === 0 ? 0 : hand.length - 1]!.n };
|
||||
}
|
||||
const pd = v.pending;
|
||||
if (v.phase !== 'choose' || !pd || pd.player !== me) return null;
|
||||
if (pd.kind === 'place') return { type: 'PLACE', row: pd.choices[0]!.row, side: pd.choices[0]!.side };
|
||||
const best = v.rows.reduce((b, r, i) => (r.bulls < v.rows[b]!.bulls ? i : b), 0);
|
||||
return { type: 'TAKE_ROW', row: best };
|
||||
}
|
||||
|
||||
describe('젝스님트 room flow', () => {
|
||||
test.each([
|
||||
[1, {}],
|
||||
[3, { deck: 'pro', endMode: 'rounds', rounds: 2 }],
|
||||
[4, { placement: 'both', lowCard: 'choose', endMode: 'rounds', rounds: 2 }],
|
||||
] as const)('컴퓨터 %i명과 연습 %j: 사람은 자기 화면만 보고 끝까지, 컴퓨터가 고른 카드는 공개 전까지 안 보여요', (nBots, options) => {
|
||||
const h = harness();
|
||||
let room: Room;
|
||||
if (nBots === 1) room = h.manager.createPractice('A', 'six-nimmt') as Room;
|
||||
else {
|
||||
const r = h.manager.create('A', 'six-nimmt', 'private');
|
||||
if (typeof r === 'string') throw new Error(r);
|
||||
room = r;
|
||||
expect(room.configure('A', { options: { ...GAMES['six-nimmt']!.defaultOptions, ...options } })).toBeNull();
|
||||
for (let i = 0; i < nBots; i++) expect(room.addBot('A')).toBeNull();
|
||||
}
|
||||
rooms.push(room);
|
||||
const a = h.conn('A');
|
||||
room.join(a, 'player');
|
||||
expect(room.start('A')).toBeNull();
|
||||
const bots = room.game!.players.filter(isBotId);
|
||||
expect(bots).toHaveLength(nBots);
|
||||
let cs = 0;
|
||||
let seen = 0;
|
||||
let mine = 0;
|
||||
let chose = 0;
|
||||
for (let i = 0; i < 60_000 && !room.game!.finished; i++) {
|
||||
h.clock.advance(250);
|
||||
if (room.bots.dueAt !== null && room.bots.dueAt <= h.clock.now()) room.bots.fire();
|
||||
const d = room.effectiveDeadline();
|
||||
if (d !== null && d <= h.clock.now()) room.onTimer();
|
||||
const vs = views(a);
|
||||
for (const v of vs.slice(seen)) {
|
||||
// A computer's secret pick never reaches my screen before the reveal.
|
||||
for (const b of bots) expect(JSON.stringify(v)).not.toContain(`six-sel:${b}`);
|
||||
expect(v.me).toBe('A');
|
||||
}
|
||||
seen = vs.length;
|
||||
const v = vs.at(-1);
|
||||
const m = v && personMove(v, 'A', mine);
|
||||
if (m) {
|
||||
if (m.type === 'TAKE_ROW' || m.type === 'PLACE') chose++;
|
||||
room.act('A', ++cs, m);
|
||||
mine++;
|
||||
}
|
||||
}
|
||||
expect(room.game!.finished).toBe(true);
|
||||
expect(a.msgs.filter((m) => m.t === 'reject')).toEqual([]);
|
||||
const s = room.game!.state as SixNimmtState;
|
||||
expect(s.timeouts.A).toBe(0); // every step of the person was a real press
|
||||
const last = views(a).at(-1)!;
|
||||
expect(last.result!.ranking.map((r) => r.player).sort()).toEqual(['A', ...bots].sort());
|
||||
expect(last.result!.ranking[0]!.total).toBe(Math.min(...s.seats.map((p) => s.totals[p]!)));
|
||||
expect(mine).toBeGreaterThanOrEqual(10);
|
||||
if (nBots === 1) expect(chose + mine).toBeGreaterThan(10);
|
||||
const row = h.db.query<{ result_json: string }, []>('SELECT result_json FROM games').get()!;
|
||||
expect(JSON.parse(row.result_json).practice).toBe(true);
|
||||
});
|
||||
|
||||
test('시간 초과: 사람이 아무것도 안 하면 제한 시간마다 자동으로 내고 3번이면 자리 비움', () => {
|
||||
const h = harness();
|
||||
const room = h.manager.createPractice('A', 'six-nimmt') as Room;
|
||||
rooms.push(room);
|
||||
const a = h.conn('A');
|
||||
room.join(a, 'player');
|
||||
expect(room.start('A')).toBeNull();
|
||||
for (let i = 0; i < 2000; i++) {
|
||||
h.clock.advance(500);
|
||||
if (room.bots.dueAt !== null && room.bots.dueAt <= h.clock.now()) room.bots.fire();
|
||||
const d = room.effectiveDeadline();
|
||||
if (d !== null && d <= h.clock.now()) room.onTimer();
|
||||
if ((room.game!.state as SixNimmtState).timeouts.A! >= 3) break;
|
||||
}
|
||||
const s = room.game!.state as SixNimmtState;
|
||||
expect(s.timeouts.A).toBeGreaterThanOrEqual(3);
|
||||
expect(views(a).at(-1)!.players.A!.away).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user