- 규칙 모듈 packages/games/src/old-maid: 2~8명, 트럼프 52장 + 조커 1장을 첫 사람(무작위)부터 한 장씩 나누고 같은 숫자 짝은 자동으로 버림. 차례에는 다음 자리(왼쪽)의 카드 있는 사람 손패에서 자리(index)로 한 장 뽑기(from 함께 보내 대상이 바뀌면 거절), 짝이 없으면 내 손패 무작위 자리에 숨김. 다 턴 순서대로 순위, 마지막 조커를 든 사람이 도둑(꼴찌). 결과 scoreText 에 "🃏 도둑"/"다 털었어요"/"나감" 표시. - 내 손패 섞기: 남은 사람 누구나 언제든, 차례마다 3번까지, 시계는 그대로. 남에게 보이는 자리는 실제 손패 순서이고, view 에는 남의 손패 장수만(뽑은 카드는 뽑은 사람에게만). - 시간 초과는 무작위 한 장 뽑기(3번 연속이면 5초), 카드를 든 채 나가면 그 카드를 섞어 다음 자리부터 한 장씩 나눠 주고 짝을 버림, 나간 사람은 맨 아래. 둘만 남았을 때 나가면 도둑 없이 끝. - 컴퓨터 상대(BOT_GAMES): 단계와 관계없이 무작위로 뽑고 가끔(15%) 자기 손패를 먼저 섞음. - 화면 apps/web/src/games/old-maid: 뽑힐 사람의 뒷면 카드를 펼쳐 고르기(tapConfirm 이면 두 번 눌러 확인, PC 한 번, 키보드 방향키+Enter), 섞으면 흔들림, 지난 뽑기·버린 짝, 내 손패(조커 표시)와 [🔀 섞기], 조커를 넘기면 알림. 30초 요약, 지금 할 수 있는 것, 규칙. - 등록(GAMES, 카탈로그, BOT_GAMES·전략, 화면 레지스트리, 아이콘·카드 탭), 도움말 테스트 게임 수 27, 문서 docs/games/old-maid.md, E2E 계획(PC 1 + 휴대폰 2, 끝까지). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import { SeededRng, seedN } from '@bg/engine';
|
|
import { decideBotAction } from '../bots/index';
|
|
import { botPlayout } from '../bots/playout';
|
|
import { oldMaid as game, type OldMaidState } from './index';
|
|
import { SHUFFLE_CHANCE } from './bot';
|
|
|
|
const setup = (players: string[], seed = 1): OldMaidState =>
|
|
game.setup({ players, options: game.defaultOptions, rng: SeededRng.fromSeed(seedN(seed)), now: 0 });
|
|
const decide = (s: OldMaidState, p: string, r: number) => decideBotAction(game, s, p, { now: 0, random: () => r }) as Record<string, unknown>;
|
|
|
|
describe('old-maid bot', () => {
|
|
test('draws a card from the neighbour it must draw from, at any spot', () => {
|
|
const s = setup(['bot:1:x', 'B', 'C']);
|
|
s.turn = 'bot:1:x';
|
|
const from = 'B';
|
|
const n = s.hands.B!.length;
|
|
const spots = new Set<number>();
|
|
for (const r of [0.2, 0.4, 0.6, 0.8, 0.99]) {
|
|
const a = decide(s, 'bot:1:x', r);
|
|
expect(a).toMatchObject({ type: 'draw', from });
|
|
spots.add(a.index as number);
|
|
}
|
|
expect(spots.size).toBeGreaterThan(2);
|
|
expect(Math.max(...spots)).toBeLessThan(n);
|
|
});
|
|
|
|
test('now and then shuffles its own hand first, but only once a turn', () => {
|
|
let s = setup(['bot:1:x', 'B', 'C']);
|
|
s.turn = 'bot:1:x';
|
|
expect(decide(s, 'bot:1:x', SHUFFLE_CHANCE / 2)).toEqual({ type: 'shuffle' });
|
|
s = game.apply(s, 'bot:1:x', { type: 'shuffle' }, { rng: SeededRng.fromSeed([1, 2, 3, 4]), now: 1 }).state;
|
|
expect(decide(s, 'bot:1:x', SHUFFLE_CHANCE / 2).type).toBe('draw');
|
|
});
|
|
|
|
for (const n of [2, 5, 8]) {
|
|
test(`bots finish a game: ${n} players`, () => {
|
|
const players = ['h', ...Array.from({ length: n - 1 }, (_, i) => `bot:${i + 1}`)];
|
|
for (let seed = 1; seed <= 3; seed++) {
|
|
const r = botPlayout(game as never, { players, seed: seedN(seed), isBot: (p) => p.startsWith('bot:') });
|
|
expect(r.finished).toBe(true);
|
|
expect(r.botTimeouts).toBe(0);
|
|
}
|
|
});
|
|
}
|
|
});
|