섯다 엔진·컴퓨터 다시 만듦(한게임 섯다 기준): 원 단위(시작 100만원·기본금 1만원, v1 칩 방은 ×1000으로 옮김), 2장 한 번에 받기 기본, 20/40장, 베팅 규칙 111~444, 쿼터는 옵션, 땡잡이 3·7 아무 패·멍구사 9땡까지 기본, 시간 무제한, 베팅 기록·판별 손익을 view에

컴퓨터는 남은 패를 전부 따져 보고(맞대결·3명은 모든 경우, 큰 판은 3,000판 표본) 상대 베팅으로 패 범위를 좁혀 판돈 몫과 기댓값으로 결정.
1장만 받고 하프 한 번에 다이하던 버그(고정값 0.35 패 세기와 값 비율 비교) 고침, 회귀 테스트 추가.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:35:23 +09:00
parent f12cf12b84
commit 8cde4fa525
7 changed files with 1023 additions and 143 deletions

View File

@@ -5,6 +5,7 @@ import {
chipsTotal,
evalSeotda,
resolve,
scaleMoney,
seotda,
type HandEval,
type HandRules,
@@ -25,12 +26,29 @@ const ev = (a: number, b: number, r: Partial<HandRules> = {}) => evalSeotda(a, b
let clock = 1000;
const rng = () => SeededRng.fromSeed([7, 7, 7, 7]);
/**
* Most flow tests were written for 1장씩 두 번 + 쿼터 + strict 땡잡이 + 멍구사 8땡까지 (the defaults before the 한게임
* rebuild); they keep those rules explicitly. The 한게임 defaults have their own tests below.
*/
const CLASSIC: Partial<SeotdaOptions> = { dealMode: 'twoRounds', quarter: true, ttaengjabi: 'strict', mungGusa: 'upTo8' };
/** Fresh game whose first dealer is `dealer` (seat order = players). */
function make(opts: Partial<SeotdaOptions> = {}, players = ['A', 'B', 'C'], dealer = 'A'): SeotdaState {
const options = seotda.optionsSchema.parse(opts);
/**
* The flow tests count in the old small units (시작 1,000 / 기본금 10, i.e. 원 ÷ 1000): `startingChips`/`baseUnit` given
* in those units are scaled up for the schema, and the new game is scaled back down (`scaleMoney`, the inverse of the
* v1 → v2 migration). The engine itself is unit-free.
*/
/** Options in the old small units (startingChips 500…5000, baseUnit 2…50). */
type OldOpts = Partial<Omit<SeotdaOptions, 'startingChips' | 'baseUnit'>> & { startingChips?: number; baseUnit?: number };
function make(opts: OldOpts = {}, players = ['A', 'B', 'C'], dealer = 'A'): SeotdaState {
const up = { ...opts };
if (up.startingChips !== undefined) up.startingChips *= 1000;
if (up.baseUnit !== undefined) up.baseUnit *= 1000;
const options = seotda.optionsSchema.parse({ ...CLASSIC, ...up });
for (let seed = 1; seed < 500; seed++) {
const s = seotda.setup({ players, options, rng: SeededRng.fromSeed(seedN(seed)), now: 0 });
if (s.hand!.dealer === dealer) return s;
if (s.hand!.dealer === dealer) return scaleMoney(s, 1 / 1000);
}
throw new Error('no seed with that dealer');
}
@@ -350,7 +368,7 @@ describe('재경기', () => {
expect(s.stats.rematches).toBe(1);
});
function gusaHand(opts: Partial<SeotdaOptions>) {
function gusaHand(opts: OldOpts) {
let s = make({ dealMode: 'oneRound', ...opts });
s = rig(s, { A: [P(4), S(9)], B: [S(1), P(2)], C: [P(5), P(6)] });
s = act(s, 'A', { type: 'check' });
@@ -377,7 +395,7 @@ describe('재경기', () => {
let s = gusaHand({ rejoinCost: 'full' });
expect(s.hand!.rejoinCost).toBe(30);
s.seats[2]!.stack = 20;
expect(reject(s, 'C', { type: 'rejoin', accept: true })).toBe('칩이 모자라 재참가할 수 없어요.');
expect(reject(s, 'C', { type: 'rejoin', accept: true })).toBe('보유 금액이 모자라 재참가할 수 없어요.');
expect(seotda.legalActions!(s, 'C')).toEqual([{ type: 'rejoin', accept: false }]);
s = act(s, 'C', { type: 'timeout' });
expect(s.hand!.order).toEqual(['A', 'B']);
@@ -547,7 +565,7 @@ describe('timeouts, away, leaving', () => {
describe('rebuy, elimination, scores', () => {
/** Ends the current hand by folds, then sets stacks before the hand-end processing. */
function toHandEnd(opts: Partial<SeotdaOptions>, players = ['A', 'B', 'C']): SeotdaState {
function toHandEnd(opts: OldOpts, players = ['A', 'B', 'C']): SeotdaState {
let s = make({ dealMode: 'oneRound', ...opts }, players);
while (s.hand!.phase !== 'handEnd') s = act(s, seotda.activePlayers(s)[0]!, { type: 'die' });
return s;
@@ -617,10 +635,132 @@ describe('rebuy, elimination, scores', () => {
});
});
describe('한게임 방식 (원 단위, 기본 설정)', () => {
/** A game with the real options (no CLASSIC rules, no unit scaling). */
function hg(opts: Partial<SeotdaOptions> = {}, players = ['A', 'B', 'C'], dealer = 'A'): SeotdaState {
const options = seotda.optionsSchema.parse(opts);
for (let seed = 1; seed < 500; seed++) {
const s = seotda.setup({ players, options, rng: SeededRng.fromSeed(seedN(seed)), now: 0 });
if (s.hand!.dealer === dealer) return s;
}
throw new Error('no seed with that dealer');
}
test('2장을 한 번에 받고 한 번 베팅한 뒤 공개, 금액은 원 (기본금 1만원 × 3명 = 판돈 3만원)', () => {
let s = hg();
expect(Object.values(s.hand!.cards).map((c) => c.length)).toEqual([2, 2, 2]);
const v = seotda.view(s, 'A');
expect([v.pot, v.baseUnit, v.seats[0]!.stack]).toEqual([30_000, 10_000, 990_000]);
expect(v.legal.map((l) => l.type)).toEqual(['check', 'ping', 'half', 'die']); // 쿼터는 한게임에 없어 기본으로 꺼 둠
for (const p of ['A', 'B', 'C']) s = act(s, p, { type: 'check' });
expect(s.hand!.phase).toBe('handEnd');
expect(s.hand!.showdown).not.toBeNull();
});
test('베팅 규칙 222: 선과 다음 사람은 첫 베팅에서 하프·다이만, 그 뒤는 자유', () => {
let s = hg({ betRule: '222' });
const v = seotda.view(s, 'A');
expect(v.forcedHalf).toBe(true);
expect(v.legal.map((l) => l.type)).toEqual(['half', 'die']);
expect(reject(s, 'A', { type: 'check' })).toBe('베팅 규칙 222: 지금은 하프 또는 다이만 할 수 있어요.');
s = act(s, 'A', { type: 'half' });
expect(seotda.view(s, 'B').legal.map((l) => l.type)).toEqual(['half', 'die']);
s = act(s, 'B', { type: 'half' });
const c = seotda.view(s, 'C');
expect(c.forcedHalf).toBe(false);
expect(c.legal.map((l) => l.type)).toEqual(['call', 'ddadang', 'half', 'die']);
expect(c.betLog.map((e) => [e.p, e.t])).toEqual([
['A', 'half'],
['B', 'half'],
]);
});
test('베팅 규칙 111: 선이 시간을 넘기면 체크가 아니라 다이', () => {
let s = hg({ betRule: '111' });
s = act(s, 'A', { type: 'timeout' }, 21_000);
expect(s.hand!.lastAction.A!.type).toBe('die');
});
test('쿼터를 켠 방만 쿼터를 받음', () => {
const off = hg();
expect(reject(off, 'A', { type: 'quarter' })).toBe('이 방은 쿼터 베팅을 쓰지 않아요.');
const on = hg({ quarter: true });
expect(seotda.view(on, 'A').legal.map((l) => l.type)).toContain('quarter');
});
test('40장: 1~10월 4장 모두 쓰고, 3장 섯다도 10명까지', () => {
const s = hg({ deck: 40 });
const all = [...s.hand!.deck, ...Object.values(s.hand!.cards).flat()].sort((a, b) => a - b);
expect(all).toEqual(Array.from({ length: 40 }, (_, i) => i));
expect(seotda.playersFor!({ ...seotda.defaultOptions, deck: 40, cardMode: 'three' })).toEqual({ min: 2, max: 10 });
});
test('행동 제한 시간 무제한: 베팅·고르기에 마감이 없고, 판 결과 화면만 시간이 흐름', () => {
let s = hg({ turnSeconds: null });
expect(s.deadlineAt).toBeNull();
for (const p of ['A', 'B', 'C']) s = act(s, p, { type: 'check' });
expect(s.hand!.phase).toBe('handEnd');
expect(s.deadlineAt).not.toBeNull();
const three = hg({ turnSeconds: null, cardMode: 'three' });
let t = three;
for (const p of ['A', 'B', 'C']) t = act(t, p, { type: 'check' });
expect(t.hand!.phase).toBe('choose');
expect(t.deadlineAt).toBeNull();
});
test('판이 끝나면 각자 얼마를 따고 잃었는지(handDelta)', () => {
let s = hg();
s = act(s, 'A', { type: 'half' }); // 1만 5천원
s = act(s, 'B', { type: 'die' });
s = act(s, 'C', { type: 'die' });
const v = seotda.view(s, null);
expect(v.foldWin).toEqual({ winner: 'A', amount: 30_000 });
expect(v.seats.map((x) => x.handDelta)).toEqual([20_000, -10_000, -10_000]);
});
test('v1(칩) 방 상태를 v2(원)로 옮김: 금액 × 1000, 진행 중 규칙은 그대로(쿼터 켬, 20장, 일반 베팅)', () => {
let s = make({ dealMode: 'twoRounds' }); // old units: 시작 1,000 / 학교 10
s = act(s, 'A', { type: 'half' });
const v1 = structuredClone(s) as unknown as Record<string, unknown>;
const o = { ...(v1.options as Record<string, unknown>) };
delete o.deck;
delete o.betRule;
delete o.quarter;
v1.options = o;
const h = v1.hand as Record<string, unknown>;
delete h.forced;
delete h.log;
const m = seotda.migrate!(v1, 1);
expect(seotda.stateVersion).toBe(2);
expect([m.options.startingChips, m.options.baseUnit, m.baseUnit]).toEqual([1_000_000, 10_000, 10_000]);
expect(m.options).toMatchObject({ deck: 20, betRule: 'free', quarter: true });
expect(m.seats.map((x) => x.stack)).toEqual(s.seats.map((x) => x.stack * 1000));
expect(chipsTotal(m)).toBe(chipsTotal(s) * 1000);
expect(seotda.view(m, 'B').legal.find((l) => l.type === 'call')!.amount).toBe(15_000);
expect(m.hand!.log).toEqual([]);
});
});
describe('options', () => {
test('schema defaults and validation', () => {
expect(seotda.defaultOptions).toMatchObject({ cardMode: 'two', dealMode: 'twoRounds', startingChips: 1000, baseUnit: 10, rebuy: 'unlimited' });
expect(seotda.optionsSchema.safeParse({ startingChips: 500, baseUnit: 50 }).success).toBe(false);
// 한게임 섯다처럼: 2장을 한 번에 받고 한 번 베팅, 20장, 일반 베팅, 쿼터 없음, 땡잡이 3·7 아무 패, 멍구사 9땡까지, 원 단위.
expect(seotda.defaultOptions).toMatchObject({
cardMode: 'two',
dealMode: 'oneRound',
deck: 20,
betRule: 'free',
quarter: false,
ttaengjabi: 'loose',
mungGusa: 'upTo9',
startingChips: 1_000_000,
baseUnit: 10_000,
rebuy: 'unlimited',
turnSeconds: 20,
});
expect(seotda.optionsSchema.safeParse({ startingChips: 500_000, baseUnit: 50_000 }).success).toBe(false);
expect(seotda.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
// Rooms saved with the old chip options fall back to the defaults instead of failing.
expect(seotda.optionsSchema.parse({ startingChips: 1000, baseUnit: 10 })).toMatchObject({ startingChips: 1_000_000, baseUnit: 10_000 });
expect(seotda.playersFor!({ ...seotda.defaultOptions, cardMode: 'three' })).toEqual({ min: 2, max: 6 });
expect(seotda.playersFor!(seotda.defaultOptions)).toEqual({ min: 2, max: 10 });
expect(() => seotda.setup({ players: 'ABCDEFG'.split(''), options: { ...seotda.defaultOptions, cardMode: 'three' }, rng: rng(), now: 0 })).toThrow();
@@ -650,8 +790,10 @@ describe('random playouts', () => {
['기본', {}, 4, 4],
['2장 한 번에·나눔·풀', { dealMode: 'oneRound', tieRule: 'split', maxRaise: 'full' }, 5, 3],
['3장 섯다·재참가 절반', { cardMode: 'three', rejoinCost: 'half', ttaengjabi: 'loose' }, 6, 3],
['최후 1인·리바이 없음·회전', { endCondition: 'lastStanding', rebuy: 'off', dealerRule: 'rotate', baseUnit: 50, startingChips: 1000 }, 3, 4],
['10명·전액 재참가', { rejoinCost: 'full', mungGusa: 'upToJang', handLimit: 10, startingChips: 500, baseUnit: 2 }, 10, 2],
['최후 1인·리바이 없음·회전', { endCondition: 'lastStanding', rebuy: 'off', dealerRule: 'rotate', baseUnit: 50_000, startingChips: 1_000_000 }, 3, 4],
['10명·전액 재참가', { rejoinCost: 'full', mungGusa: 'upToJang', handLimit: 10, startingChips: 500_000, baseUnit: 2_000 }, 10, 2],
['1장씩·쿼터·베팅 규칙 333', { dealMode: 'twoRounds', quarter: true, betRule: '333' }, 5, 3],
['40장·3장 섯다·8명', { deck: 40, cardMode: 'three', betRule: '111' }, 8, 2],
['2명·학교 상승·제한 리바이', { schoolUpEvery: 5, rebuy: 'limited', rebuyLimit: 2, handLimit: 30 }, 2, 4],
];
test.each(configs)('%s: finishes, chips conserved, no leaks, deterministic', (_n, opts, n, runs) => {
@@ -673,7 +815,12 @@ describe('random playouts', () => {
for (let seed = 1; seed <= LEAK_SEEDS; seed++) {
const n = 2 + (seed % 5);
const players = Array.from({ length: n }, (_, i) => `P${i}`);
const options = seotda.optionsSchema.parse({ cardMode: seed % 3 === 0 ? 'three' : 'two', dealMode: seed % 4 === 1 ? 'oneRound' : 'twoRounds' });
const options = seotda.optionsSchema.parse({
cardMode: seed % 3 === 0 ? 'three' : 'two',
dealMode: seed % 4 === 1 ? 'oneRound' : 'twoRounds',
deck: seed % 7 === 0 ? 40 : 20,
betRule: seed % 5 === 2 ? '222' : 'free',
});
const r = SeededRng.fromSeed(seedN(seed));
const chooser = SeededRng.fromSeed(seedN(seed + 77));
let s = seotda.setup({ players, options, rng: r, now: 0 });