Rename mirror swaps to moves and give each helper its own kind of help
On screen, a swap is now a move. The five helps no longer all save a move: Bravery frees the next move from the row or column rule, Orientation shows where a chosen piece goes, Fortune doubles the reward of a rebuilt picture, Endurance takes back the last move and Balanced shows the model for five seconds. The model is visible until the first move only: the server no longer sends it afterwards, except during that help and at the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9cf48ea0d0
commit
ddb3b81278
14 changed files with 152 additions and 99 deletions
|
|
@ -430,7 +430,7 @@ export function createCardsApiHandler({
|
|||
if (req.method === "POST" && url.pathname === "/api/cards/mirror/help") {
|
||||
rateLimit(req, "mirror-help", 60);
|
||||
const body = await readBody(req);
|
||||
json(res, 200, service.mirror.useHelp(session.player.id, { day: body.day, mode: body.mode, cardId: body.cardId, help: body.help, moves: body.moves }));
|
||||
json(res, 200, service.mirror.useHelp(session.player.id, { day: body.day, mode: body.mode, cardId: body.cardId, help: body.help, moves: body.moves, cell: body.cell }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/mirror/reset") {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@ export const HELPERS_PER_GAME = 2;
|
|||
// Un personnage Équilibré n'a pas de spécialité : son coup de main a sa propre clé.
|
||||
export const BALANCED_HELP = "balanced";
|
||||
export const HELP_IDS = Object.freeze(["bravoure", "endurance", "fortune", "orientation", BALANCED_HELP]);
|
||||
// Échanges ajoutés par l'Endurance (la simulation donnait +2 trop fort face aux autres coups de main, environ +1).
|
||||
export const ENDURANCE_EXTRA = 1;
|
||||
// Coups de main, un par sorte d'aide (docs/miroir-brise.md) : Bravoure, un mouvement libre (hors rangée et colonne) ; Orientation,
|
||||
// la case d'un morceau choisi ; Fortune, le Trésor (gain multiplié) ; Endurance, reprendre le dernier mouvement ; Équilibré, revoir
|
||||
// le modèle pendant MODEL_PEEK_MS. Le modèle se voit librement jusqu'au premier mouvement.
|
||||
export const TREASURE_FACTOR = 2;
|
||||
export const MODEL_PEEK_MS = 5_000;
|
||||
// Illustration trop unie (ciel, brume) : plus de 20 % de morceaux presque identiques à un autre. Mesures :
|
||||
// scripts/mirror-illustrations.mjs, dans services/cards/content/mirror-illustrations.json.
|
||||
export const MAX_AMBIGUOUS_SHARE = 0.2;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
import { readFileSync } from "node:fs";
|
||||
import { dailyDayKey, isDayKey, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import {
|
||||
aligned, BALANCED_HELP, cellCount, drawIllustration, ENDURANCE_EXTRA, HELPERS_PER_GAME, helpsOf, isSolved, mirrorCandidates, mirrorImage, mirrorReward, MIRROR_MODE_IDS, MIRROR_MODES,
|
||||
MIRROR_REPEAT_DAYS, pieceAt, placedCells, placedCount, scramble, solve, swapCells, swapLimit
|
||||
aligned, BALANCED_HELP, cellCount, drawIllustration, HELPERS_PER_GAME, helpsOf, isSolved, MODEL_PEEK_MS, mirrorCandidates, mirrorImage, mirrorReward, MIRROR_MODE_IDS, MIRROR_MODES,
|
||||
MIRROR_REPEAT_DAYS, pieceAt, placedCells, placedCount, scramble, solve, swapCells, swapLimit, TREASURE_FACTOR
|
||||
} from "./mirror-rules.js";
|
||||
import { DEFAULT_MIRROR_SETTINGS, mirrorSettingsError, normalizeMirrorSettings, readMirrorSettings } from "./mirror-settings.js";
|
||||
import { specialtiesOf } from "./team-rules.js";
|
||||
|
|
@ -136,7 +136,9 @@ export class MirrorService {
|
|||
// Contour vert du Normal : les cases dont le morceau est à sa place. Le Difficile n'en montre aucune avant la fin.
|
||||
placed: placedShown || finished ? placedCells(state.pos) : [],
|
||||
placedCount: finished ? placedCount(state.pos) : null,
|
||||
helpers: state.helpers, used: state.used, helpersLocked: state.swaps > 0 || Object.keys(state.used).length > 0, freeSwap: state.free, hint: state.hint,
|
||||
helpers: state.helpers, used: state.used, helpersLocked: state.swaps > 0 || Object.keys(state.used).length > 0, freeSwap: state.free, treasure: Boolean(state.treasure), hint: state.hint,
|
||||
// Modèle visible : jusqu'au premier mouvement, pendant un « Voir le modèle » (instant de fin donné), puis à la fin.
|
||||
modelOpen: finished || state.moves === 0, peekUntil: state.peekUntil ?? 0,
|
||||
lastMove: state.lastMove,
|
||||
// L'illustration et la référence de l'ordinateur ne se montrent qu'à la fin.
|
||||
cardId: finished ? game.cardId : null, par: finished ? state.par : null
|
||||
|
|
@ -153,7 +155,7 @@ export class MirrorService {
|
|||
const hardDay = this.db.prepare("SELECT 1 FROM mirror_days WHERE day = ?").get(day);
|
||||
return {
|
||||
enabled: settings.enabled, day, nextAt: nextDailyAt(this.cards.now()), number: hardDay ? this.hardNumber(day) : this.hardNumber(day) + 1,
|
||||
rewards: settings.rewards, games, hardLock: this.hardLock(playerId, day), helpersPerGame: HELPERS_PER_GAME, enduranceExtra: ENDURANCE_EXTRA,
|
||||
rewards: settings.rewards, games, hardLock: this.hardLock(playerId, day), helpersPerGame: HELPERS_PER_GAME,
|
||||
team: this.teamHelpers(playerId),
|
||||
devReset: Boolean(this.cards.devPerks)
|
||||
};
|
||||
|
|
@ -174,6 +176,9 @@ export class MirrorService {
|
|||
const image = mirrorImage(this.cards.catalog, game.cardId, mode);
|
||||
if (!image) fail(503, "MIRROR_UNAVAILABLE", "Cette illustration est indisponible.");
|
||||
const { cols, rows, format } = MIRROR_MODES[mode];
|
||||
// Le modèle ne se voit librement que jusqu'au premier mouvement ; ensuite, grâce à l'Équilibré, ou à la fin.
|
||||
const { state } = game;
|
||||
if (model && game.status === "playing" && state.moves > 0 && this.cards.now() > (state.peekUntil ?? 0) + 1_000) fail(403, "MIRROR_MODEL_HIDDEN", "Le modèle n’est plus visible.");
|
||||
return { image, cols, rows, format, at: model ? game.state.pos.map((_, piece) => piece) : pieceAt(game.state.pos) };
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +210,7 @@ export class MirrorService {
|
|||
par = solve(start, MIRROR_MODES.normal.cols).length;
|
||||
}
|
||||
const settings = this.settings;
|
||||
const state = { start, pos: start, swaps: 0, moves: 0, history: [], par, limit: swapLimit(par, settings.margins[mode]), rewards: settings.rewards[mode], helpers: [], used: {}, extra: 0, free: false, hint: null, lastMove: null };
|
||||
const state = { start, pos: start, swaps: 0, moves: 0, history: [], par, limit: swapLimit(par, settings.margins[mode]), rewards: settings.rewards[mode], helpers: [], used: {}, extra: 0, free: false, double: false, hint: null, lastMove: null };
|
||||
this.db.prepare("INSERT INTO mirror_games(player_id, day, mode, card_id, status, state_json, reward, started_at, finished_at) VALUES (?, ?, ?, ?, 'playing', ?, 0, ?, NULL)")
|
||||
.run(playerId, today, mode, cardId, JSON.stringify(state), this.cards.now());
|
||||
});
|
||||
|
|
@ -233,7 +238,7 @@ export class MirrorService {
|
|||
save(playerId, day, game, state) {
|
||||
const left = state.limit + state.extra - state.swaps;
|
||||
const status = isSolved(state.pos) ? "won" : left <= 0 ? "lost" : "playing";
|
||||
const reward = status === "won" ? mirrorReward(state.rewards, left) : 0;
|
||||
const reward = status === "won" ? mirrorReward(state.rewards, left) * (state.treasure ? TREASURE_FACTOR : 1) : 0;
|
||||
this.db.prepare("UPDATE mirror_games SET status = ?, state_json = ?, reward = ?, finished_at = ? WHERE player_id = ? AND day = ? AND mode = ? AND status = 'playing'")
|
||||
.run(status, JSON.stringify(state), reward, status === "playing" ? null : this.cards.now(), playerId, day, game.mode);
|
||||
if (status === "playing") return;
|
||||
|
|
@ -262,35 +267,31 @@ export class MirrorService {
|
|||
chooseHelpers(playerId, { day, mode, cardIds } = {}) {
|
||||
if (!Array.isArray(cardIds) || cardIds.length > HELPERS_PER_GAME || new Set(cardIds).size !== cardIds.length) fail(400, "MIRROR_INVALID", "Demande invalide.");
|
||||
return this.change(playerId, { day, mode }, (state) => {
|
||||
if (state.swaps > 0 || Object.keys(state.used).length) fail(409, "MIRROR_HELPERS_LOCKED", "Les compagnons se choisissent avant le premier échange.");
|
||||
if (state.swaps > 0 || Object.keys(state.used).length) fail(409, "MIRROR_HELPERS_LOCKED", "Les compagnons se choisissent avant le premier mouvement.");
|
||||
const team = new Map(this.teamHelpers(playerId).map((helper) => [helper.cardId, helper]));
|
||||
if (cardIds.some((cardId) => !team.has(cardId))) fail(409, "MIRROR_HELPER_INVALID", "Ce compagnon n’est pas dans votre équipe.");
|
||||
state.helpers = cardIds.map((cardId) => team.get(cardId));
|
||||
});
|
||||
}
|
||||
|
||||
// Coup de main d'un compagnon choisi, une fois par partie. Une double spécialité dit lequel de ses deux coups de main.
|
||||
useHelp(playerId, { day, mode, cardId, help, moves } = {}) {
|
||||
// Coup de main d'un compagnon choisi, une fois par partie. Une double spécialité dit lequel de ses deux coups de main ;
|
||||
// l'Orientation dit aussi sur quel morceau (`cell`, la case où il se trouve).
|
||||
useHelp(playerId, { day, mode, cardId, help, moves, cell } = {}) {
|
||||
if (typeof cardId !== "string" || typeof help !== "string" || !Number.isInteger(moves)) fail(400, "MIRROR_INVALID", "Demande invalide.");
|
||||
if (help === "orientation" && !(Number.isInteger(cell) && cell >= 0 && cell < (validMode(mode) ? cellCount(mode) : 0))) fail(400, "MIRROR_INVALID", "Demande invalide.");
|
||||
return this.change(playerId, { day, mode, moves }, (state) => {
|
||||
const helper = state.helpers.find((item) => item.cardId === cardId);
|
||||
if (!helper || !helper.helps.includes(help)) fail(409, "MIRROR_HELPER_INVALID", "Ce coup de main n’est pas disponible.");
|
||||
if (state.used[cardId]) fail(409, "MIRROR_HELP_USED", "Ce compagnon a déjà donné son coup de main.");
|
||||
const { cols } = MIRROR_MODES[mode];
|
||||
state.lastMove = null;
|
||||
if (help === "endurance") state.extra += ENDURANCE_EXTRA;
|
||||
if (help === "bravoure") state.free = true;
|
||||
if (help === "orientation") state.hint = solve(state.pos, cols).first;
|
||||
if (help === "fortune") {
|
||||
const misplaced = state.pos.flatMap((cell, piece) => (cell === piece ? [] : [piece]));
|
||||
const piece = misplaced[this.random(misplaced.length)];
|
||||
state.lastMove = [state.pos[piece], piece];
|
||||
state.pos = swapCells(state.pos, state.pos[piece], piece);
|
||||
state.hint = null;
|
||||
}
|
||||
if (help === BALANCED_HELP) {
|
||||
// Où va ce morceau ? La case choisie et la vraie case du morceau qui s'y trouve.
|
||||
if (help === "orientation") state.hint = [cell, pieceAt(state.pos)[cell]];
|
||||
if (help === "fortune") state.treasure = true;
|
||||
if (help === BALANCED_HELP) state.peekUntil = this.cards.now() + MODEL_PEEK_MS;
|
||||
if (help === "endurance") {
|
||||
const last = state.history.pop();
|
||||
if (!last) fail(409, "MIRROR_NOTHING_TO_UNDO", "Aucun échange à reprendre.");
|
||||
if (!last) fail(409, "MIRROR_NOTHING_TO_UNDO", "Aucun mouvement à reprendre.");
|
||||
state.pos = swapCells(state.pos, last[0], last[1]);
|
||||
state.swaps -= 1;
|
||||
state.lastMove = last;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue