새 게임 버건디의 성: 주사위 두 개로 육각 타일을 가져와 1번 공국을 채우는 2~4명 개인전 + 혼자 하기(2019년판 규칙), 시작 성 고르기·2011 수도원·추가 타일·여관·방패를 방 설정으로

- 데이터 packages/games/src/castles-of-burgundy/data.ts: 1번 공국 37칸(구역 13개 계산), 인원별 보급소 칸 색(3인 6번 보급소 B·D 광산), 타일 164장 + 추가 4장 + 여관 5장, 수도원 26+2종, 방패 18종, 점수표. 확인 안 된 데이터(가축 분포·검은 뒷면 수도원·장인 번호·2/3인 칸)는 UNCONFIRMED 주석으로 한 곳에
- 엔진(engine·moves·index): 페이즈 5 × 라운드 5, 일꾼 눈 바꾸기(6↔1, 수도원 8·9~12·방패 16), 가져오기·놓기·팔기·일꾼, 구역 완성·색 보너스·가축·건물 8종·배·성 연쇄를 pending 스택으로, 검은 보급소 구매(수도원 6번 2019/2011), 페이즈 끝 광산·방패 유지비·방패 14/15, 게임 끝 점수와 동점(빈칸 많은 사람 → 차례 트랙 뒤), 혼자 하기(강으로만 넓히기·목표 표시기·상품 5장 바꾸기·색 완성 보상), 시간 초과 자동 진행·자리 비움·기권
- 합법성은 actionError 하나, 합법 수는 후보를 그것으로 거름. view는 더미·다음 페이즈 상품·남의 판 상품 종류를 숨김
- 컴퓨터(bot.ts): 뷰를 상태로 되돌려 자기 차례를 미리 두고 주사위 A → B 묶음을 평가(1~20 한 수+잡음, 21~40 상위 3개, 41~60 상위 6개), 묶음은 차례 끝까지 기억. 한 수 평균 2~18ms
- 화면 apps/web/src/games/castles-of-burgundy/: PC는 가운데 판(보급소 1~6·검은 보급소·여관·남은 상품·색 보너스) + 내 공국 SVG + 오른쪽에 다른 사람 요약·작은 공국, 휴대폰은 [내 공국]/[보급소]/[다른 사람] 탭 + 아래 고정 주사위 줄. 주사위를 고르면 가져올 타일·놓을 칸·팔 상품이 빛나고 "일꾼 n" 배지, 버릴 칸·확인·내는 방법 시트, 성 보너스·배·건물·방패 등 대기 효과는 배너와 버튼. 소리·배너(구역 완성·색 완성·페이즈), 도움말·30초 요약·타일 효과 표
- 등록: GAMES·BOT_STRATEGIES·BOT_GAMES·CATALOG·GAME_UI·GAME_ICON·판·주사위 탭, docs/games/README.md, docs/games/castles-of-burgundy.md(§2 나중에 표시, §13 구현 결정)
- 나중에(데이터 필요): 팀전, 공국 2~10번(duchy), 흰 성, 무역로, 국경 초소
- 테스트: 규칙 48개(문서 §10), 무작위 대국 4가지 옵션(타일·상품 수 보존, JSON 왕복, 결정성) + 깊게 두기, 컴퓨터 3개(1단계 < 60단계), 방 통합 1개(연습 + 시간 넘김), e2e games.e2e.ts castles-of-burgundy(PC + 휴대폰 실제 행동 70번, 320px 넘침 없음, 기권으로 결과)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-16 00:06:00 +09:00
parent 8620c82ca8
commit c9f4b782e8
25 changed files with 5221 additions and 8 deletions

View File

@@ -0,0 +1,91 @@
/** 버건디의 성 through a real Room: a practice game against a computer, played from the person's own screen, with turn clocks (docs/games/castles-of-burgundy.md §8.5). */
import { afterEach, describe, expect, test } from 'bun:test';
import { GAMES } from '@bg/games';
import type { CobAction, CobState, CobView } from '@bg/games/castles-of-burgundy';
import { botProfile, isBotId, type ServerMessage } from '@bg/shared';
import { openDb } from '../db';
import { RoomManager } from './manager';
import type { Room, 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 lastView = (c: { msgs: ServerMessage[] }) => (c.msgs.filter((m): m is StateMsg => m.t === 'state').at(-1)?.view ?? null) as CobView | null;
/** What the person presses, read only from their own screen: place > take > anything but ending the turn early. */
function personMove(v: CobView): CobAction | null {
const my = v.my;
if (!my || !my.moves.length) return null;
const rank = (a: CobAction) =>
a.type === 'useDie' ? (a.act.kind === 'place' ? 0 : a.act.kind === 'take' ? 1 : 3) : a.type === 'endTurn' ? 9 : a.type === 'buy' ? 8 : 2;
let best = my.moves.map((a, i) => ({ a, i })).sort((x, y) => rank(x.a) - rank(y.a) || (my.costs[x.i] ?? 0) - (my.costs[y.i] ?? 0) || x.i - y.i)[0]!.a;
if (my.needDiscard) {
if ((best.type === 'useDie' || best.type === 'bonus') && best.act.kind === 'take') best = { ...best, act: { ...best.act, discard: 0 } };
else if ((best.type === 'buy' || best.type === 'depotTake' || best.type === 'soloTrade') && 'tile' in best) best = { ...best, discard: 0 } as CobAction;
}
return best;
}
describe('버건디의 성 room flow', () => {
test('컴퓨터와 연습: 사람은 자기 화면만 보고 두고, 가끔 시간을 넘겨도 끝까지 가요', () => {
const h = harness();
const room = h.manager.createPractice('A', 'castles-of-burgundy') as Room;
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.length).toBeGreaterThan(0);
let cs = 0;
let mine = 0;
let lastTurn = -1;
let skipTurn = false;
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 v = lastView(a);
if (!v || !v.my) continue;
if (v.turnSeq !== lastTurn) {
lastTurn = v.turnSeq;
skipTurn = v.turnSeq % 7 === 3; // now and then the person lets the clock run out
}
if (skipTurn) continue;
const m = personMove(v);
if (m) {
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 CobState;
expect(s.stage).toBe('finished');
expect(s.log.some((e) => e.t === 'end')).toBe(true);
expect(mine).toBeGreaterThan(40);
const last = lastView(a)!;
expect(last.final!.map((r) => r.player).sort()).toEqual(['A', ...bots].sort());
const row = h.db.query<{ result_json: string }, []>('SELECT result_json FROM games').get()!;
expect(JSON.parse(row.result_json).practice).toBe(true);
}, 60_000);
});