Files
joke-app/packages/games/src/solitaire/bot.test.ts
EJClaw 1b9acb9fc1 새 게임 5개(같은 판 경주): 지뢰찾기, 사천성, 솔리테어, 스도쿠, 네모네모 로직
- 공통 틀 race: 같은 시드 판을 모두 각자 동시에, 3초 카운트다운, 제한 시간/무제한, 포기, 다 푼 시간 → 푼 만큼 순위, live 컴퓨터
- 지뢰찾기: 초급·중급·고급, 모두에게 같은 곳이 열린 채 시작, 깃발·한꺼번에 열기, 휴대폰 길게 누르기·깃발 모드
- 사천성: 마작패 72·112·136장, 두 번 이하로 꺾이는 선, 항상 풀리는 배치, 막히면 자동 섞기, 힌트
- 솔리테어: 클론다이크(1장·3장)·프리셀·스파이더(1·2·4무늬), 되돌리기, 자동 정리
- 스도쿠: 답이 하나인 문제 생성기(쉬움·보통·어려움), 메모, 겹침 표시, 힌트
- 네모네모 로직: 그림 37개(5×5·10×10·15×15, 모두 줄 논리만으로 풀림), 드래그 칠하기·X 표시, 풀면 그림과 이름
- 게임 46개, 컴퓨터 상대 42개, 게임 고르기에 혼자·퍼즐 탭
(아발론·모노레일은 아직 공개 전이라 이 배포에서 뺌; 작업 갈래 codex/owner/grp_discord_joke-app 2773f5c..에서 옮김)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:29:01 +09:00

75 lines
3.6 KiB
TypeScript

/** 솔리테어 computers (docs/games/solitaire.md §13): never refused, always finish (no endless loops), stronger levels do better. */
import { describe, expect, test } from 'bun:test';
import { seedN } from '@bg/engine';
import { liveBotPlayout } from '../bots/live-playout';
import { chooseMove, scoreMove, solitaireBot } from './bot';
import { solitaire, type SolitaireBoardView, type SolitaireOptions, type SolitaireState } from './index';
const isBot = (p: string) => p.startsWith('bot:');
const MODES: Partial<SolitaireOptions>[] = [{ mode: 'klondike', draw: 1 }, { mode: 'klondike', draw: 3 }, { mode: 'freecell' }, { mode: 'spider', suits: 1 }, { mode: 'spider', suits: 4 }];
describe('solitaire · 한 판 전체', () => {
test('사람(가만히) + 컴퓨터, 컴퓨터끼리만(무제한): 거절 0, 모두 끝까지, 빠른 판단', () => {
for (const [k, o] of MODES.entries()) {
for (const humans of [1, 0]) {
const n = 2 + k % 2;
const players = Array.from({ length: n }, (_, i) => (i < humans ? `human${i}` : `bot:${i + 1}:s${k}${i}`));
const r = liveBotPlayout(solitaire, solitaireBot, {
players,
options: solitaire.optionsSchema.parse({ ...o, timeLimitSec: humans ? 900 : null }),
seed: seedN(k * 10 + humans),
isBot,
levelOf: (p) => 1 + ((p.length * 7 + k * 13) % 60),
});
expect(r.finished).toBe(true);
expect(r.rejected).toEqual([]);
expect(r.maxBotMs).toBeLessThan(50);
const s = r.state as SolitaireState;
if (!humans) for (const p of players) expect(['solved', 'done']).toContain(s.status[p]!);
}
}
});
test('강한 컴퓨터가 약한 컴퓨터보다 평균적으로 더 많이 올려요(같은 패)', () => {
const total = { easy: 0, hard: 0 };
for (let k = 0; k < 12; k++) {
const r = liveBotPlayout(solitaire, solitaireBot, {
players: ['bot:1:easy', 'bot:2:hard'],
options: solitaire.optionsSchema.parse(MODES[k % MODES.length]),
seed: seedN(700 + k),
isBot,
levelOf: (p) => (p.endsWith('easy') ? 3 : 58),
});
const s = r.state as SolitaireState;
const prog = (p: string) => solitaire.view(s, p).seats.find((x) => x.id === p)!.progress;
total.easy += prog('bot:1:easy');
total.hard += prog('bot:2:hard');
}
expect(total.hard).toBeGreaterThan(total.easy);
});
test('먼저 파운데이션, 다음 뒤집힌 카드를 여는 수; 같은 자리에서 같은 수는 두 번 하지 않아요', () => {
const v: SolitaireBoardView = {
mode: 'klondike',
draw: 1,
t: [[null, '9H'], ['TS'], ['AD'], [], [], [], []],
stock: 3,
waste: [],
cells: [],
f: ['', '', '', ''],
done: '',
canUndo: false,
undos: 0,
};
expect(scoreMove(v, { type: 'move', from: 't2', n: 1, to: 'f' })).toBeGreaterThan(scoreMove(v, { type: 'move', from: 't0', n: 1, to: 't1' }));
expect(scoreMove(v, { type: 'move', from: 't0', n: 1, to: 't1' })).toBeGreaterThan(scoreMove(v, { type: 'draw' }));
const mem = {};
expect(chooseMove(v, 0, () => 0, mem)).toEqual({ type: 'move', from: 't2', n: 1, to: 'f' });
expect(chooseMove(v, 0, () => 0, mem)).toEqual({ type: 'move', from: 't0', n: 1, to: 't1' });
expect(chooseMove(v, 0, () => 0, mem)).toEqual({ type: 'draw' });
// Nothing left to try on this screen → give up.
expect(chooseMove({ ...v, stock: 0 }, 0, () => 0, { tried: {} })).not.toEqual({ type: 'stop' });
expect(chooseMove({ ...v, t: [['KS'], [], [], [], [], [], []], stock: 0 }, 0, () => 0, {})).toEqual({ type: 'stop' });
});
});