야단법석 달리기(Magical Athlete): 규칙·컴퓨터 상대·화면·도움말·문서·E2E

- 규칙 모듈 packages/games/src/magical-athlete: 선수 24명(능력 처리 순서가 하나로 정해지는 선수만),
  뱀 순서 뽑기(2~3명은 선수 8명·경주마다 둘, 4~6명은 4명·하나), 몰래 동시에 출전 선수 고르기,
  경주 4번(순한 판·거친 판 번갈아, 거친 판은 화살표·돌·별 칸), 1등 3점·2등 1점(갈수록 커지는 점수표 옵션).
  능력 처리 순서 고정: 칸 효과 → 차례인 사람 → 시계 방향, 연쇄는 줄 끝, 선수당 한 차례 5번, 두 번째 도착 즉시 종료,
  경주 차례 상한. 시간 초과는 안전한 기본값(능력 안 씀), 나간 사람 선수는 자동으로 끝까지.
- 컴퓨터: 평가값 뽑기, 칸 수 기대 이득으로 능력 판단, 레벨별 실수.
- 화면: 뱀 모양 경주로 SVG(PC 11칸·휴대폰 8칸 줄), 말 이동 애니메이션, 능력 버튼, 경주 기록, 결과 표,
  도움말·30초 요약. 판이 화면보다 길면 위에서 시작(가운데 정렬이면 위가 잘려 고르기 카드를 못 누름).
- 등록(GAMES, CATALOG, BOT_GAMES, BOT_STRATEGIES, 화면 레지스트리, 아이콘·판 탭), 문서 docs/games/magical-athlete.md.
- 테스트: 규칙·능력·순서 42개(문서 예시 포함), 컴퓨터 10개, 도움말 2개, 방 통합 2개(컴퓨터 1·3명과 끝까지),
  E2E(PC 방장 + 휴대폰, 실제 뽑기·고르기·굴리기·능력으로 네 경주 끝까지).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 03:45:09 +09:00
parent 65c56d3ae7
commit 71381087cc
23 changed files with 4019 additions and 2 deletions

View File

