Add the Broken Mirror puzzle to the Guild

A daily puzzle: a card illustration cut into pieces, rebuilt by swapping
two pieces of the same row or column within a limited number of swaps.
The normal picture is a square card in 4 x 4, drawn for each player, with
placed pieces outlined in green; the hard one is a 5 x 7 portrait shared
by everyone each day, with a result to copy. The limit is the computer's
best result (beam search) plus a margin, and every swap left adds
stardust. Two companions of the daily team can each give one help, by
specialty; a double specialty picks one when used.

The server keeps the piece positions, sends the picture already shuffled
and checks every swap. Uniform illustrations are left out, from measures
written by scripts/mirror-illustrations.mjs. The Guild gets its quest and
a Codex tile, the administration a tab (opening, rewards, margins, the
day's summary), and migration 30 its tables. New collections must plan at
least one double-specialty character, counted by
scripts/team-specialties.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-28 13:38:46 +01:00
parent 5210503922
commit 9cf48ea0d0
36 changed files with 3124 additions and 20 deletions

View file

@ -2562,3 +2562,73 @@ test("an administrator opens expeditions and a player leaves alone, follows the
await expect(status).toContainText("Fermées aux joueurs");
await setServerClock(0);
});
test("an administrator opens the broken mirror and a player rebuilds the normal picture, then starts the shared hard one", async ({ page }) => {
test.setTimeout(120_000);
await page.goto("/#/cards");
await page.getByRole("button", { name: "Version développement", exact: true }).click();
await page.goto("/#/cards/admin/guild/mirror");
const status = page.getByRole("region", { name: /^Miroir brisé (Ouvert|Fermé) aux joueurs$/ });
await expect(status).toContainText("Fermé aux joueurs");
await status.getByRole("button", { name: "Ouvrir le Miroir", exact: true }).click();
await page.getByRole("dialog").getByRole("button", { name: "Ouvrir", exact: true }).click();
await expect(status).toContainText("Ouvert aux joueurs");
await expect(page.getByRole("region", { name: "Gains", exact: true }).getByRole("spinbutton", { name: "Normal, base", exact: true })).toHaveValue("10");
await page.goto("/#/cards/guild");
await page.reload();
const quest = page.getByRole("article", { name: "Miroir brisé" });
await expect(quest).toContainText("Deux images vous attendent : le Normal, puis le Difficile.");
await quest.getByRole("link", { name: "Jouer", exact: true }).click();
await expect(page).toHaveURL(/#\/cards\/mirror$/);
await expect(page.getByRole("button", { name: "Commencer le Difficile" })).toHaveCount(0);
await page.getByRole("button", { name: "Commencer le Normal", exact: true }).click();
// 16 morceaux, une image mélangée en blob ; on n'échange que dans la même rangée ou la même colonne.
const board = page.getByRole("group", { name: "Morceaux de l’illustration" });
const pieces = board.getByRole("button");
await expect(pieces).toHaveCount(16);
await expect.poll(() => pieces.first().evaluate((element) => element.style.backgroundImage)).toMatch(/^url\("blob:/);
const left = page.locator(".nebula-mirror-left strong");
const startLeft = Number(await left.textContent());
await pieces.nth(0).click();
await expect(pieces.nth(5)).toHaveAttribute("data-off", "true");
await expect(pieces.nth(3)).toHaveAttribute("data-legal", "true");
// La place des morceaux ne sort pas du serveur : le parcours la lit en base, comme la réponse de la Carte du jour.
const { path: databasePath } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-db.json"), "utf8"));
const { solve } = await import("../services/cards/mirror-rules.js");
const nextMove = (mode, cols) => {
const database = new DatabaseSync(databasePath, { readOnly: true });
const row = database.prepare("SELECT g.status, g.state_json FROM mirror_games AS g JOIN players ON players.id = g.player_id WHERE players.discord_id = 'dev-admin' AND g.mode = ? ORDER BY g.day DESC LIMIT 1").get(mode);
database.close();
return row.status === "playing" ? solve(JSON.parse(row.state_json).pos, cols).first : null;
};
await pieces.nth(0).click();
let swaps = 0;
for (let move = nextMove("normal", 4); move; move = nextMove("normal", 4)) {
await pieces.nth(move[0]).click();
await pieces.nth(move[1]).click();
swaps += 1;
// Chaque échange compte : le nombre restant baisse, jusqu'au résultat.
await expect(page.locator(`.nebula-mirror-left strong:text-is("${startLeft - swaps}"), .nebula-mirror-result`).first()).toBeVisible();
}
const result = page.getByRole("region", { name: "Image reconstituée !" });
await expect(result).toContainText(`+${10 + startLeft - swaps} poussière`);
await expect(result).toContainText("Illustration :");
// Le Difficile s'ouvre ensuite : 35 morceaux, sans contour vert.
await page.getByRole("button", { name: "Passer au Difficile", exact: true }).click();
await page.getByRole("button", { name: "Commencer le Difficile", exact: true }).click();
await expect(pieces).toHaveCount(35);
await expect(board.locator("[data-placed]")).toHaveCount(0);
await page.setViewportSize({ width: 768, height: 900 });
expect(await page.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false);
await page.setViewportSize({ width: 1280, height: 720 });
// Le Miroir se referme pour les parcours suivants.
await page.goto("/#/cards/admin/guild/mirror");
await status.getByRole("button", { name: "Fermer le Miroir", exact: true }).click();
await page.getByRole("dialog").getByRole("button", { name: "Fermer", exact: true }).click();
await expect(status).toContainText("Fermé aux joueurs");
});