Files
HokmPlay/scripts/game.js
T

42 lines
1.7 KiB
JavaScript
Raw Normal View History

// Capture several frames of an actual vs-computer game so we can pick the best
// "gameplay" shot (hand fanned at the bottom, trump chosen, a trick in play).
const { chromium } = require("playwright");
const path = require("path");
const OUT = path.join(__dirname, "shots");
const URL = process.env.SHOT_URL || "http://localhost:3025/";
(async () => {
const browser = await chromium.launch({ channel: "chrome" });
const ctx = await browser.newContext({
viewport: { width: 430, height: 932 },
deviceScaleFactor: 2,
locale: "fa-IR",
isMobile: true,
hasTouch: true,
});
const page = await ctx.newPage();
await page.goto(URL, { waitUntil: "networkidle" }).catch(() => {});
await page.waitForTimeout(2500);
await page.getByText("بازی با کامپیوتر", { exact: false }).first().click();
// Capture a frame every few seconds through deal → hakem → trump → play.
const stamps = [6, 10, 14, 18, 24, 30];
let prev = 0;
for (const s of stamps) {
await page.waitForTimeout((s - prev) * 1000);
prev = s;
await page.screenshot({ path: path.join(OUT, `game-${String(s).padStart(2, "0")}s.png`) });
// If it's our turn to choose trump, pick the first suit so play proceeds.
try {
const trump = page.getByText("حکم را انتخاب", { exact: false });
if (await trump.count()) {
const suit = page.locator("button").filter({ hasText: /♠|♥|♦|♣/ }).first();
if (await suit.count()) await suit.click({ timeout: 1500 }).catch(() => {});
}
} catch {}
console.log("frame", s + "s");
}
await browser.close();
console.log("DONE");
})().catch((e) => { console.error("FATAL", e); process.exit(1); });