병합: 루미큐브 앱 규칙 기본 + 끌어다 놓는 판(움직이는 동안 모두에게 보임)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-14 04:43:03 +09:00
13 changed files with 1587 additions and 534 deletions

View File

@@ -58,9 +58,13 @@ async function finishHand(pages: Page[]) {
for (const p of pages) await p.getByText('이번 판 결과').first().waitFor({ timeout: 10_000 });
}
/** 루미큐브: whoever has the turn tries "도와줘" → "새 묶음" → "확정"; otherwise takes one tile. */
/**
* 루미큐브: whoever has the turn tries "도와줘" → places the picked tiles → "완료"; otherwise takes one tile.
* The first play drags the picked tiles from the rack onto the grid with the mouse, checks that the other player
* sees them on the table before 완료 (live working table), resets with "되돌리기", then places them with "새 묶음".
*/
async function rummikubTurns(pages: Page[], turns: number) {
const stats = { plays: 0, draws: 0, undo: false };
const stats = { plays: 0, draws: 0, dragged: false };
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
const bar = (p: Page) => p.getByRole('group', { name: '내 차례 행동' });
/** Waits until a bar button is enabled / disabled (server answered). */
@@ -77,6 +81,7 @@ async function rummikubTurns(pages: Page[], turns: number) {
if (!mover) await pages[0]!.waitForTimeout(100);
}
if (!mover) throw new Error(`nobody has the turn (turn ${n + 1})`);
const others = pages.filter((p) => p !== mover);
await bar(mover).waitFor();
let played = false;
await bar(mover).getByRole('button', { name: '도와줘' }).click();
@@ -84,23 +89,52 @@ async function rummikubTurns(pages: Page[], turns: number) {
if (picked > 0) {
// Tap one picked tile twice (deselect, select again) — the tap-to-select path.
const first = mover.locator('.rk-rack button[aria-pressed="true"]').first();
const label = await first.getAttribute('aria-label');
const id = (await first.getAttribute('data-tile'))!;
await first.click();
await mover.locator(`.rk-rack button[aria-label="${label}"]`).first().click();
await bar(mover).getByRole('button', { name: '새 묶음' }).click();
await mover.locator('.rk-set').last().waitFor();
if (!stats.undo) {
// Undo once (back to the turn start), then place again.
await mover.waitForTimeout(450); // not a double tap
await mover.locator(`.rk-rack [data-tile="${id}"]`).click();
if (!stats.dragged) {
// Drag the picked tiles onto the grid (mouse), row 2, column 2.
const tile = await mover.locator(`.rk-rack [data-tile="${id}"]`).boundingBox();
const board = await mover.locator('.rk-board').boundingBox();
if (!tile || !board) throw new Error('no tile / board box');
await mover.mouse.move(tile.x + tile.width / 2, tile.y + tile.height / 2);
await mover.mouse.down();
const cw = board.width / 20;
const tx = board.x + cw * 2.5;
const ty = board.y + cw * 1.36 * 2.5;
for (let k = 1; k <= 12; k++) await mover.mouse.move(tile.x + ((tx - tile.x) * k) / 12, tile.y + ((ty - tile.y) * k) / 12);
// While the tiles are still in hand, the others see them moving (drag preview stream, face down from the rack).
for (const o of others) await o.locator('.rk-ghostrow .rk-back').first().waitFor({ timeout: 5000 });
// The last position reaches them too (trailing preview), so the ghost row ends up over the board.
for (const o of others)
await o.waitForFunction(
() => {
const g = document.querySelector('.rk-ghostrow .rk-back')?.getBoundingClientRect();
const b = document.querySelector('.rk-board')?.getBoundingClientRect();
return !!g && !!b && g.top < b.top + b.height / 2;
},
null,
{ timeout: 5000 },
);
await mover.screenshot({ path: join(SHOTS, 'rummikub-3-dragging.png') });
await others[0]!.screenshot({ path: join(SHOTS, 'rummikub-4-dragging-seen-by-other.png') });
await mover.mouse.up();
await mover.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
// Everybody else sees the tile on the table right away (before 완료).
for (const o of others) await o.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
await barButton(mover, '되돌리기', true);
await bar(mover).getByRole('button', { name: '되돌리기' }).click();
await barButton(mover, '처음으로', false);
stats.undo = true;
await mover.locator(`.rk-rack [data-tile="${id}"]`).waitFor({ timeout: 5000 });
for (const o of others) await o.locator(`.rk-board [data-tile="${id}"]`).waitFor({ state: 'detached', timeout: 5000 });
stats.dragged = true;
await bar(mover).getByRole('button', { name: '도와줘' }).click();
await bar(mover).getByRole('button', { name: '새 묶음' }).click();
}
const commit = bar(mover).getByRole('button', { name: '확정' });
await bar(mover).getByRole('button', { name: '새 묶음' }).click();
await mover.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
const commit = bar(mover).getByRole('button', { name: '완료' });
await mover
.waitForFunction(() => [...document.querySelectorAll('.rk-bar button')].some((b) => b.textContent === '확정' && b.classList.contains('btn-primary') && !b.hasAttribute('disabled')), null, { timeout: 5000 })
.waitForFunction(() => [...document.querySelectorAll('.rk-bar button')].some((b) => b.textContent === '완료' && b.classList.contains('btn-primary') && !b.hasAttribute('disabled')), null, { timeout: 5000 })
.then(
() => (played = true),
() => {},
@@ -109,7 +143,7 @@ async function rummikubTurns(pages: Page[], turns: number) {
await commit.click();
stats.plays++;
} else {
await bar(mover).getByRole('button', { name: '처음으로' }).click();
await bar(mover).getByRole('button', { name: '되돌리기' }).click();
await mover.waitForTimeout(300);
}
}
@@ -121,7 +155,7 @@ async function rummikubTurns(pages: Page[], turns: number) {
}
await mover.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 5000 });
}
console.log(` rummikub: ${stats.plays} plays, ${stats.draws} draws, undo ${stats.undo ? 'used' : 'not used'}`);
console.log(` rummikub: ${stats.plays} plays, ${stats.draws} draws, drag ${stats.dragged ? 'used' : 'not used'}`);
return stats;
}