커넥트 포(사목) 규칙·컴퓨터 상대·화면·테스트
- 규칙 모듈 packages/games/src/connect-four: 7×6 기본, 8×7·9×7 판, 열을 고르면 맨 아래 빈칸으로 떨어짐, 가로·세로·대각선 4개(이상) 즉시 승리(이긴 줄 전부 기록), 판이 차면 무승부. 먼저 두는 사람은 오목·오셀로와 같은 관례(무작위/방장 먼저/방장 나중/판마다 번갈아 — gameNo). 시간: 한 수당·피셔·없음, 시간 초과 자동 두기(승리 > 막기 > 위 칸을 내주지 않는 가운데 열), 허용 횟수 넘으면 시간패, 기권·나가기. - 컴퓨터 상대: 네가맥스 알파베타 + 반복 심화 + 치환표, 바로 이기기/막기·강제 수 판정, 열린 줄과 홀짝 줄 위협을 증분 평가. 레벨 1~60에 따라 1~10수 읽기(어려움은 빈칸 24개부터 끝까지 시도), 국면 5만 개 상한으로 한 수 평균 수 ms·최악 수십 ms. humanBest로 사람 같은 실수, 낮은 단계는 4목 막기를 가끔 놓침. - 화면 apps/web/src/games/connect-four: 구멍 뚫린 파란 판(마스크), 떨어지는 애니메이션(움직임 줄이기 존중), 이긴 줄 강조, 열 전체 터치 영역, 키보드 ←·→·Home·End·Enter, 스크린리더 안내, 다크 모드, 30초 요약·도움말. - 등록: GAMES, CATALOG, BOT_GAMES, BOT_STRATEGIES, NO_LUCK, 화면 레지스트리, 아이콘·판 탭, 공통 테스트 목록. - 문서 docs/games/connect-four.md, 목록 한 줄. E2E 계획(PC 키보드 + 휴대폰 터치, 꽉 찬 열 무시, 끝까지). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1208,6 +1208,80 @@ const PLANS: Record<string, Plan> = {
|
||||
// cursor starts at d4 (3,3): black d3 = up; then white c3 = up, left
|
||||
moves: [['ArrowUp', 'Enter'], ['ArrowUp', 'ArrowLeft', 'Enter']],
|
||||
},
|
||||
'connect-four': {
|
||||
// 방장(PC, 빨강, 먼저)은 키보드(Home → 오른쪽 화살표 → Enter)로, 친구(휴대폰, 노랑)는 열을 직접 눌러서 둔다.
|
||||
// 1열을 끝까지 채운 뒤 친구가 꽉 찬 1열을 눌러도 아무 일이 없는지 보고, 빨강이 맨 아래 줄 다섯 개(1~5열)로 이긴다.
|
||||
lobby: async (host) => {
|
||||
await host.getByRole('button', { name: '방장이 먼저', exact: true }).click();
|
||||
await host.getByText(/방장 먼저/).first().waitFor();
|
||||
},
|
||||
drive: async (pages) => {
|
||||
const [host, guest] = pages as [Page, Page];
|
||||
const grid = (p: Page) => p.locator('svg[role="grid"]').first();
|
||||
await grid(host).waitFor();
|
||||
await grid(guest).waitFor();
|
||||
const discs = (p: Page) => p.locator('svg[role="grid"] circle[r="0.41"]').count();
|
||||
const myTurn = (p: Page) => p.waitForFunction(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 10_000 });
|
||||
const waitDiscs = async (n: number) => {
|
||||
for (const p of pages) await p.waitForFunction((k) => document.querySelectorAll('svg[role="grid"] circle[r="0.41"]').length >= k, n, { timeout: 10_000 });
|
||||
};
|
||||
const hostDrop = async (col: number) => {
|
||||
await myTurn(host);
|
||||
await grid(host).focus();
|
||||
await host.keyboard.press('Home');
|
||||
for (let i = 0; i < col; i++) await host.keyboard.press('ArrowRight');
|
||||
await host.keyboard.press('Enter');
|
||||
};
|
||||
const guestDrop = async (col: number) => {
|
||||
await myTurn(guest);
|
||||
await guest.locator(`svg[role="grid"] rect[data-col="${col}"]`).tap();
|
||||
const confirm = guest.getByRole('button', { name: `${col + 1}열에 넣기` });
|
||||
if (await confirm.isVisible().catch(() => false)) await confirm.click();
|
||||
};
|
||||
// 0-based columns: red 0, yellow 0, … fills column 1 (빨노빨노빨노), then the bottom-row fight.
|
||||
const plan: ['h' | 'g', number][] = [['h', 0], ['g', 0], ['h', 0], ['g', 0], ['h', 0], ['g', 0], ['h', 3], ['g', 3], ['h', 2], ['g', 2], ['h', 4], ['g', 4], ['h', 1]];
|
||||
let n = 0;
|
||||
for (const [who, col] of plan) {
|
||||
if (who === 'g' && n === 7) {
|
||||
// Column 1 is full: tapping it does nothing (still the guest's turn, same number of discs).
|
||||
await myTurn(guest);
|
||||
await guest.locator('svg[role="grid"] rect[data-col="0"]').tap();
|
||||
await guest.waitForTimeout(400);
|
||||
if ((await discs(guest)) !== 7) throw new Error('a disc went into the full column');
|
||||
if (!(await guest.locator('.turn-status').innerText()).includes('내 차례예요')) throw new Error('turn passed after tapping a full column');
|
||||
}
|
||||
await (who === 'h' ? hostDrop(col) : guestDrop(col));
|
||||
n++;
|
||||
await waitDiscs(n);
|
||||
if (n === 10) {
|
||||
await host.waitForTimeout(500);
|
||||
await host.screenshot({ path: join(SHOTS, 'connect-four-mid-pc.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone-full.png'), fullPage: true });
|
||||
await host.emulateMedia({ colorScheme: 'dark' });
|
||||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||||
await host.waitForTimeout(300);
|
||||
await host.screenshot({ path: join(SHOTS, 'connect-four-mid-pc-dark.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone-dark.png') });
|
||||
await host.emulateMedia({ colorScheme: 'light' });
|
||||
await guest.emulateMedia({ colorScheme: 'light' });
|
||||
}
|
||||
}
|
||||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||||
const rings = await host.locator('svg[role="grid"] circle.c4-win').count();
|
||||
if (rings !== 5) throw new Error(`expected the 5-disc line lit, got ${rings}`);
|
||||
await host.waitForTimeout(600);
|
||||
await host.screenshot({ path: join(SHOTS, 'connect-four-result-pc.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'connect-four-result-phone.png') });
|
||||
const summary = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||||
if (!summary.includes('빨강 승 (5개 연결, 13수)')) throw new Error(`unexpected result: ${summary.slice(0, 120)}`);
|
||||
// Close the result to look at the lit line.
|
||||
await host.keyboard.press('Escape');
|
||||
await host.waitForTimeout(400);
|
||||
await host.screenshot({ path: join(SHOTS, 'connect-four-final-board-pc.png') });
|
||||
console.log(` connect-four: ${n} drops (keyboard + taps), full column refused, ${summary.split('\n').find((l) => l.includes('빨강 승'))}`);
|
||||
},
|
||||
},
|
||||
chess: {
|
||||
// cursor starts on the e-file pawn of whoever is at the bottom: white e2-e4, black d7-d5 (board flipped)
|
||||
moves: [['Enter', 'ArrowUp', 'ArrowUp', 'Enter'], ['Enter', 'ArrowUp', 'ArrowUp', 'Enter']],
|
||||
|
||||
Reference in New Issue
Block a user