@@ -1078,6 +1078,57 @@ async function liarShots(pages: Page[], name: string, dark = false) {
await phone.emulateMedia({ colorScheme: 'light' });
}
/**
* 야단법석 달리기: one UI step for `p` — draft a racer card (the PC host's first pick by keyboard), pick racers for the
* race and press "… 내보내기", or press one of the turn buttons (주사위 굴리기 / 능력 쓰기 / 먼저 갈 선수).
* Every third turn choice takes the second button so optional powers and "skip" are both used.
*/
async function magicalStep(p: Page, phone: boolean, st: { picks: number; selects: number; acts: number; keyboard: boolean; second: number }): Promise<boolean> {
const press = (l: ReturnType<Page['locator']>) => (phone ? l.tap({ timeout: 1500 }) : l.click({ timeout: 1500 }));
try {
const draft = p.locator('section[aria-label="선수 뽑기"] button.ma-card:not([disabled])');
const nd = await draft.count();
if (nd) {
if (!phone && !st.keyboard) {
await draft.first().focus();
await p.keyboard.press('Enter');
st.keyboard = true;
} else await press(draft.nth(st.picks % nd));
st.picks++;
await p.waitForTimeout(120);
return true;
}
const sel = p.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled])');
if (await sel.count()) {
const head = await p.locator('section[aria-label="출전 선수 고르기"] h3').innerText();
const need = Number(/선수 (\d)명/.exec(head)?.[1] ?? 1);
// Only press cards that are not chosen yet, so a retry after a slow screen never un-chooses one.
const chosen = await p.locator('section[aria-label="출전 선수 고르기"] button.ma-card[aria-pressed="true"]').count();
const free = p.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled]):not([aria-pressed="true"])');
for (let k = chosen; k < need; k++) await press(free.first());
const go = p.getByRole('button', { name: /내보내기$/ });
await go.waitFor({ timeout: 3000 });
await press(go);
st.selects++;
await p.locator('section[aria-label="출전 선수 고르기"]', { hasText: '내가 고른 선수' }).or(p.locator('section[aria-label="경주로"]')).first().waitFor({ timeout: 5000 });
return true;
}
const opts = p.locator('section[aria-label="내 차례 할 일"] .ma-opts button:not([disabled])');
const n = await opts.count();
if (n) {
const i = st.acts % 3 === 2 && n > 1 ? 1 : 0;
if (i === 1) st.second++;
await press(opts.nth(i));
st.acts++;
await p.waitForTimeout(150);
return true;
}
} catch {
return false;
}
return false;
}
const PLANS: Record<string, Plan> = {
rummikub: {
// PC host + phone guest, first meld "없음" so hint plays happen early; 10 real turns through the UI.
@@ -2761,6 +2812,71 @@ const PLANS: Record<string, Plan> = {
await guest.screenshot({ path: join(SHOTS, 'clue-result-phone.png') });
if ((st.suggest ?? 0) < 8 || !st.roll || !st.enter || !st.accuse || !privacy) throw new Error(`too few real turns: ${JSON.stringify(st)}`);
console.log(` clue: finished after ${actions} UI actions ${JSON.stringify(Object.fromEntries(Object.entries(st).filter(([k]) => !k.startsWith('shot'))))}`);
},
},
'magical-athlete': {
// PC host + phone guest: 2 players → 8 racers each (snake draft ×4), two racers per race. Real draft, secret picks,
// rolls and power choices through the UI until all four races are over (2nd and 4th on the wild track).
drive: async (pages) => {
const [host, guest] = pages as [Page, Page];
const st = { picks: 0, selects: 0, acts: 0, keyboard: false, second: 0 };
const shots = new Set<string>();
let power = false;
let wild = false;
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
const until = Date.now() + 420_000;
while (Date.now() < until && !(await over())) {
if (!shots.has('draft') && (await host.locator('section[aria-label="선수 뽑기"]').count()) && st.picks >= 3) {
shots.add('draft');
await host.screenshot({ path: join(SHOTS, 'magical-athlete-draft-pc.png') });
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-draft-phone.png'), fullPage: true });
}
if (!shots.has('select') && (await guest.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled])').count())) {
shots.add('select');
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-select-phone.png'), fullPage: true });
}
let acted = false;
for (const [i, p] of pages.entries()) {
if (await magicalStep(p, i > 0, st)) {
acted = true;
break;
}
}
if (!power && (await host.locator('.ma-log li.power').count())) power = true;
if (!wild && (await host.locator('.ma-side-tag.wild').count())) wild = true;
if (!shots.has('race') && st.acts >= 20 && (await host.locator('section[aria-label="경주로"]').count())) {
shots.add('race');
await host.screenshot({ path: join(SHOTS, 'magical-athlete-race-pc.png') });
await guest.evaluate(() => window.scrollTo(0, 0));
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-race-phone.png') });
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-race-phone-full.png'), fullPage: true });
await host.emulateMedia({ colorScheme: 'dark' });
await host.waitForTimeout(250);
await host.screenshot({ path: join(SHOTS, 'magical-athlete-race-pc-dark.png') });
await host.emulateMedia({ colorScheme: 'light' });
}
if (wild && !shots.has('wild') && (await host.locator('section[aria-label="경주로"]').count())) {
shots.add('wild');
await host.waitForTimeout(400);
await host.screenshot({ path: join(SHOTS, 'magical-athlete-wild-pc.png') });
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-wild-phone.png') });
}
if (!acted) await host.waitForTimeout(150);
}
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify(st)})`);
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
await host.waitForTimeout(600);
await host.screenshot({ path: join(SHOTS, 'magical-athlete-result-pc.png') });
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-result-phone.png') });
await host.keyboard.press('Escape');
await host.locator('section[aria-label="최종 결과"]').waitFor();
await host.screenshot({ path: join(SHOTS, 'magical-athlete-final-pc.png'), fullPage: true });
const rows = await host.locator('section[aria-label="경주 결과"] tbody tr').count();
if (rows !== 4) throw new Error(`expected 4 race results, saw ${rows}`);
if (!power) throw new Error('no racer power was logged');
if (!wild) throw new Error('never raced on the wild track');
if (st.picks !== 16 || st.selects < 6 || st.acts < 40 || !st.keyboard || st.second < 5) throw new Error(`too few real steps: ${JSON.stringify(st)}`);
console.log(` magical-athlete: ${st.picks} picks, ${st.selects} race picks, ${st.acts} turn choices (${st.second} second options), powers + wild track seen`);
},
},
};