Recette 1l : libellés de la courbe à 12 px, moment décisif en fin de match, ligne du match, Crawford, tuiles

La courbe du match suit sa taille réelle (viewBox recalculé, redessinée à
chaque changement de taille) ; un contrôle de la recette vérifie les 12 px.
Le moment décisif sur la fin du match garde l'anneau or seul. Ligne du
match alignée à gauche, « contre Débutant ». « · Crawford » dans l'en-tête
de l'analyse. Une seule légende sous les tuiles, avec la fiche. « Sur ce
double passé ».

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 02:07:06 +01:00
co-authored by Claude Opus 5.5
parent 36bb9be384
commit 991a52787d
8 changed files with 121 additions and 21 deletions
+3
View File
@@ -59,6 +59,8 @@ export interface AnalysisMatch {
readonly total: number;
/** « 0–2 », vous – l'ordinateur. */
readonly score: string;
/** C'est la partie Crawford du match. */
readonly crawford: boolean;
readonly previous: string | null;
readonly next: string | null;
}
@@ -705,6 +707,7 @@ export function createAnalysisView(options: AnalysisViewOptions): AnalysisView {
match.number,
match.total,
match.score,
match.crawford,
);
for (const [link, id] of [
[previousGame, match.previous],
+1
View File
@@ -2089,6 +2089,7 @@ export function startApp(options: AppOptions): void {
number,
total: games.length,
score: start === null ? "" : matchScoreText(start.score),
crawford: start?.crawford ?? false,
previous: games[number - 2]?.id ?? null,
next: games[number]?.id ?? null,
};
+7 -5
View File
@@ -72,6 +72,8 @@ export const MATCH_SUMMARY_TEXTS = {
legendDecisive: "Moment décisif",
legendReview: "Décision à revoir",
legendEnd: "Fin du match",
/** Le moment décisif tombe sur la fin du match : une seule marque. */
legendDecisiveEnd: "Moment décisif, fin du match",
bubble: (game: number, turn: number | null, score: string, chance: string) =>
turn === null
? `Début du match · ${score} · ${chance}`
@@ -106,8 +108,8 @@ export const MATCH_SUMMARY_TEXTS = {
// Votre jeu
playTitle: "Votre jeu sur le match",
tiles: { all: "Tout le match", chequer: "Les pions", cube: "Le videau" },
tileUnit: "millièmes par décision",
tileNone: "aucune décision",
tilesCaption: "Taux d'erreur, en millièmes par décision",
tilesHow: "Comment le lire",
// Le videau
cubeTitle: "Le videau",
@@ -145,8 +147,8 @@ export const MATCH_SUMMARY_TEXTS = {
/** Sous l'en-tête du bilan d'une partie de match. */
gameOfMatch: (n: number, length: number) => `Partie ${n} du match en ${length} points`,
/** En tête de l'analyse d'une partie de match : « Partie 2 sur 5 · 0–2 ». */
analysisHeader: (n: number, total: number, score: string) =>
`Partie ${n} sur ${total} · ${score}`,
analysisHeader: (n: number, total: number, score: string, crawford: boolean) =>
`Partie ${n} sur ${total} · ${score}${crawford ? " · Crawford" : ""}`,
previousGame: "Partie précédente",
nextGame: "Partie suivante",
@@ -159,7 +161,7 @@ export const MATCH_SUMMARY_TEXTS = {
return `Match en ${match.length} points · ${state}`;
},
listCaption: (date: string, games: number, level: string) =>
`${date} · ${games} partie${games > 1 ? "s" : ""} · ${level}`,
`${date} · ${games} partie${games > 1 ? "s" : ""} · contre ${level}`,
listInferred: "rattaché d'après les scores",
resume: "Reprendre",
errorRate: (millis: number) => `${millis}`,
+51 -12
View File
@@ -278,11 +278,18 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS
svg.setAttribute("tabindex", "0");
card.append(svg);
const legend = element(card, "ul", { className: "match-legend" });
for (const [mark, text] of [
["decisive", T.legendDecisive],
["review", T.legendReview],
[summary.match.winner === "player" ? "end won" : "end", T.legendEnd],
] as const) {
// Le moment décisif sur la fin du match : l'anneau or seul.
const marks: [string, string][] = decisiveAtEnd(summary)
? [
["decisive", T.legendDecisiveEnd],
["review", T.legendReview],
]
: [
["decisive", T.legendDecisive],
["review", T.legendReview],
[summary.match.winner === "player" ? "end won" : "end", T.legendEnd],
];
for (const [mark, text] of marks) {
const item = element(legend, "li");
const dot = element(item, "span", { className: `match-mark ${mark}` });
dot.setAttribute("aria-hidden", "true");
@@ -311,6 +318,20 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS
const draw = () => drawCurve(svg, summary, selected);
redrawCurve = draw;
draw();
// Le tracé suit la taille réelle de la courbe (une unité du viewBox
// pour un pixel, les libellés à leur taille) : il se redessine dès
// qu'elle change, quand la page devient visible ou tourne.
if (typeof ResizeObserver !== "undefined") {
let size = "";
new ResizeObserver(() => {
const box = svg.getBoundingClientRect();
const now = `${Math.round(box.width)}x${Math.round(box.height)}`;
if (box.width > 0 && now !== size) {
size = now;
draw();
}
}).observe(svg);
}
// Lecture au doigt : glisser choisit le point sous le doigt (une
// vibration légère à chaque changement de partie) ; lâcher garde la
@@ -420,11 +441,14 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS
element(tile, "strong", {
text: rate.decisions === 0 ? "–" : String(errorRateMillis(rate.perDecision)),
});
element(tile, "span", {
className: "caption",
text: rate.decisions === 0 ? T.tileNone : T.tileUnit,
});
}
const unit = element(card, "p", {
id: "match-tiles-caption",
className: "caption match-tiles-caption",
});
unit.append(`${T.tilesCaption} · `);
const how = element(unit, "a", { id: "match-tiles-glossary", text: T.tilesHow });
how.href = routeHash({ screen: "glossary", term: "taux-d-erreur" });
const box = element(card, "div", { className: "summary-gauges" });
const level = summary.errorRate.level;
const levelName = MATCH_TEXTS.levels[level].name;
@@ -601,8 +625,9 @@ export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchS
* bulle du point choisi.
*/
function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number | null): void {
const width = Math.round(svg.getBoundingClientRect().width || 360);
const height = CURVE_HEIGHT;
const box = svg.getBoundingClientRect();
const width = Math.round(box.width || 360);
const height = Math.round(box.height || CURVE_HEIGHT);
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
svg.replaceChildren();
const points = summary.curve;
@@ -699,7 +724,7 @@ function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number |
if (reviewed !== null) {
mark(indexOf(reviewed.game, reviewed.turn), "match-mark-review", 5);
}
if (summary.match.over) {
if (summary.match.over && !decisiveAtEnd(summary)) {
mark(
points.length - 1,
summary.match.winner === "player" ? "match-mark-end won" : "match-mark-end",
@@ -721,6 +746,20 @@ function drawCurve(svg: SVGSVGElement, summary: MatchSummary, selected: number |
}
}
/** Le moment décisif est le dernier tour du match fini : sa marque (l'anneau
* or) tient lieu de marque de fin. */
function decisiveAtEnd(summary: MatchSummary): boolean {
const decisive = summary.decisive;
const last = summary.curve.at(-1);
return (
summary.match.over &&
decisive !== null &&
last !== undefined &&
last.game === decisive.game &&
last.turn === decisive.turn
);
}
/** La bulle du point choisi : partie, coup, score, chances ; un lien SVG
* vers la décision dans l'analyse. */
function bubble(
+1 -1
View File
@@ -359,7 +359,7 @@ test("les phrases du bilan du match", () => {
decisiveSentence(phrases, { ...moment, side: "computer", roll: [6, 6] }),
/^Avec le 6-6 de l'ordinateur/,
);
assert.match(decisiveSentence(phrases, { ...moment, roll: null }), /^Sur ce double/);
assert.match(decisiveSentence(phrases, { ...moment, roll: null }), /^Sur ce double passé, /);
for (const text of [
decisiveSentence(phrases, { ...moment, side: "computer", roll: [6, 6] }),
matchCubeSentence(phrases, 12, 11),
+1 -1
View File
@@ -378,4 +378,4 @@ Le même, un tour de l'ordinateur.
Le même, un tour fini sur un double passé (sans jet).
- Sur ce double, vos chances de gagner le match passent de {avant} à {apres}. C'est le plus grand écart du match.
- Sur ce double passé, vos chances de gagner le match passent de {avant} à {apres}. C'est le plus grand écart du match.
+37 -2
View File
@@ -307,7 +307,35 @@ const losses = await page.evaluate(() =>
[...document.querySelectorAll("#match-summary .match-loss")].map((e) => e.textContent));
check(losses.every((t) => /^−?\d+,\d\s%( de chances de gagner le match)?$/.test(t)),
`pertes : ${JSON.stringify(losses)}`);
await capture("1-bilan-du-match");
/** Recette : chaque texte de la courbe fait au moins 12 px à l'écran
* (taille de la police, mise à l'échelle du viewBox). */
async function curveTextsReadable(where) {
const small = await page.evaluate(() => {
const svg = document.getElementById("match-curve");
const box = svg.getBoundingClientRect();
const view = svg.viewBox.baseVal;
const scale = Math.min(box.width / view.width, box.height / view.height);
return [...svg.querySelectorAll("text")]
.map((t) => ({ text: t.textContent, px: parseFloat(getComputedStyle(t).fontSize) * scale }))
.filter((t) => t.px < 11.95)
.map((t) => `« ${t.text} » ${t.px.toFixed(1)} px`);
});
check(small.length === 0, `${where} : libellés de la courbe trop petits : ${small.join(", ")}`);
}
await curveTextsReadable("portrait");
// Le moment décisif sur la fin du match : l'anneau or seul, et la légende
// le dit.
const legend = await page.evaluate(() => ({
items: [...document.querySelectorAll(".match-legend li")].map((li) => li.textContent),
endDot: document.querySelector("#match-curve .match-mark-end") !== null,
}));
const decisiveAtEnd = legend.items.includes("Moment décisif, fin du match");
check(decisiveAtEnd ? !legend.endDot && legend.items.length === 2 : legend.endDot && legend.items.length === 3,
`légende de la courbe : ${JSON.stringify(legend)}`);
// Les tuiles : le chiffre seul, l'unité en une ligne dessous.
check((await page.textContent("#match-tiles-caption")).startsWith("Taux d'erreur, en millièmes par décision"),
"légende des tuiles");
await capture("1-bilan-du-match", () => curveTextsReadable("capture"));
// La courbe touchée : la bulle (partie, coup, score, chances), un lien vers
// la décision.
@@ -345,7 +373,7 @@ await until("analyse d'une partie du match", () =>
/^#\/parties\/[a-z0-9-]+\/analyse\/\d+$/.test(location.hash) &&
!document.getElementById("analysis-match").hidden);
const header = await page.textContent("#analysis-match-title");
check(new RegExp(`^Partie \\d sur ${games} · \\d–\\d$`).test(header), `en-tête de l'analyse : « ${header} »`);
check(new RegExp(`^Partie \\d sur ${games} · \\d–\\d( · Crawford)?$`).test(header), `en-tête de l'analyse : « ${header} »`);
await capture("3-analyse-partie-de-match", async () => {
await page.evaluate(() => window.scrollTo(0, 0));
});
@@ -365,6 +393,12 @@ const line = await page.evaluate((ids) => {
const item = document.querySelector("#games .games-match");
return {
title: item.querySelector("strong").textContent,
caption: item.querySelector(".caption").textContent,
aligned: (() => {
const strong = item.querySelector("strong").getBoundingClientRect();
const caption = item.querySelector(".caption").getBoundingClientRect();
return Math.abs(strong.left - caption.left) < 1;
})(),
strokes: item.querySelectorAll(".match-stroke").length,
won: item.querySelectorAll(".match-stroke.won").length,
href: item.querySelector("a").getAttribute("href"),
@@ -374,6 +408,7 @@ const line = await page.evaluate((ids) => {
};
}, bilan.gameIds);
check(/^Match en 5 points · gagné 5–\d$/.test(line.title), `ligne du match : « ${line.title} »`);
check(/· contre Débutant$/.test(line.caption) && line.aligned, `détail de la ligne du match : ${JSON.stringify(line)}`);
check(line.strokes === games && line.won >= 2, `traits du match : ${JSON.stringify(line)}`);
check(line.href === matchHash, `la ligne du match ouvre ${line.href}`);
check(line.others === 0, `${line.others} parties du match listées à part`);
+20
View File
@@ -4051,6 +4051,21 @@ html.landscape .match-summary {
height: 196px;
}
/* Les libellés de la courbe : 12 px à l'écran au moins (une unité du
* viewBox vaut un pixel). */
.match-curve .curve-label { font-size: 12px; }
.match-tiles-caption {
margin: calc(-1 * var(--space-1)) 0 var(--space-3);
}
.match-tiles-caption a {
display: inline-flex;
align-items: center;
min-height: 44px;
color: var(--accent);
}
.match-crawford { fill: var(--surface-sunken); }
.match-separator { stroke: var(--border); stroke-width: 1; }
.match-score { fill: var(--text); font-weight: 700; }
@@ -4253,6 +4268,11 @@ html.landscape .match-summary {
.match-line-link {
flex: 1;
min-width: 0;
text-align: left;
}
.match-line-link .progression-text {
align-items: flex-start;
}
.match-strokes {