Add an Easy mirror before Normal and let every companion help
Easy is a square 4 x 4 picture drawn for each player, with green outlines, where any two pieces swap; it is scored against the free minimum and pays 5 plus 1 per move left. The three mirrors open one after another (Easy, Normal, Hard) and the Guild quest is done with all three. Migration 31 rebuilds mirror_games to accept the new mode. The mirror page shows three illustrated cards, Easy painted with Codex. Bravery now places a misplaced piece for free, since swapping anywhere means nothing in Easy. Each of the five companions can help once per game instead of two in all. Mirror styles now win over the global button hover, so placed pieces keep their green outline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4321559831
commit
ebb220d532
18 changed files with 276 additions and 146 deletions
|
|
@ -9,7 +9,7 @@ import { createCardsApiHandler } from "../services/cards/api.js";
|
|||
import { buildPublishedCatalog, prepareVersionedCatalog } from "../services/cards/catalog.js";
|
||||
import { CardsDatabase } from "../services/cards/database.js";
|
||||
import {
|
||||
aligned, BALANCED_HELP, cellCount, drawIllustration, helpsOf, isSolved, MAX_AMBIGUOUS_SHARE, MAX_FIXED_AT_START, mirrorCandidates, mirrorReward, MIRROR_MODES, pieceAt, placedCount, scramble, solve, swapCells, swapLimit
|
||||
aligned, BALANCED_HELP, cellCount, drawIllustration, HELPERS_PER_GAME, helpsOf, isSolved, minSwaps, previousMode, MAX_AMBIGUOUS_SHARE, MAX_FIXED_AT_START, mirrorCandidates, mirrorReward, MIRROR_MODES, pieceAt, placedCount, scramble, solve, swapCells, swapLimit
|
||||
} from "../services/cards/mirror-rules.js";
|
||||
import { loadMirrorMeasures } from "../services/cards/mirror-service.js";
|
||||
import { DEFAULT_MIRROR_SETTINGS, mirrorSettingsError, readMirrorSettings } from "../services/cards/mirror-settings.js";
|
||||
|
|
@ -144,11 +144,16 @@ function game(t, { enabled = true, team = false, seed = 5 } = {}) {
|
|||
|
||||
const stored = (db, playerId, mode, day = DAY) => JSON.parse(db.prepare("SELECT state_json FROM mirror_games WHERE player_id = ? AND day = ? AND mode = ?").get(playerId, day, mode).state_json);
|
||||
|
||||
// Joue la solution de l'ordinateur jusqu'à la fin, ou `limit` échanges.
|
||||
// Joue jusqu'à la fin, ou `limit` échanges : en Facile, chaque morceau directement à sa place ; sinon la solution de l'ordinateur.
|
||||
function nextMove(pos, mode) {
|
||||
if (!MIRROR_MODES[mode].freeSwaps) return solve(pos, MIRROR_MODES[mode].cols).first;
|
||||
const piece = pos.findIndex((cell, index) => cell !== index);
|
||||
return [pos[piece], piece];
|
||||
}
|
||||
function play({ mirror, db, player }, mode, limit = Infinity) {
|
||||
let view = mirror.view(player.id).games[mode];
|
||||
for (let count = 0; view.status === "playing" && count < limit; count += 1) {
|
||||
const [from, to] = solve(stored(db, player.id, mode).pos, MIRROR_MODES[mode].cols).first;
|
||||
const [from, to] = nextMove(stored(db, player.id, mode).pos, mode);
|
||||
view = mirror.swap(player.id, { day: DAY, mode, from, to, moves: view.moves }).mirror.games[mode];
|
||||
}
|
||||
return view;
|
||||
|
|
@ -167,6 +172,15 @@ function wasteSwap({ mirror, db, player }, mode) {
|
|||
throw new Error("aucun échange neutre");
|
||||
}
|
||||
|
||||
// Termine le Facile (et le Normal pour `upTo = "hard"`), pour ouvrir le mode suivant.
|
||||
function unlock(context, upTo = "normal", player = context.player) {
|
||||
for (let mode = "easy"; mode !== upTo; mode = MIRROR_MODES_ORDER[MIRROR_MODES_ORDER.indexOf(mode) + 1]) {
|
||||
context.mirror.start(player.id, { day: DAY, mode });
|
||||
play({ ...context, player }, mode);
|
||||
}
|
||||
}
|
||||
const MIRROR_MODES_ORDER = ["easy", "normal", "hard"];
|
||||
|
||||
function readyTeam({ service, player }) {
|
||||
service.team.startRecruitment(player.id, { day: DAY });
|
||||
let view = service.team.view(player.id);
|
||||
|
|
@ -181,7 +195,7 @@ function readyTeam({ service, player }) {
|
|||
test("the mirror is closed by default and only an administrator opens it", (t) => {
|
||||
const { mirror, player, admin, db } = game(t, { enabled: false });
|
||||
assert.equal(mirror.view(player.id).enabled, false);
|
||||
assert.deepEqual(mirror.summary(player.id), { enabled: false, normal: "none", hard: "none", hardLock: "normal" });
|
||||
assert.deepEqual(mirror.summary(player.id), { enabled: false, easy: "none", normal: "none", hard: "none", locks: { easy: null, normal: "easy", hard: "normal" } });
|
||||
refuses("MIRROR_CLOSED", () => mirror.start(player.id, { day: DAY, mode: "normal" }));
|
||||
assert.throws(() => mirror.updateSettings(player.id, { ...DEFAULT_MIRROR_SETTINGS, enabled: true }), (error) => error.status === 403);
|
||||
refuses("MIRROR_SETTINGS_INVALID", () => mirror.updateSettings(admin.id, { ...DEFAULT_MIRROR_SETTINGS, margins: { normal: 99, hard: 6 } }));
|
||||
|
|
@ -190,9 +204,31 @@ test("the mirror is closed by default and only an administrator opens it", (t) =
|
|||
assert.equal(JSON.parse(db.prepare("SELECT settings_json FROM mirror_settings").get().settings_json).unknown, undefined);
|
||||
});
|
||||
|
||||
test("the easy picture swaps any two pieces, against the free minimum, and opens the normal one", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, db, service } = context;
|
||||
assert.equal(previousMode("easy"), null);
|
||||
assert.equal(previousMode("hard"), "normal");
|
||||
const easy = mirror.start(player.id, { day: DAY, mode: "easy" }).mirror.games.easy;
|
||||
const state = stored(db, player.id, "easy");
|
||||
assert.equal(easy.freeSwap, true);
|
||||
assert.equal(state.par, minSwaps(state.start));
|
||||
assert.equal(easy.limit, state.par + DEFAULT_MIRROR_SETTINGS.margins.easy);
|
||||
// Deux morceaux éloignés s'échangent.
|
||||
assert.equal(mirror.swap(player.id, { day: DAY, mode: "easy", from: 0, to: 5, moves: 0 }).mirror.games.easy.swaps, 1);
|
||||
assert.equal(mirror.view(player.id).locks.normal, "easy");
|
||||
const before = service.getState(player.id).wallet.stardust;
|
||||
const won = play(context, "easy");
|
||||
assert.equal(won.status, "won");
|
||||
assert.equal(won.reward, DEFAULT_MIRROR_SETTINGS.rewards.easy.base + won.left * DEFAULT_MIRROR_SETTINGS.rewards.easy.perSwap);
|
||||
assert.equal(service.getState(player.id).wallet.stardust, before + won.reward);
|
||||
assert.equal(mirror.view(player.id).locks.normal, null);
|
||||
});
|
||||
|
||||
test("a normal game keeps its secret, refuses illegal swaps and pays once when the picture is whole", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, db, service } = context;
|
||||
unlock(context);
|
||||
const before = service.getState(player.id).wallet.stardust;
|
||||
const view = mirror.start(player.id, { day: DAY, mode: "normal" }).mirror;
|
||||
const normal = view.games.normal;
|
||||
|
|
@ -223,7 +259,7 @@ test("a normal game keeps its secret, refuses illegal swaps and pays once when t
|
|||
assert.ok(won.cardId && Number.isInteger(won.par) && won.placedCount === 16);
|
||||
assert.equal(service.getState(player.id).wallet.stardust, before + won.reward);
|
||||
refuses("MIRROR_FINISHED", () => mirror.swap(player.id, { day: DAY, mode: "normal", from: 0, to: 1, moves: won.moves }));
|
||||
const history = service.getState(player.id).history.find((entry) => entry.type === "mirror_finished");
|
||||
const history = service.getState(player.id).history.find((entry) => entry.type === "mirror_finished" && entry.details.mode === "normal");
|
||||
assert.equal(history.details.stardust, won.reward);
|
||||
assert.equal(mirror.summary(player.id).normal, "won");
|
||||
});
|
||||
|
|
@ -231,16 +267,15 @@ test("a normal game keeps its secret, refuses illegal swaps and pays once when t
|
|||
test("the hard picture opens after the normal one and is the same for everyone", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, service, db } = context;
|
||||
refuses("MIRROR_HARD_LOCKED", () => mirror.start(player.id, { day: DAY, mode: "hard" }));
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
play(context, "normal");
|
||||
refuses("MIRROR_LOCKED", () => mirror.start(player.id, { day: DAY, mode: "hard" }));
|
||||
refuses("MIRROR_LOCKED", () => mirror.start(player.id, { day: DAY, mode: "normal" }));
|
||||
unlock(context, "hard");
|
||||
const hard = mirror.start(player.id, { day: DAY, mode: "hard" }).mirror;
|
||||
assert.deepEqual([hard.games.hard.cols, hard.games.hard.rows, hard.games.hard.placed], [5, 7, []]);
|
||||
assert.equal(hard.number, 1);
|
||||
|
||||
const other = service.upsertPlayer({ discordId: "3", displayName: "Noé", avatarUrl: "" });
|
||||
mirror.start(other.id, { day: DAY, mode: "normal" });
|
||||
play({ ...context, player: other }, "normal");
|
||||
unlock(context, "hard", other);
|
||||
mirror.start(other.id, { day: DAY, mode: "hard" });
|
||||
assert.deepEqual(stored(db, other.id, "hard").start, stored(db, player.id, "hard").start);
|
||||
assert.equal(db.prepare("SELECT COUNT(DISTINCT card_id) AS count FROM mirror_games WHERE mode = 'hard'").get().count, 1);
|
||||
|
|
@ -259,19 +294,20 @@ test("a hard picture that shows the player's daily card waits for the daily card
|
|||
service.todayPuzzle(player.id);
|
||||
const hardCard = mirror.cards.database.transaction(() => mirror.ensureHardDay(DAY)).cardId;
|
||||
db.prepare("UPDATE daily_attempts SET card_id = ? WHERE player_id = ?").run(hardCard, player.id);
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
// Le Normal ne tire jamais la Carte du jour en cours.
|
||||
assert.notEqual(db.prepare("SELECT card_id FROM mirror_games WHERE mode = 'normal'").get().card_id, hardCard);
|
||||
play(context, "normal");
|
||||
assert.equal(mirror.view(player.id).hardLock, "daily");
|
||||
unlock(context, "hard");
|
||||
// Ni le Facile ni le Normal ne tirent la Carte du jour en cours, et pas deux fois la même illustration.
|
||||
const cards = db.prepare("SELECT card_id FROM mirror_games WHERE mode IN ('easy', 'normal')").all().map((row) => row.card_id);
|
||||
assert.ok(!cards.includes(hardCard) && new Set(cards).size === 2);
|
||||
assert.equal(mirror.view(player.id).locks.hard, "daily");
|
||||
refuses("MIRROR_DAILY_FIRST", () => mirror.start(player.id, { day: DAY, mode: "hard" }));
|
||||
db.prepare("UPDATE daily_attempts SET status = 'lost' WHERE player_id = ?").run(player.id);
|
||||
assert.equal(mirror.view(player.id).hardLock, null);
|
||||
assert.equal(mirror.view(player.id).locks.hard, null);
|
||||
});
|
||||
|
||||
test("a game without swaps left is lost and pays nothing", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, service } = context;
|
||||
unlock(context);
|
||||
const before = service.getState(player.id).wallet.stardust;
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
let view = mirror.view(player.id).games.normal;
|
||||
|
|
@ -281,18 +317,19 @@ test("a game without swaps left is lost and pays nothing", (t) => {
|
|||
assert.ok(view.cardId && view.placedCount < 16);
|
||||
assert.equal(service.getState(player.id).wallet.stardust, before);
|
||||
// Une partie perdue ouvre quand même le Difficile.
|
||||
assert.equal(mirror.view(player.id).hardLock, null);
|
||||
assert.equal(mirror.view(player.id).locks.hard, null);
|
||||
});
|
||||
|
||||
test("any companion of a ready daily team can help, once each and twice per game", (t) => {
|
||||
test("any companion of a ready daily team can help, once each, up to five per game", (t) => {
|
||||
const context = game(t, { team: true });
|
||||
const { mirror, player, db, clock, service } = context;
|
||||
unlock(context);
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
assert.deepEqual(mirror.view(player.id).team, []);
|
||||
const team = readyTeam(context);
|
||||
const helpers = mirror.view(player.id).team;
|
||||
assert.equal(helpers.length, team.companions.length);
|
||||
assert.equal(mirror.view(player.id).games.normal.helpsLeft, 2);
|
||||
assert.equal(mirror.view(player.id).games.normal.helpsLeft, HELPERS_PER_GAME);
|
||||
// Le modèle se voit jusqu'au premier mouvement.
|
||||
assert.equal(mirror.view(player.id).games.normal.modelOpen, true);
|
||||
assert.deepEqual(mirror.image(player.id, "normal", { model: true }).at, Array.from({ length: 16 }, (_, piece) => piece));
|
||||
|
|
@ -310,14 +347,15 @@ test("any companion of a ready daily team can help, once each and twice per game
|
|||
const swapNormal = (from, to) => mirror.swap(player.id, { day: DAY, mode: "normal", from, to, moves: moves() }).mirror.games.normal;
|
||||
refuses("MIRROR_HELPER_INVALID", () => use("starvoid-dragon-unknown", "bravoure"));
|
||||
|
||||
// Bravoure : le prochain mouvement se fait n'importe où, une seule fois. Deux coups de main au plus par partie.
|
||||
// Bravoure : un morceau mal placé va à sa place, sans compter de mouvement. Deux coups de main au plus par partie.
|
||||
withHelps([["bravoure"], ["endurance"], ["fortune"]]);
|
||||
assert.equal(use(ids[0], "bravoure").freeSwap, true);
|
||||
const placedBefore = placedCount(stored(db, player.id, "normal").pos);
|
||||
const placedOne = use(ids[0], "bravoure");
|
||||
assert.ok(placedOne.placed.length > placedBefore && placedOne.swaps === 0 && placedOne.lastMove);
|
||||
refuses("MIRROR_HELP_USED", () => use(ids[0], "bravoure"));
|
||||
refuses("MIRROR_HELPER_INVALID", () => use(ids[1], "fortune"));
|
||||
const free = swapNormal(0, 5);
|
||||
assert.equal(free.freeSwap, false);
|
||||
refuses("MIRROR_SWAP_INVALID", () => swapNormal(0, 5));
|
||||
const free = swapNormal(0, 1);
|
||||
// Après le premier mouvement, le modèle ne sort plus du serveur.
|
||||
assert.equal(free.modelOpen, false);
|
||||
refuses("MIRROR_MODEL_HIDDEN", () => mirror.image(player.id, "normal", { model: true }));
|
||||
|
|
@ -326,9 +364,13 @@ test("any companion of a ready daily team can help, once each and twice per game
|
|||
const before = stored(db, player.id, "normal").pos;
|
||||
const undone = use(ids[1], "endurance");
|
||||
assert.equal(undone.swaps, free.swaps - 1);
|
||||
assert.deepEqual(undone.lastMove, [0, 5]);
|
||||
assert.deepEqual(stored(db, player.id, "normal").pos, swapCells(before, 0, 5));
|
||||
assert.equal(undone.helpsLeft, 0);
|
||||
assert.deepEqual(undone.lastMove, [0, 1]);
|
||||
assert.deepEqual(stored(db, player.id, "normal").pos, swapCells(before, 0, 1));
|
||||
assert.equal(undone.helpsLeft, HELPERS_PER_GAME - 2);
|
||||
// Un coup de main par compagnon, jusqu'à HELPERS_PER_GAME par partie.
|
||||
const full = stored(db, player.id, "normal");
|
||||
full.used = Object.fromEntries(Array.from({ length: HELPERS_PER_GAME }, (_, index) => [`compagnon-${index}`, "fortune"]));
|
||||
db.prepare("UPDATE mirror_games SET state_json = ? WHERE player_id = ? AND mode = 'normal'").run(JSON.stringify(full), player.id);
|
||||
refuses("MIRROR_HELPS_EXHAUSTED", () => use(ids[2], "fortune"));
|
||||
|
||||
// Orientation : la vraie case du morceau choisi ; Équilibré : le modèle pendant 5 secondes.
|
||||
|
|
@ -358,7 +400,7 @@ test("any companion of a ready daily team can help, once each and twice per game
|
|||
test("a closed daily team gives no helper, and a deleted account leaves no game", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, db } = context;
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
mirror.start(player.id, { day: DAY, mode: "easy" });
|
||||
assert.deepEqual(mirror.view(player.id).team, []);
|
||||
mirror.forgetPlayer(player.id);
|
||||
assert.equal(db.prepare("SELECT COUNT(*) AS count FROM mirror_games").get().count, 0);
|
||||
|
|
@ -367,11 +409,11 @@ test("a closed daily team gives no helper, and a deleted account leaves no game"
|
|||
test("a new day brings a new hard picture and a new normal game", (t) => {
|
||||
const context = game(t);
|
||||
const { mirror, player, clock, db } = context;
|
||||
mirror.start(player.id, { day: DAY, mode: "normal" });
|
||||
mirror.start(player.id, { day: DAY, mode: "easy" });
|
||||
clock.now += DAY_MS;
|
||||
const next = mirror.view(player.id);
|
||||
assert.equal(next.day, "2026-11-29");
|
||||
assert.equal(next.games.normal, null);
|
||||
assert.equal(next.games.easy, null);
|
||||
mirror.cards.database.transaction(() => { mirror.ensureHardDay(DAY); mirror.ensureHardDay("2026-11-29"); });
|
||||
const cards = db.prepare("SELECT card_id FROM mirror_days ORDER BY day").all().map((row) => row.card_id);
|
||||
assert.notEqual(cards[0], cards[1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue