- 방 화면을 벗어나면(홈·규칙) detach: 자리·접속 상태는 유지, 방 접속 수에서 빠짐 - 컴퓨터가 있는 방: 사람이 모두 [방 나가기]하면 바로 닫고, 아무도 안 보면 대기실·끝난 방 1분, 게임 중 30분 뒤 정리 - 게스트 로그아웃 = 계정 삭제(자리·전적·세션·소켓), 사이트를 닫고 24시간 지난 게스트도 1분 주기로 삭제 - users.last_seen_at을 요청·소켓 종료 때 갱신(이전엔 갱신 안 됨), 003 마이그레이션에서 기존 게스트 시계 초기화 - 테스트: 무작위 대국 시드를 playoutSeeds()로 평소 1/10, test:full은 전부. bun test --parallel=4, 테스트 서버 종료 대기 1s→50ms Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
/** 마작 무작위 대국 ① 4인 반장전 240판(FULL_TESTS, 기본은 24판) (docs/09-game-engine.md §7.2): 끝까지 합법 진행 + 불변식. */
|
|
import { describe, expect, test } from 'bun:test';
|
|
import { playoutSeeds } from '@bg/engine';
|
|
import { emptyStats, playGame, variedOptions } from './playout';
|
|
|
|
const stats = emptyStats();
|
|
/** 240 games with FULL_TESTS, a tenth otherwise; the count thresholds below scale with it. */
|
|
const GAMES = playoutSeeds(240);
|
|
const k = GAMES / 240;
|
|
|
|
describe('무작위 대국: 4인 반장전', () => {
|
|
for (let chunk = 0; chunk * 20 < GAMES; chunk++) {
|
|
const size = Math.min(20, GAMES - chunk * 20);
|
|
test(`시드 ${0 + chunk * 20 + 1}~${0 + chunk * 20 + size}`, () => {
|
|
for (let i = 1; i <= size; i++) {
|
|
const seed = 0 + chunk * 20 + i;
|
|
playGame({ seed, players: 4, options: { length: 'hanchan', ...variedOptions(seed, 4) }, prefs: seed % 5 === 0, leaveAt: seed % 17 === 0 ? 400 : undefined, stats });
|
|
}
|
|
});
|
|
}
|
|
test('다양한 결과가 나왔고 apply는 빠르다', () => {
|
|
expect(stats.tsumo).toBeGreaterThan(50 * k);
|
|
expect(stats.ron).toBeGreaterThan(100 * k);
|
|
expect(stats.exhaustive).toBeGreaterThan(100 * k);
|
|
expect(stats.abortive).toBeGreaterThan(0);
|
|
expect(stats.riichi).toBeGreaterThan(200 * k);
|
|
expect(stats.kans).toBeGreaterThan(50 * k);
|
|
expect(Object.keys(stats.endReasons).length).toBeGreaterThanOrEqual(3);
|
|
expect(stats.applyMs / stats.applies).toBeLessThan(1);
|
|
expect(stats.maxApplyMs).toBeLessThan(25);
|
|
});
|
|
});
|