Bilan du match : page, courbe des chances de gagner le match, listes et accès
Page #/matchs/<id>/bilan (en-tête, courbe continue lue au doigt, partie par partie, jeu, videau, moment décisif, décision à revoir, export SGF, prompt). Un match tient en une ligne dans Mes parties et la progression ; le bilan et l'analyse d'une partie de match y renvoient. Test navigateur d'un match en 5 points remonté de 0–4. ADR 0007 et 0013 amendés, plan clos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
68664dc3f7
commit
3b0107af1b
@@ -45,11 +45,8 @@ export interface MatchGame {
|
||||
readonly journal: GameJournal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Un match joué : ses parties dans l'ordre, et où il en est.
|
||||
*
|
||||
* Glossaire : docs/glossaire/match.md
|
||||
*/
|
||||
/** Un match joué : ses parties dans l'ordre, et où il en est (voir
|
||||
* docs/glossaire/match.md). */
|
||||
export interface PlayedMatch {
|
||||
/** L'identifiant du match (version 3 des événements) ; pour un match
|
||||
* d'avant, celui de sa première partie. */
|
||||
@@ -251,9 +248,8 @@ export interface MatchGameRow {
|
||||
/**
|
||||
* Un point de la courbe des chances de gagner le match : le début du
|
||||
* match, puis chaque tour de chaque partie. La fin d'une partie est le
|
||||
* début de la suivante : la courbe est continue d'une partie à l'autre.
|
||||
*
|
||||
* Glossaire : docs/glossaire/chances-de-gagner-le-match.md
|
||||
* début de la suivante : la courbe est continue d'une partie à l'autre
|
||||
* (voir docs/glossaire/chances-de-gagner-le-match.md).
|
||||
*/
|
||||
export interface MatchCurvePoint {
|
||||
readonly game: number;
|
||||
@@ -299,7 +295,8 @@ export interface MatchSummary {
|
||||
/** La chance de vos dés sur tout le match. */
|
||||
readonly luck: LuckSummary;
|
||||
/** Vos décisions de videau comptées (comme le taux d'erreur du
|
||||
* videau), et celles qui diffèrent du moteur, dans l'ordre du bilan. */
|
||||
* videau), et celles qui diffèrent du moteur d'au moins
|
||||
* CUBE_LOSS_SHOWN, dans l'ordre du bilan. */
|
||||
readonly cubeDecisions: number;
|
||||
readonly cubeErrors: readonly CubeError[];
|
||||
readonly decisive: DecisiveMoment | null;
|
||||
@@ -417,7 +414,7 @@ export function summarizeMatch(match: PlayedMatch): MatchSummary {
|
||||
for (const kind of CUBE_ERROR_KINDS) {
|
||||
for (const d of decisions) {
|
||||
const a = d.advice;
|
||||
if (a.kind === "cube" && a.equityLoss < 0 && CUBE_KIND[a.action] === kind) {
|
||||
if (a.kind === "cube" && differs(d) && CUBE_KIND[a.action] === kind) {
|
||||
cubeErrors.push({ ...d, kind });
|
||||
}
|
||||
}
|
||||
@@ -459,6 +456,17 @@ export function summarizeMatch(match: PlayedMatch): MatchSummary {
|
||||
};
|
||||
}
|
||||
|
||||
/** Plus petite perte de chances de gagner le match qui fait d'une décision
|
||||
* de videau une décision « autre que celle du moteur » : 0,05 %, ce qui
|
||||
* s'écrit au moins « −0,1 % ». En dessous, gnubg compte un écart, mais la
|
||||
* ligne dirait « 0,0 % » : elle n'apprendrait rien au joueur. */
|
||||
export const CUBE_LOSS_SHOWN = 0.0005;
|
||||
|
||||
/** La décision diffère de celle du moteur, d'une perte qui se voit. */
|
||||
function differs(d: MatchDecision): boolean {
|
||||
return d.advice.equityLoss < 0 && (d.loss === null || d.loss <= -CUBE_LOSS_SHOWN);
|
||||
}
|
||||
|
||||
/** Le tour qui a fait le plus varier les chances de gagner le match, entre
|
||||
* deux points analysés qui se suivent (le premier en cas d'égalité). */
|
||||
function decisiveMoment(curve: readonly MatchCurvePoint[]): DecisiveMoment | null {
|
||||
|
||||
+34
-6
@@ -10,7 +10,7 @@ import { runAnalysis } from "./domain/analysis/game-analysis.js";
|
||||
import { Game } from "./domain/game/game.js";
|
||||
import { linkOf, readPosition } from "./domain/game/position-link.js";
|
||||
import { levelOf } from "./domain/game/saved-game.js";
|
||||
import { exportSgf } from "./domain/game/sgf.js";
|
||||
import { exportMatchSgf, exportSgf } from "./domain/game/sgf.js";
|
||||
import {
|
||||
illustratedMove,
|
||||
MovePractice,
|
||||
@@ -18,7 +18,12 @@ import {
|
||||
tutorialBoard,
|
||||
} from "./domain/learning/tutorial.js";
|
||||
import { positionBefore } from "./domain/prompts/position.js";
|
||||
import { conceptExample, exercisesPosition, summaryPosition } from "./domain/prompts/prompts.js";
|
||||
import {
|
||||
conceptExample,
|
||||
exercisesPosition,
|
||||
matchPosition,
|
||||
summaryPosition,
|
||||
} from "./domain/prompts/prompts.js";
|
||||
import { createWasmEngine } from "./engine/wasm-engine.js";
|
||||
import { type EngineWorker, startEngineWorker } from "./engine/worker-run.js";
|
||||
import { createGameSession } from "./storage/game-session.js";
|
||||
@@ -129,17 +134,28 @@ startApp({
|
||||
if (game === null) {
|
||||
throw new Error("partie introuvable");
|
||||
}
|
||||
const started = new Date(game.summary.startedAt);
|
||||
const two = (n: number) => String(n).padStart(2, "0");
|
||||
const date = `${started.getFullYear()}-${two(started.getMonth() + 1)}-${two(started.getDate())}`;
|
||||
const { date, time } = fileDate(game.summary.startedAt);
|
||||
const text = await exportSgf(engine, game.journal, {
|
||||
playerName: "Vous",
|
||||
computerName: "Ustagammon",
|
||||
date,
|
||||
});
|
||||
const time = `${two(started.getHours())}${two(started.getMinutes())}`;
|
||||
return { fileName: `ustagammon-${date}-${time}.sgf`, text };
|
||||
},
|
||||
exportMatchSgf: async (ids) => {
|
||||
const games = await Promise.all(ids.map((id) => storage().library.load(id)));
|
||||
const first = games[0];
|
||||
if (first === undefined || games.some((g) => g === null)) {
|
||||
throw new Error("partie du match introuvable");
|
||||
}
|
||||
const { date, time } = fileDate(first?.summary.startedAt ?? 0);
|
||||
const text = await exportMatchSgf(
|
||||
engine,
|
||||
games.flatMap((g) => (g === null ? [] : [g.journal])),
|
||||
{ playerName: "Vous", computerName: "Ustagammon", date },
|
||||
);
|
||||
return { fileName: `ustagammon-match-${date}-${time}.sgf`, text };
|
||||
},
|
||||
},
|
||||
cachedBoard: () => settings.loadBoard(),
|
||||
saveBoard: (board) => settings.saveBoard(board),
|
||||
@@ -181,11 +197,23 @@ startApp({
|
||||
summary: (journal) => summaryPosition(engine, journal),
|
||||
concept: (journal) => conceptExample(engine, journal, ANALYSIS_PLY),
|
||||
exercises: (journals) => exercisesPosition(engine, journals),
|
||||
match: (summary) => matchPosition(engine, summary),
|
||||
},
|
||||
startUpdates: (onAvailable) =>
|
||||
startUpdates(new URL("../sw.js", import.meta.url), worker.ready, onAvailable),
|
||||
});
|
||||
|
||||
/** La date et l'heure d'un début de partie, pour un nom de fichier SGF :
|
||||
* AAAA-MM-JJ et HHMM. */
|
||||
function fileDate(time: number): { readonly date: string; readonly time: string } {
|
||||
const started = new Date(time);
|
||||
const two = (n: number) => String(n).padStart(2, "0");
|
||||
return {
|
||||
date: `${started.getFullYear()}-${two(started.getMonth() + 1)}-${two(started.getDate())}`,
|
||||
time: `${two(started.getHours())}${two(started.getMinutes())}`,
|
||||
};
|
||||
}
|
||||
|
||||
/** La valeur, ou undefined si l'obtenir lève une exception. */
|
||||
function attempt<T>(get: () => T): T | undefined {
|
||||
try {
|
||||
|
||||
@@ -33,6 +33,7 @@ import { formatHalfMoves } from "../domain/game/position.js";
|
||||
import { VERDICT_ICONS } from "./advice-view.js";
|
||||
import { askAiLink } from "./ask-ai.js";
|
||||
import { icon } from "./icons.js";
|
||||
import { MATCH_SUMMARY_TEXTS } from "./match-summary-texts.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { boardSvg, createMovePlayer, drawSteps, type MovePlayer } from "./move-board.js";
|
||||
import { percent, REVIEW_TEXTS, signed } from "./review-texts.js";
|
||||
@@ -47,6 +48,19 @@ export interface AnalysisData {
|
||||
/** Le coup choisi (null : le coup à revoir, ou le premier). */
|
||||
readonly turn: number | null;
|
||||
readonly phrases: MasterPhrases | null;
|
||||
/** Une partie de match (étape 1l) : sa place dans le match, le score
|
||||
* au début, et les parties d'avant et d'après (null : partie libre). */
|
||||
readonly match: AnalysisMatch | null;
|
||||
}
|
||||
|
||||
/** La place d'une partie dans son match, pour l'en-tête de l'analyse. */
|
||||
export interface AnalysisMatch {
|
||||
readonly number: number;
|
||||
readonly total: number;
|
||||
/** « 0–2 », vous – l'ordinateur. */
|
||||
readonly score: string;
|
||||
readonly previous: string | null;
|
||||
readonly next: string | null;
|
||||
}
|
||||
|
||||
export interface AnalysisViewOptions {
|
||||
@@ -144,6 +158,29 @@ export function createAnalysisView(options: AnalysisViewOptions): AnalysisView {
|
||||
className: "analysis-title",
|
||||
text: REVIEW_TEXTS.analysisTitle,
|
||||
});
|
||||
// Une partie de match (étape 1l) : « ‹ Partie 2 sur 5 · 0–2 › », pour
|
||||
// passer d'une partie à l'autre. La courbe reste celle de la partie.
|
||||
const matchNav = element(section, "nav", {
|
||||
id: "analysis-match",
|
||||
className: "viewer-nav analysis-match",
|
||||
});
|
||||
matchNav.hidden = true;
|
||||
const previousGame = element(matchNav, "a", {
|
||||
id: "analysis-previous-game",
|
||||
className: "icon-button viewer-step",
|
||||
});
|
||||
previousGame.append(icon("chevron"));
|
||||
previousGame.setAttribute("aria-label", MATCH_SUMMARY_TEXTS.previousGame);
|
||||
const matchTitle = element(matchNav, "p", {
|
||||
id: "analysis-match-title",
|
||||
className: "viewer-turn",
|
||||
});
|
||||
const nextGame = element(matchNav, "a", {
|
||||
id: "analysis-next-game",
|
||||
className: "icon-button viewer-step",
|
||||
});
|
||||
nextGame.append(icon("chevron"));
|
||||
nextGame.setAttribute("aria-label", MATCH_SUMMARY_TEXTS.nextGame);
|
||||
const message = element(section, "p", {
|
||||
id: "analysis-message",
|
||||
className: "analysis-message",
|
||||
@@ -661,6 +698,27 @@ export function createAnalysisView(options: AnalysisViewOptions): AnalysisView {
|
||||
numbers.hidden = true;
|
||||
return;
|
||||
}
|
||||
const match = next.match;
|
||||
matchNav.hidden = match === null;
|
||||
if (match !== null) {
|
||||
matchTitle.textContent = MATCH_SUMMARY_TEXTS.analysisHeader(
|
||||
match.number,
|
||||
match.total,
|
||||
match.score,
|
||||
);
|
||||
for (const [link, id] of [
|
||||
[previousGame, match.previous],
|
||||
[nextGame, match.next],
|
||||
] as const) {
|
||||
if (id === null) {
|
||||
link.removeAttribute("href");
|
||||
link.setAttribute("aria-disabled", "true");
|
||||
} else {
|
||||
link.href = routeHash({ screen: "analysis", game: id, turn: null });
|
||||
link.removeAttribute("aria-disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
turns = gameTurns(next.journal);
|
||||
curve = chanceCurve(next.journal);
|
||||
const summary = summarizeAnalysis(next.journal);
|
||||
|
||||
+317
-24
@@ -28,6 +28,13 @@ import {
|
||||
readyForSummary,
|
||||
summarizeAnalysis,
|
||||
} from "../domain/analysis/game-analysis.js";
|
||||
import {
|
||||
groupMatches,
|
||||
type MatchGame,
|
||||
matchOfGame,
|
||||
type PlayedMatch,
|
||||
summarizeMatch,
|
||||
} from "../domain/analysis/match-analysis.js";
|
||||
import {
|
||||
type MasterPhrases,
|
||||
masterLine,
|
||||
@@ -42,13 +49,13 @@ import {
|
||||
import type { Advice } from "../domain/game/advice.js";
|
||||
import type { Cube } from "../domain/game/cube.js";
|
||||
import type { MoveNotation } from "../domain/game/engine.js";
|
||||
import type { GameJournal } from "../domain/game/events.js";
|
||||
import { currentLine, EMPTY_JOURNAL, type GameJournal } from "../domain/game/events.js";
|
||||
import type { Game, MoveSteps, NewGame, SideBoards } from "../domain/game/game.js";
|
||||
import type { HalfMove } from "../domain/game/position.js";
|
||||
import { type PositionLink, type SharedPosition, setupOf } from "../domain/game/position-link.js";
|
||||
import type { SavedGameSummary } from "../domain/game/saved-game.js";
|
||||
import { otherSide, type Side } from "../domain/game/side.js";
|
||||
import type { GameState } from "../domain/game/state.js";
|
||||
import { type GameState, replay } from "../domain/game/state.js";
|
||||
import {
|
||||
finishedLessons,
|
||||
LESSON_END,
|
||||
@@ -61,7 +68,7 @@ import {
|
||||
import { ADVICE_TEXTS } from "./advice-texts.js";
|
||||
import { type Analyse, createAdviceTracker } from "./advice-tracker.js";
|
||||
import { createAdviceView, VERDICT_ICONS } from "./advice-view.js";
|
||||
import { createAnalysisView } from "./analysis-view.js";
|
||||
import { type AnalysisMatch, createAnalysisView } from "./analysis-view.js";
|
||||
import { createPromptView, type PromptResult } from "./ask-ai.js";
|
||||
import { ASK_AI_TEXTS } from "./ask-ai-texts.js";
|
||||
import {
|
||||
@@ -86,7 +93,7 @@ import {
|
||||
slideChecker,
|
||||
} from "./board-view.js";
|
||||
import { GAMES_TEXTS } from "./games-texts.js";
|
||||
import { createGamesView, type GamesView } from "./games-view.js";
|
||||
import { createGamesView, downloadFile, type GamesView } from "./games-view.js";
|
||||
import { boardGeometry, type Geometry, type Layout, PORTRAIT_ASPECT } from "./geometry.js";
|
||||
import { createHaptics, type Vibrate } from "./haptics.js";
|
||||
import { createHelpView, loadGlossaryEntry } from "./help.js";
|
||||
@@ -100,6 +107,9 @@ import { LESSON_COUNT, type Lesson, lessonSource, outlineOf, parseLesson } from
|
||||
import { LESSON_TEXTS } from "./lesson-texts.js";
|
||||
import { lessonCards, nextLessonCard } from "./lessons-model.js";
|
||||
import { createLessonsView } from "./lessons-view.js";
|
||||
import { matchLineOf } from "./match-line.js";
|
||||
import { MATCH_SUMMARY_TEXTS, matchScoreText } from "./match-summary-texts.js";
|
||||
import { createMatchSummaryView } from "./match-summary-view.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { replacingLink, startNavigation } from "./navigation.js";
|
||||
import { createNewGameView } from "./new-game-view.js";
|
||||
@@ -222,6 +232,11 @@ export interface SavedGamesAccess {
|
||||
readonly saveAnalyses: (id: string, journal: GameJournal) => void;
|
||||
readonly remove: (id: string) => Promise<void>;
|
||||
readonly exportSgf: (id: string) => Promise<{ fileName: string; text: string }>;
|
||||
/** Le fichier SGF d'un match entier, ses parties dans l'ordre (étape
|
||||
* 1l). */
|
||||
readonly exportMatchSgf: (
|
||||
ids: readonly string[],
|
||||
) => Promise<{ fileName: string; text: string }>;
|
||||
}
|
||||
|
||||
/** Ce que la vue d'une position demande au domaine et au moteur. */
|
||||
@@ -289,6 +304,7 @@ export function startApp(options: AppOptions): void {
|
||||
promptVeil: byId("prompt-veil"),
|
||||
analysis: byId("analysis"),
|
||||
progression: byId("progression"),
|
||||
matchSummary: byId("match-summary"),
|
||||
menuAdvice: byId<HTMLButtonElement>("menu-advice"),
|
||||
prompt: byId("prompt"),
|
||||
strips: { computer: stripOf("strip-computer"), player: stripOf("strip-player") },
|
||||
@@ -725,7 +741,7 @@ export function startApp(options: AppOptions): void {
|
||||
show(ui.take, doubled);
|
||||
show(ui.drop, doubled);
|
||||
show(ui.again, over && panelDismissed);
|
||||
ui.again.textContent = afterGameLabel(game);
|
||||
ui.again.textContent = afterGameLabel(game, false);
|
||||
show(ui.replay, shownMove !== null);
|
||||
// Le coup de l'ordinateur montré : sa position se copie en lien.
|
||||
show(ui.copyLink, shownMove !== null && currentLink !== null);
|
||||
@@ -947,7 +963,7 @@ export function startApp(options: AppOptions): void {
|
||||
ui.panelText.textContent = end.title;
|
||||
detail.textContent = end.detail;
|
||||
ui.panelSecondary.textContent = TEXTS.reviewGame;
|
||||
ui.panelPrimary.textContent = afterGameLabel(g);
|
||||
ui.panelPrimary.textContent = afterGameLabel(g, true);
|
||||
ui.panelSettings.hidden = false;
|
||||
ui.panelVeil.dataset.kind = "over";
|
||||
} else if (ask) {
|
||||
@@ -1254,10 +1270,19 @@ export function startApp(options: AppOptions): void {
|
||||
/** Après une partie finie : la partie suivante du match s'il continue,
|
||||
* sinon « Rejouer », une nouvelle partie aux mêmes réglages (un match de
|
||||
* même longueur après un match), tout de suite. */
|
||||
function afterGame(): void {
|
||||
if (game !== null) {
|
||||
newGame(game.nextGame ?? game.rematch);
|
||||
function afterGame(toMatchSummary: boolean): void {
|
||||
if (game === null) {
|
||||
return;
|
||||
}
|
||||
// Le match fini : le panneau de fin de partie et le bilan de la
|
||||
// dernière partie mènent au bilan du match (étape 1l) ; « Rejouer »
|
||||
// reste sous le plateau.
|
||||
const finished = toMatchSummary ? matchSummaryIdOf(game) : null;
|
||||
if (finished !== null) {
|
||||
navigation.go(routeHash({ screen: "matchSummary", match: finished }));
|
||||
return;
|
||||
}
|
||||
newGame(game.nextGame ?? game.rematch);
|
||||
}
|
||||
|
||||
function showBanner(journal: GameJournal): void {
|
||||
@@ -1332,6 +1357,12 @@ export function startApp(options: AppOptions): void {
|
||||
remove: options.games.remove,
|
||||
exportSgf: options.games.exportSgf,
|
||||
onClose: () => leaveSheet(),
|
||||
matches: async () => (await loadMatches()).map(matchLineOf),
|
||||
resumeMatch: (match) => {
|
||||
if (!busy) {
|
||||
void resumeMatch(match);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const helpView = createHelpView(ui.helpContent, ui.helpTabs);
|
||||
@@ -1351,11 +1382,13 @@ export function startApp(options: AppOptions): void {
|
||||
// moteur à part ; la partie regardée (bilan, analyse) et son journal.
|
||||
const reviewRunner = createReviewRunner(options.analyseGame);
|
||||
let reviewed: { id: string; journal: GameJournal; game: Game } | null = null;
|
||||
// Le match de la partie regardée (étape 1l), lu à son ouverture.
|
||||
let reviewedMatch: { id: string; match: PlayedMatch; number: number } | null = null;
|
||||
|
||||
const summaryView = createSummaryView({
|
||||
veil: ui.summaryVeil,
|
||||
close: () => leaveSheet(),
|
||||
again: () => afterGame(),
|
||||
again: () => afterGame(true),
|
||||
});
|
||||
|
||||
const analysisView = createAnalysisView({
|
||||
@@ -1474,6 +1507,16 @@ export function startApp(options: AppOptions): void {
|
||||
}
|
||||
case "glossary":
|
||||
return promptSource.concept(route.term ?? "", game?.journal ?? null);
|
||||
case "matchSummary": {
|
||||
const match = await loadMatch(route.match);
|
||||
if (match === null) {
|
||||
return { message: ASK_AI_TEXTS.missingMatch };
|
||||
}
|
||||
const summary = summarizeMatch(match);
|
||||
return summary.ready
|
||||
? promptSource.match(summary)
|
||||
: { message: ASK_AI_TEXTS.matchNotReady };
|
||||
}
|
||||
case "progression": {
|
||||
// Les parties analysées de l'écran, de la plus ancienne à la
|
||||
// plus récente : rien n'est analysé pour le prompt.
|
||||
@@ -1513,6 +1556,10 @@ export function startApp(options: AppOptions): void {
|
||||
}
|
||||
if (reviewed !== null) {
|
||||
review(reviewed.id, reviewed.journal);
|
||||
if (reviewedMatch?.id !== id) {
|
||||
const found = await matchOf(id, reviewed.journal).catch(() => null);
|
||||
reviewedMatch = found === null ? null : { id, ...found };
|
||||
}
|
||||
}
|
||||
showReview(id, false);
|
||||
}
|
||||
@@ -1538,12 +1585,17 @@ export function startApp(options: AppOptions): void {
|
||||
reviewed = { ...reviewed, journal: live?.journal ?? analysed };
|
||||
}
|
||||
progressionAnalysed(id, live?.journal ?? analysed);
|
||||
matchAnalysed(id, live?.journal ?? analysed);
|
||||
showReview(id, false);
|
||||
render();
|
||||
},
|
||||
// L'écran de progression attend peut-être cette analyse pour
|
||||
// lancer celle de la partie suivante.
|
||||
() => reviewProgression(),
|
||||
// L'écran de progression ou le bilan du match attendent
|
||||
// peut-être cette analyse pour lancer celle de la partie
|
||||
// suivante.
|
||||
() => {
|
||||
reviewProgression();
|
||||
reviewMatch();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1553,8 +1605,17 @@ export function startApp(options: AppOptions): void {
|
||||
// relues à chaque visite, avec leurs analyses rangées. Celles qui n'en
|
||||
// ont pas encore sont analysées en arrière-plan, une à une, la plus
|
||||
// récente d'abord ; rien n'est recalculé pour les autres.
|
||||
const progressionView = createProgressionView({ section: ui.progression });
|
||||
const progressionView = createProgressionView({
|
||||
section: ui.progression,
|
||||
resumeMatch: (match) => {
|
||||
if (!busy) {
|
||||
void resumeMatch(match);
|
||||
}
|
||||
},
|
||||
});
|
||||
let progressionGames: FinishedGame[] | null = null;
|
||||
// Les matchs, pour leurs lignes (étape 1l).
|
||||
let progressionMatches: PlayedMatch[] = [];
|
||||
// Chaque lecture a son numéro : une lecture dépassée n'est pas dessinée.
|
||||
let progressionRequest = 0;
|
||||
// Les parties dont l'analyse a été lancée depuis l'ouverture de l'écran.
|
||||
@@ -1596,13 +1657,14 @@ export function startApp(options: AppOptions): void {
|
||||
progressionGames = null;
|
||||
renderProgression();
|
||||
options.engineReady
|
||||
.then(() => loadProgression())
|
||||
.then(() => Promise.all([loadProgression(), loadMatches()]))
|
||||
.then(
|
||||
(games) => {
|
||||
([games, matches]) => {
|
||||
if (request !== progressionRequest) {
|
||||
return;
|
||||
}
|
||||
progressionGames = games;
|
||||
progressionMatches = matches;
|
||||
renderProgression();
|
||||
reviewProgression();
|
||||
},
|
||||
@@ -1627,7 +1689,11 @@ export function startApp(options: AppOptions): void {
|
||||
progressionView.render(
|
||||
progressionGames === null
|
||||
? null
|
||||
: { entries: progressionEntries(progressionGames), phrases },
|
||||
: {
|
||||
entries: progressionEntries(progressionGames),
|
||||
matches: progressionMatches.map(matchLineOf),
|
||||
phrases,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1636,6 +1702,11 @@ export function startApp(options: AppOptions): void {
|
||||
function progressionAnalysed(id: string, journal: GameJournal): void {
|
||||
if (progressionGames?.some((g) => g.id === id)) {
|
||||
progressionGames = progressionGames.map((g) => (g.id === id ? { ...g, journal } : g));
|
||||
progressionMatches = progressionMatches.map((m) =>
|
||||
m.games.some((g) => g.id === id)
|
||||
? { ...m, games: m.games.map((g) => (g.id === id ? { ...g, journal } : g)) }
|
||||
: m,
|
||||
);
|
||||
renderProgression();
|
||||
}
|
||||
}
|
||||
@@ -1662,6 +1733,173 @@ export function startApp(options: AppOptions): void {
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------- Bilan du match (1l)
|
||||
|
||||
// L'écran #/matchs/<id>/bilan : les parties du match, relues à chaque
|
||||
// visite avec leurs analyses rangées ; celles qui n'en ont pas assez
|
||||
// sont analysées en arrière-plan, une à une.
|
||||
const matchSummaryView = createMatchSummaryView({
|
||||
section: ui.matchSummary,
|
||||
stepsBefore: async (gameId, advice) => {
|
||||
const viewed = liveGame(gameId) ?? (await options.games.view(gameId));
|
||||
return viewed === null
|
||||
? null
|
||||
: viewed.stepsBefore(
|
||||
advice.eventId,
|
||||
"player",
|
||||
advice.kind === "move" ? advice.played.halfMoves : [],
|
||||
);
|
||||
},
|
||||
exportSgf: async (summary) => {
|
||||
downloadFile(await options.games.exportMatchSgf(summary.match.games.map((g) => g.id)));
|
||||
},
|
||||
resume: (summary) => void resumeMatch(summary.match),
|
||||
vibrate: () => haptic("curveGame"),
|
||||
});
|
||||
let shownMatch: PlayedMatch | null = null;
|
||||
let matchShownId: string | null = null;
|
||||
let matchRequest = 0;
|
||||
// Les parties dont l'analyse a été lancée depuis l'ouverture de l'écran.
|
||||
const matchTried = new Set<string>();
|
||||
|
||||
/** Les parties de match enregistrées, avec leur journal (celui de la
|
||||
* partie à l'écran, s'il s'agit d'elle), réunies en matchs. */
|
||||
async function loadMatches(): Promise<PlayedMatch[]> {
|
||||
const list = await options.games.list();
|
||||
const games = await Promise.all(
|
||||
list
|
||||
.filter((summary) => summary.match !== undefined)
|
||||
.map(async (summary): Promise<MatchGame | null> => {
|
||||
const journal =
|
||||
liveGame(summary.id)?.journal ?? (await options.games.journal(summary.id));
|
||||
return journal === null
|
||||
? null
|
||||
: {
|
||||
id: summary.id,
|
||||
startedAt: summary.startedAt,
|
||||
updatedAt: summary.updatedAt,
|
||||
journal,
|
||||
};
|
||||
}),
|
||||
);
|
||||
return groupMatches(games.filter((g): g is MatchGame => g !== null)).matches;
|
||||
}
|
||||
|
||||
/** Un match par son identifiant (null s'il n'existe pas). */
|
||||
async function loadMatch(id: string): Promise<PlayedMatch | null> {
|
||||
if (shownMatch?.id === id) {
|
||||
return shownMatch;
|
||||
}
|
||||
return (await loadMatches()).find((m) => m.id === id) ?? null;
|
||||
}
|
||||
|
||||
/** Le match d'une partie et sa place dans le match (null : partie
|
||||
* libre, ou partie qu'on ne sait rattacher à aucun match). */
|
||||
async function matchOf(
|
||||
gameId: string,
|
||||
journal: GameJournal,
|
||||
): Promise<{ match: PlayedMatch; number: number } | null> {
|
||||
const start = journal.events[0];
|
||||
if (start?.type !== "GameStarted" || start.match === undefined) {
|
||||
return null;
|
||||
}
|
||||
return matchOfGame(await loadMatches(), gameId);
|
||||
}
|
||||
|
||||
function showMatchSummary(id: string): void {
|
||||
const request = ++matchRequest;
|
||||
matchShownId = id;
|
||||
matchTried.clear();
|
||||
shownMatch = null;
|
||||
matchSummaryView.show(null);
|
||||
options.engineReady
|
||||
.then(() => loadMatches())
|
||||
.then(
|
||||
(matches) => {
|
||||
if (request !== matchRequest) {
|
||||
return;
|
||||
}
|
||||
shownMatch = matches.find((m) => m.id === id) ?? null;
|
||||
if (shownMatch === null) {
|
||||
matchSummaryView.show(null, true);
|
||||
return;
|
||||
}
|
||||
renderMatchSummary();
|
||||
reviewMatch();
|
||||
},
|
||||
() => {
|
||||
if (request === matchRequest) {
|
||||
matchSummaryView.show(null, true);
|
||||
}
|
||||
},
|
||||
);
|
||||
if (phrases === null) {
|
||||
phrasesLoading.then(
|
||||
() => renderMatchSummary(),
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renderMatchSummary(): void {
|
||||
if (navigation.route.screen !== "matchSummary" || shownMatch === null) {
|
||||
return;
|
||||
}
|
||||
matchSummaryView.show({ summary: summarizeMatch(shownMatch), phrases });
|
||||
// La feuille du prompt attendait l'analyse : elle se met à jour.
|
||||
const route = navigation.route;
|
||||
if (isAiRoute(route) && promptView.isOpen && !promptView.ready) {
|
||||
showPrompt(route);
|
||||
}
|
||||
}
|
||||
|
||||
/** Une analyse rangée : le match, s'il est à l'écran, se met à jour. */
|
||||
function matchAnalysed(id: string, journal: GameJournal): void {
|
||||
if (shownMatch?.games.some((g) => g.id === id)) {
|
||||
shownMatch = {
|
||||
...shownMatch,
|
||||
games: shownMatch.games.map((g) => (g.id === id ? { ...g, journal } : g)),
|
||||
};
|
||||
renderMatchSummary();
|
||||
}
|
||||
}
|
||||
|
||||
/** Lance l'analyse de la prochaine partie du match à l'écran à qui il
|
||||
* en manque (rien si une analyse tourne déjà : à sa fin, elle rappelle
|
||||
* cette fonction). */
|
||||
function reviewMatch(): void {
|
||||
if (
|
||||
navigation.route.screen !== "matchSummary" ||
|
||||
shownMatch === null ||
|
||||
reviewRunner.running !== null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const next = shownMatch.games.find(
|
||||
(g) => !matchTried.has(g.id) && missingAnalyses(g.journal).length > 0,
|
||||
);
|
||||
if (next !== undefined) {
|
||||
matchTried.add(next.id);
|
||||
review(next.id, next.journal);
|
||||
}
|
||||
}
|
||||
|
||||
/** « Reprendre le match » : sa dernière partie à l'écran ; si elle est
|
||||
* finie, la partie suivante commence. */
|
||||
async function resumeMatch(match: PlayedMatch): Promise<void> {
|
||||
const last = match.games.at(-1);
|
||||
if (last === undefined || busy) {
|
||||
return;
|
||||
}
|
||||
const other = await options.games.open(last.id);
|
||||
hideBanner();
|
||||
navigation.replace("#/");
|
||||
await act(() => showGame(other));
|
||||
if (other.state.phase === "over" && other.nextGame !== null) {
|
||||
afterGame(false);
|
||||
}
|
||||
}
|
||||
|
||||
/** L'analyse en cours d'une partie qui n'est ni regardée ni à l'écran
|
||||
* s'arrête : le moteur à part revient au conseil du maître. */
|
||||
function stopForeignReview(): void {
|
||||
@@ -1696,8 +1934,16 @@ export function startApp(options: AppOptions): void {
|
||||
journal: shown.journal,
|
||||
game: shown.game,
|
||||
end: shown.game.state.phase === "over" ? endParts(shown.game) : null,
|
||||
afterLabel: live === null ? null : afterGameLabel(live),
|
||||
afterLabel: live === null ? null : afterGameLabel(live, true),
|
||||
phrases,
|
||||
match:
|
||||
reviewedMatch?.id === id
|
||||
? {
|
||||
id: reviewedMatch.match.id,
|
||||
number: reviewedMatch.number,
|
||||
length: reviewedMatch.match.length,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
@@ -1710,11 +1956,30 @@ export function startApp(options: AppOptions): void {
|
||||
game: shown.game,
|
||||
turn: route.turn,
|
||||
phrases,
|
||||
match: analysisMatch(id),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** La place de la partie id dans son match, pour l'en-tête de
|
||||
* l'analyse (null : partie libre). */
|
||||
function analysisMatch(id: string): AnalysisMatch | null {
|
||||
if (reviewedMatch?.id !== id) {
|
||||
return null;
|
||||
}
|
||||
const { match, number } = reviewedMatch;
|
||||
const games = match.games;
|
||||
const start = replay(currentLine(games[number - 1]?.journal ?? EMPTY_JOURNAL)).match;
|
||||
return {
|
||||
number,
|
||||
total: games.length,
|
||||
score: start === null ? "" : matchScoreText(start.score),
|
||||
previous: games[number - 2]?.id ?? null,
|
||||
next: games[number]?.id ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* La partie à l'écran vient de finir : son analyse part en
|
||||
* arrière-plan, et le bilan remplace le panneau de fin de partie dès
|
||||
@@ -1863,7 +2128,7 @@ export function startApp(options: AppOptions): void {
|
||||
selected = null;
|
||||
void settle(true);
|
||||
},
|
||||
again: () => afterGame(),
|
||||
again: () => afterGame(false),
|
||||
// Le menu a son adresse : l'ouvrir, c'est aller à #/menu (comme son
|
||||
// lien) ; le refermer, revenir à l'écran d'avant.
|
||||
menu: () => {
|
||||
@@ -1907,6 +2172,8 @@ export function startApp(options: AppOptions): void {
|
||||
navigation.leave((r) => r.screen === "lessons");
|
||||
} else if (route.screen === "progression") {
|
||||
navigation.leave((r) => r.screen === "progression");
|
||||
} else if (route.screen === "matchSummary") {
|
||||
navigation.leave((r) => r.screen === "matchSummary");
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1983,7 +2250,7 @@ export function startApp(options: AppOptions): void {
|
||||
if (ui.panelVeil.dataset.kind === "doubled") {
|
||||
actions.take();
|
||||
} else {
|
||||
afterGame();
|
||||
afterGame(true);
|
||||
}
|
||||
};
|
||||
// « Changer les réglages » : un lien vers l'écran « Nouvelle partie » ;
|
||||
@@ -2069,6 +2336,7 @@ export function startApp(options: AppOptions): void {
|
||||
const choosing = below.screen === "newGame";
|
||||
const analysing = below.screen === "analysis";
|
||||
const progression = below.screen === "progression";
|
||||
const matchPage = below.screen === "matchSummary";
|
||||
const page =
|
||||
help ||
|
||||
position ||
|
||||
@@ -2078,7 +2346,8 @@ export function startApp(options: AppOptions): void {
|
||||
lesson ||
|
||||
choosing ||
|
||||
analysing ||
|
||||
progression;
|
||||
progression ||
|
||||
matchPage;
|
||||
const wasPage = ui.game.hidden;
|
||||
const wasScreen = ui.root.dataset.screen;
|
||||
ui.game.hidden = page;
|
||||
@@ -2090,6 +2359,7 @@ export function startApp(options: AppOptions): void {
|
||||
ui.lesson.hidden = !lesson;
|
||||
ui.analysis.hidden = !analysing;
|
||||
ui.progression.hidden = !progression;
|
||||
ui.matchSummary.hidden = !matchPage;
|
||||
const opening = choosing && ui.newGameSection.hidden;
|
||||
ui.newGameSection.hidden = !choosing;
|
||||
ui.root.classList.toggle("page-open", page);
|
||||
@@ -2137,6 +2407,15 @@ export function startApp(options: AppOptions): void {
|
||||
if (progression && wasScreen !== "progression") {
|
||||
showProgression();
|
||||
}
|
||||
// Le bilan du match aussi (étape 1l) : ses parties ont pu être
|
||||
// analysées entre-temps.
|
||||
if (below.screen === "matchSummary") {
|
||||
if (wasScreen !== "matchSummary" || matchShownId !== below.match) {
|
||||
showMatchSummary(below.match);
|
||||
}
|
||||
} else {
|
||||
matchShownId = null;
|
||||
}
|
||||
|
||||
// La marche à suivre pour installer : une feuille, comme le menu.
|
||||
if (route.screen === "install" && ui.installVeil.hidden) {
|
||||
@@ -2197,7 +2476,7 @@ export function startApp(options: AppOptions): void {
|
||||
() => openReview(id),
|
||||
() => undefined,
|
||||
);
|
||||
} else if (route.screen !== "progression") {
|
||||
} else if (route.screen !== "progression" && route.screen !== "matchSummary") {
|
||||
stopForeignReview();
|
||||
}
|
||||
if (route.screen === "games") {
|
||||
@@ -3150,11 +3429,25 @@ function bandText(prompt: string, crawford: boolean): string {
|
||||
}
|
||||
|
||||
/** Le bouton qui suit une partie finie : « Partie suivante » dans un match
|
||||
* qui continue, sinon « Rejouer » (mêmes réglages). */
|
||||
function afterGameLabel(game: Game): string {
|
||||
* qui continue, sinon « Rejouer » (mêmes réglages) ; à la fin d'un match,
|
||||
* dans le panneau de fin de partie et le bilan (toMatchSummary), « Bilan du
|
||||
* match » (étape 1l). */
|
||||
function afterGameLabel(game: Game, toMatchSummary: boolean): string {
|
||||
if (toMatchSummary && matchSummaryIdOf(game) !== null) {
|
||||
return MATCH_SUMMARY_TEXTS.seeMatchSummary;
|
||||
}
|
||||
return game.nextGame === null ? MATCH_TEXTS.replay : MATCH_TEXTS.nextGame;
|
||||
}
|
||||
|
||||
/** L'identifiant du match que cette partie vient de finir (null : partie
|
||||
* libre, match qui continue, ou match d'avant l'identifiant). */
|
||||
function matchSummaryIdOf(game: Game): string | null {
|
||||
const state = game.state;
|
||||
return state.phase === "over" && state.matchAfter?.over === true
|
||||
? (state.match?.id ?? null)
|
||||
: null;
|
||||
}
|
||||
|
||||
/** Le résultat d'une partie finie, sur une ligne (consigne, une fois le
|
||||
* panneau fermé). */
|
||||
function resultText(game: Game): string {
|
||||
|
||||
@@ -22,11 +22,15 @@ export const ASK_AI_TEXTS = {
|
||||
analysis: "Analyse",
|
||||
glossary: "Glossaire",
|
||||
progression: "Progression",
|
||||
matchSummary: "Bilan du match",
|
||||
},
|
||||
failed: "Le prompt n'a pas pu être préparé.",
|
||||
noAdvice: "Pas de prompt pour cette décision : le maître ne l'a pas encore analysée.",
|
||||
notReady: "Le maître analyse encore la partie : le prompt sera prêt avec le bilan.",
|
||||
missingGame: "Cette partie n'est plus sur ce téléphone.",
|
||||
missingMatch: "Ce match n'est plus sur ce téléphone.",
|
||||
matchNotReady:
|
||||
"Le maître analyse encore les parties du match : le prompt sera prêt avec le bilan.",
|
||||
missingTerm: "Ce terme n'est pas dans le glossaire.",
|
||||
noAnalysedGame:
|
||||
"Pas encore d'exercices : le maître n'a analysé aucune partie terminée. Ils seront prêts avec la première.",
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
// (#/parties/<id>, ses branches dépliées) : l'écran de jeu l'ouvre et la
|
||||
// ferme selon l'adresse (show, hide), et « Branches » est un vrai lien.
|
||||
|
||||
import type { PlayedMatch } from "../domain/analysis/match-analysis.js";
|
||||
import { branches } from "../domain/game/branches.js";
|
||||
import type { GameJournal } from "../domain/game/events.js";
|
||||
import type { SavedGameSummary } from "../domain/game/saved-game.js";
|
||||
import { GAMES_TEXTS } from "./games-texts.js";
|
||||
import { icon } from "./icons.js";
|
||||
import { type MatchLine, renderMatchLine } from "./match-line.js";
|
||||
import { routeHash } from "./router.js";
|
||||
|
||||
export interface GamesViewOptions {
|
||||
@@ -36,6 +38,11 @@ export interface GamesViewOptions {
|
||||
/** La croix ou le voile touché : quitter la feuille (l'écran de jeu
|
||||
* change d'adresse, puis appelle hide). */
|
||||
readonly onClose: () => void;
|
||||
/** Les matchs (étape 1l) : chacun tient en une ligne, à la place de
|
||||
* ses parties. */
|
||||
readonly matches: () => Promise<readonly MatchLine[]>;
|
||||
/** « Reprendre » sur la ligne d'un match en cours. */
|
||||
readonly resumeMatch: (match: PlayedMatch) => void;
|
||||
}
|
||||
|
||||
export interface GamesView {
|
||||
@@ -93,13 +100,35 @@ export function createGamesView(options: GamesViewOptions): GamesView {
|
||||
};
|
||||
|
||||
async function render(): Promise<void> {
|
||||
const games = await options.list();
|
||||
list.replaceChildren(...games.map((game) => gameItem(game, game.id === options.shownId())));
|
||||
const [games, matches] = await Promise.all([
|
||||
options.list(),
|
||||
options.matches().catch((): readonly MatchLine[] => []),
|
||||
]);
|
||||
// Un match tient en une ligne, à la place de ses parties, à la date
|
||||
// de sa dernière action ; les parties libres gardent la leur.
|
||||
const inMatch = new Set(matches.flatMap((line) => line.match.games.map((g) => g.id)));
|
||||
const items = [
|
||||
...games
|
||||
.filter((game) => !inMatch.has(game.id))
|
||||
.map((game) => ({
|
||||
at: game.updatedAt,
|
||||
item: () => gameItem(game, game.id === options.shownId()),
|
||||
})),
|
||||
...matches.map((line) => ({ at: line.match.updatedAt, item: () => matchItem(line) })),
|
||||
].sort((a, b) => b.at - a.at);
|
||||
list.replaceChildren(...items.map((entry) => entry.item()));
|
||||
if (games.length === 0) {
|
||||
message.textContent = GAMES_TEXTS.empty;
|
||||
}
|
||||
}
|
||||
|
||||
function matchItem(line: MatchLine): HTMLElement {
|
||||
const item = element("li", "games-item games-match");
|
||||
item.dataset.match = line.match.id;
|
||||
renderMatchLine(item, line, () => options.resumeMatch(line.match));
|
||||
return item;
|
||||
}
|
||||
|
||||
function gameItem(game: SavedGameSummary, shown: boolean): HTMLElement {
|
||||
const item = element("li", "games-item");
|
||||
item.dataset.id = game.id;
|
||||
@@ -126,7 +155,7 @@ export function createGamesView(options: GamesViewOptions): GamesView {
|
||||
...(game.status === "over" ? [summaryLink(game.id)] : []),
|
||||
button(
|
||||
GAMES_TEXTS.exportSgf,
|
||||
run(async () => download(await options.exportSgf(game.id))),
|
||||
run(async () => downloadFile(await options.exportSgf(game.id))),
|
||||
"secondary",
|
||||
"export",
|
||||
),
|
||||
@@ -276,7 +305,7 @@ function button(
|
||||
}
|
||||
|
||||
/** Fait télécharger un fichier texte au navigateur. */
|
||||
function download(file: { fileName: string; text: string }): void {
|
||||
export function downloadFile(file: { fileName: string; text: string }): void {
|
||||
const url = URL.createObjectURL(new Blob([file.text], { type: "application/x-go-sgf" }));
|
||||
const link = element("a");
|
||||
link.href = url;
|
||||
|
||||
@@ -10,7 +10,10 @@ export type HapticEvent =
|
||||
| "checkerHit"
|
||||
| "computerDoubles"
|
||||
| "gameWon"
|
||||
| "gameLost";
|
||||
| "gameLost"
|
||||
/** Bilan du match : le doigt passe d'une partie à l'autre sur la
|
||||
* courbe (étape 1l). */
|
||||
| "curveGame";
|
||||
|
||||
/** Motifs en millisecondes (vibration, pause, vibration…). */
|
||||
export const HAPTIC_PATTERNS: Readonly<Record<HapticEvent, readonly number[]>> = {
|
||||
@@ -19,6 +22,7 @@ export const HAPTIC_PATTERNS: Readonly<Record<HapticEvent, readonly number[]>> =
|
||||
computerDoubles: [40, 60, 40],
|
||||
gameWon: [30, 50, 30, 50, 60],
|
||||
gameLost: [60],
|
||||
curveGame: [8],
|
||||
};
|
||||
|
||||
/** navigator.vibrate, s'il existe. */
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// Un match en une ligne, dans « Mes parties » et la progression (étape 1l ;
|
||||
// charte, ecrans-etape-1.md, « Bilan du match », accès) : le titre (« Match
|
||||
// en 5 points · gagné 5–4 »), un trait par partie, la date, le nombre de
|
||||
// parties et le niveau, le taux d'erreur du match à droite ; la ligne ouvre
|
||||
// le bilan du match. Un match en cours a « Reprendre » à côté.
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import { readyForSummary } from "../domain/analysis/game-analysis.js";
|
||||
import { type PlayedMatch, summarizeMatch } from "../domain/analysis/match-analysis.js";
|
||||
import { errorRateMillis } from "../domain/analysis/progression.js";
|
||||
import { currentLine } from "../domain/game/events.js";
|
||||
import { computerLevelOf } from "../domain/game/level.js";
|
||||
import { replay } from "../domain/game/state.js";
|
||||
import { icon } from "./icons.js";
|
||||
import { MATCH_SUMMARY_TEXTS as T } from "./match-summary-texts.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { PROGRESSION_TEXTS } from "./progression-texts.js";
|
||||
import { routeHash } from "./router.js";
|
||||
|
||||
/** Un match et son taux d'erreur (null : analyse pas encore finie). */
|
||||
export interface MatchLine {
|
||||
readonly match: PlayedMatch;
|
||||
readonly errorRate: number | null;
|
||||
}
|
||||
|
||||
/** La ligne d'un match : son taux d'erreur, celui du bilan du match, dès
|
||||
* que toutes ses parties ont leur bilan. */
|
||||
export function matchLineOf(match: PlayedMatch): MatchLine {
|
||||
const ready = match.games.every((g) => readyForSummary(g.journal));
|
||||
return { match, errorRate: ready ? summarizeMatch(match).errorRate.perDecision : null };
|
||||
}
|
||||
|
||||
/** Dessine la ligne d'un match dans parent ; resume : « Reprendre », pour
|
||||
* un match en cours. */
|
||||
export function renderMatchLine(
|
||||
parent: HTMLElement,
|
||||
line: MatchLine,
|
||||
resume: (() => void) | null,
|
||||
): HTMLElement {
|
||||
const { match } = line;
|
||||
const box = document.createElement("div");
|
||||
box.className = "match-line";
|
||||
box.dataset.match = match.id;
|
||||
const link = document.createElement("a");
|
||||
link.className = "progression-game match-line-link";
|
||||
link.href = routeHash({ screen: "matchSummary", match: match.id });
|
||||
const text = document.createElement("span");
|
||||
text.className = "progression-text";
|
||||
const title = document.createElement("strong");
|
||||
title.textContent = T.listTitle(match);
|
||||
const strokes = document.createElement("span");
|
||||
strokes.className = "match-strokes";
|
||||
strokes.setAttribute("aria-hidden", "true");
|
||||
for (const game of match.games) {
|
||||
const state = replay(currentLine(game.journal));
|
||||
const stroke = document.createElement("span");
|
||||
stroke.className =
|
||||
state.result === null
|
||||
? "match-stroke"
|
||||
: `match-stroke ${state.result.winner === "player" ? "won" : "lost"}`;
|
||||
strokes.append(stroke);
|
||||
}
|
||||
if (!match.over) {
|
||||
const next = document.createElement("span");
|
||||
next.className = "match-stroke next";
|
||||
strokes.append(next);
|
||||
}
|
||||
const level = computerLevelOf(match.level);
|
||||
const caption = document.createElement("span");
|
||||
caption.className = "caption";
|
||||
caption.textContent = [
|
||||
T.listCaption(
|
||||
PROGRESSION_TEXTS.date(match.startedAt),
|
||||
match.games.length,
|
||||
level === null ? match.level : MATCH_TEXTS.levels[level].name,
|
||||
),
|
||||
...(match.inferred ? [T.listInferred] : []),
|
||||
].join(" · ");
|
||||
text.append(title, strokes, caption);
|
||||
const rate = document.createElement("span");
|
||||
rate.className = "progression-rate";
|
||||
if (line.errorRate === null) {
|
||||
rate.classList.add("pending");
|
||||
rate.textContent = PROGRESSION_TEXTS.rateLoading;
|
||||
} else {
|
||||
const millis = errorRateMillis(line.errorRate);
|
||||
rate.dataset.rate = String(line.errorRate);
|
||||
const strong = document.createElement("strong");
|
||||
strong.textContent = T.errorRate(millis);
|
||||
const unit = document.createElement("span");
|
||||
unit.className = "caption";
|
||||
unit.textContent = PROGRESSION_TEXTS.rateLabel;
|
||||
rate.append(strong, unit);
|
||||
rate.setAttribute("aria-label", T.errorRateLabel(millis));
|
||||
}
|
||||
link.append(text, rate, icon("chevron"));
|
||||
box.append(link);
|
||||
if (!match.over && resume !== null) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "match-resume";
|
||||
button.textContent = T.resume;
|
||||
button.onclick = () => resume();
|
||||
box.append(button);
|
||||
}
|
||||
parent.append(box);
|
||||
return box;
|
||||
}
|
||||
@@ -0,0 +1,766 @@
|
||||
// Le bilan d'un match entier (#/matchs/<id>/bilan, étape 1l ; charte,
|
||||
// ecrans-etape-1.md, « Bilan du match ») : une page qui défile. L'en-tête,
|
||||
// la courbe des chances de gagner le match à travers toutes les parties,
|
||||
// « Partie par partie », votre jeu sur le match, le videau, le moment
|
||||
// décisif, la décision à revoir, l'export SGF, puis la barre d'actions.
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
//
|
||||
// Tout ce qu'elle affiche vient du bilan du match (domain/analysis/
|
||||
// match-analysis.ts), donc des analyses du moteur rangées dans chaque
|
||||
// partie, et des phrases du maître. La courbe est dessinée à la main en
|
||||
// SVG ; la bulle de lecture y est un lien SVG vers la décision (pas de
|
||||
// style en ligne : CSP stricte).
|
||||
|
||||
import {
|
||||
cubeKindsWithoutError,
|
||||
formatMatchLoss,
|
||||
type MatchCurvePoint,
|
||||
type MatchSummary,
|
||||
} from "../domain/analysis/match-analysis.js";
|
||||
import {
|
||||
decisiveSentence,
|
||||
diceWords,
|
||||
type MasterPhrases,
|
||||
masterWords,
|
||||
matchCubeAgreements,
|
||||
matchCubeSentence,
|
||||
nothingToReview,
|
||||
} from "../domain/analysis/phrases.js";
|
||||
import { errorRateMillis } from "../domain/analysis/progression.js";
|
||||
import type { Advice } from "../domain/game/advice.js";
|
||||
import type { MoveSteps } from "../domain/game/game.js";
|
||||
import { COMPUTER_LEVELS } from "../domain/game/level.js";
|
||||
import { VERDICT_ICONS } from "./advice-view.js";
|
||||
import { askAiLink } from "./ask-ai.js";
|
||||
import { icon } from "./icons.js";
|
||||
import {
|
||||
CUBE_ERROR_WORDS,
|
||||
matchScoreText,
|
||||
MATCH_SUMMARY_TEXTS as T,
|
||||
} from "./match-summary-texts.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { boardSvg, drawSteps } from "./move-board.js";
|
||||
import { percent, REVIEW_TEXTS } from "./review-texts.js";
|
||||
import { routeHash } from "./router.js";
|
||||
|
||||
/** Ce que montre la page. */
|
||||
export interface MatchSummaryData {
|
||||
readonly summary: MatchSummary;
|
||||
readonly phrases: MasterPhrases | null;
|
||||
}
|
||||
|
||||
export interface MatchSummaryViewOptions {
|
||||
/** La page (index.html) ; son contenu est construit ici. */
|
||||
readonly section: HTMLElement;
|
||||
/** Le plateau d'avant une décision d'une partie du match. */
|
||||
readonly stepsBefore: (gameId: string, advice: Advice) => Promise<MoveSteps | null>;
|
||||
/** « Exporter le match (SGF) ». */
|
||||
readonly exportSgf: (summary: MatchSummary) => Promise<void>;
|
||||
/** « Reprendre le match » : la dernière partie, à l'écran. */
|
||||
readonly resume: (summary: MatchSummary) => void;
|
||||
/** Une vibration légère, à chaque changement de partie sur la courbe. */
|
||||
readonly vibrate: () => void;
|
||||
}
|
||||
|
||||
export interface MatchSummaryView {
|
||||
/** Dessine la page (null : le match se lit ; missing : il n'existe
|
||||
* pas). */
|
||||
show(data: MatchSummaryData | null, missing?: boolean): void;
|
||||
hide(): void;
|
||||
}
|
||||
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
/** Hauteur de la courbe (au moins 150 px de zone tactile, charte) et ses
|
||||
* marges : les scores au-dessus, les noms des parties en dessous. */
|
||||
const CURVE_HEIGHT = 196;
|
||||
const PAD = { left: 40, right: 12, top: 26, bottom: 26 };
|
||||
const BUBBLE = { width: 210, height: 44 };
|
||||
|
||||
function element<K extends keyof HTMLElementTagNameMap>(
|
||||
parent: HTMLElement,
|
||||
tag: K,
|
||||
options: { id?: string; className?: string; text?: string } = {},
|
||||
): HTMLElementTagNameMap[K] {
|
||||
const child = document.createElement(tag);
|
||||
if (options.id !== undefined) {
|
||||
child.id = options.id;
|
||||
}
|
||||
if (options.className !== undefined) {
|
||||
child.className = options.className;
|
||||
}
|
||||
if (options.text !== undefined) {
|
||||
child.textContent = options.text;
|
||||
}
|
||||
parent.append(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
function svgElement<K extends keyof SVGElementTagNameMap>(
|
||||
parent: Element,
|
||||
tag: K,
|
||||
attributes: Record<string, string | number>,
|
||||
): SVGElementTagNameMap[K] {
|
||||
const child = document.createElementNS(SVG_NS, tag);
|
||||
for (const [name, value] of Object.entries(attributes)) {
|
||||
child.setAttribute(name, String(value));
|
||||
}
|
||||
parent.append(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
/** L'adresse d'une décision : l'analyse de sa partie, sur son coup. */
|
||||
function decisionHref(gameId: string, turn: number | null): string {
|
||||
return routeHash({ screen: "analysis", game: gameId, turn });
|
||||
}
|
||||
|
||||
const DICE_SIDE = {
|
||||
veryLucky: "for-2",
|
||||
lucky: "for-1",
|
||||
none: "even",
|
||||
unlucky: "against-1",
|
||||
veryUnlucky: "against-2",
|
||||
} as const;
|
||||
|
||||
export function createMatchSummaryView(options: MatchSummaryViewOptions): MatchSummaryView {
|
||||
const { section } = options;
|
||||
let drawn = "";
|
||||
let redrawCurve: (() => void) | null = null;
|
||||
window.addEventListener("resize", () => {
|
||||
if (!section.hidden) {
|
||||
redrawCurve?.();
|
||||
}
|
||||
});
|
||||
|
||||
function show(data: MatchSummaryData | null, missing = false): void {
|
||||
const key =
|
||||
data === null
|
||||
? `none|${missing}`
|
||||
: JSON.stringify({
|
||||
id: data.summary.match.id,
|
||||
phrases: data.phrases !== null,
|
||||
ready: data.summary.ready,
|
||||
games: data.summary.match.games.map((g) => g.id),
|
||||
curve: data.summary.curve.map((p) => p.chance),
|
||||
errors: data.summary.cubeErrors.map((e) => e.loss),
|
||||
review: data.summary.toReview?.advice.eventId ?? null,
|
||||
rate: data.summary.errorRate.perDecision,
|
||||
});
|
||||
if (key === drawn) {
|
||||
return;
|
||||
}
|
||||
drawn = key;
|
||||
section.replaceChildren();
|
||||
redrawCurve = null;
|
||||
delete section.dataset.ready;
|
||||
if (data === null) {
|
||||
element(section, "h1", { className: "progression-title", text: T.title });
|
||||
const status = element(section, "p", {
|
||||
id: "match-status",
|
||||
className: "progression-summary",
|
||||
text: missing ? T.missing : T.loading,
|
||||
});
|
||||
status.setAttribute("role", "status");
|
||||
return;
|
||||
}
|
||||
render(data);
|
||||
}
|
||||
|
||||
function render(data: MatchSummaryData): void {
|
||||
const { summary, phrases } = data;
|
||||
const { match } = summary;
|
||||
section.dataset.match = match.id;
|
||||
// Paysage : deux colonnes (charte) ; en portrait, l'une sous l'autre.
|
||||
const left = element(section, "div", { className: "match-column match-main" });
|
||||
const right = element(section, "div", { className: "match-column match-side" });
|
||||
|
||||
// 1. L'en-tête.
|
||||
const head = element(left, "header", { className: "match-head" });
|
||||
element(head, "p", {
|
||||
id: "match-overline",
|
||||
className: "overline",
|
||||
text: T.overline(match),
|
||||
});
|
||||
element(head, "h1", {
|
||||
id: "match-title",
|
||||
className: "progression-title",
|
||||
text: T.headline(match),
|
||||
});
|
||||
element(head, "p", {
|
||||
id: "match-sentence",
|
||||
className: "progression-summary",
|
||||
text: T.sentence(summary),
|
||||
});
|
||||
if (match.inferred) {
|
||||
element(head, "p", { id: "match-inferred", className: "caption", text: T.inferred });
|
||||
}
|
||||
if (!summary.ready) {
|
||||
element(head, "p", {
|
||||
id: "match-analysing",
|
||||
className: "muted",
|
||||
text: T.analysing,
|
||||
}).setAttribute("role", "status");
|
||||
}
|
||||
|
||||
// 2. La courbe.
|
||||
curveCard(left, summary);
|
||||
|
||||
// 3. Partie par partie.
|
||||
gamesCard(left, summary);
|
||||
|
||||
// 4. Votre jeu sur le match.
|
||||
if (phrases !== null) {
|
||||
playCard(right, summary, phrases);
|
||||
cubeCard(right, summary, phrases);
|
||||
decisiveCard(right, summary, phrases);
|
||||
reviewCard(right, summary, phrases);
|
||||
}
|
||||
|
||||
// 8. L'export, puis la barre d'actions.
|
||||
const exportBox = element(right, "p", { className: "match-export" });
|
||||
const exportButton = element(exportBox, "button", {
|
||||
id: "match-export",
|
||||
className: "link-button",
|
||||
text: T.exportSgf,
|
||||
});
|
||||
exportButton.type = "button";
|
||||
const exportHint = element(exportBox, "span", {
|
||||
className: "caption",
|
||||
text: ` ${T.exportHint}`,
|
||||
});
|
||||
exportButton.onclick = () => {
|
||||
exportHint.textContent = ` ${T.exportHint}`;
|
||||
options.exportSgf(summary).catch((error: unknown) => {
|
||||
exportHint.textContent = ` ${T.exportFailed(error instanceof Error ? error.message : String(error))}`;
|
||||
});
|
||||
};
|
||||
const bar = element(right, "div", { className: "panel-actions match-actions" });
|
||||
const firstGame = match.games[0];
|
||||
if (firstGame !== undefined) {
|
||||
const again = element(bar, "a", {
|
||||
id: "match-review",
|
||||
className: "button secondary",
|
||||
text: T.reviewMatch,
|
||||
});
|
||||
again.href = decisionHref(firstGame.id, 1);
|
||||
}
|
||||
if (match.over) {
|
||||
const start = element(bar, "a", {
|
||||
id: "match-primary",
|
||||
className: "button",
|
||||
text: T.newMatch,
|
||||
});
|
||||
start.href = routeHash({ screen: "newGame" });
|
||||
} else {
|
||||
const resume = element(bar, "button", {
|
||||
id: "match-primary",
|
||||
text: T.resumeMatch,
|
||||
});
|
||||
resume.type = "button";
|
||||
resume.onclick = () => options.resume(summary);
|
||||
}
|
||||
section.dataset.ready = String(summary.ready);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ Courbe
|
||||
|
||||
function curveCard(parent: HTMLElement, summary: MatchSummary): void {
|
||||
const card = element(parent, "section", {
|
||||
id: "match-curve-card",
|
||||
className: "analysis-card match-curve-card",
|
||||
});
|
||||
element(card, "h2", { className: "overline", text: T.curveTitle });
|
||||
const svg = document.createElementNS(SVG_NS, "svg");
|
||||
svg.id = "match-curve";
|
||||
svg.setAttribute("class", "analysis-curve match-curve");
|
||||
svg.setAttribute("role", "img");
|
||||
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) {
|
||||
const item = element(legend, "li");
|
||||
const dot = element(item, "span", { className: `match-mark ${mark}` });
|
||||
dot.setAttribute("aria-hidden", "true");
|
||||
item.append(text);
|
||||
}
|
||||
const points = summary.curve;
|
||||
const known = points.filter((p) => p.chance !== null);
|
||||
if (known.length < points.length) {
|
||||
element(card, "p", { className: "caption", text: T.pending });
|
||||
}
|
||||
const chances = known.map((p) => p.chance as number);
|
||||
const decisive = summary.decisive;
|
||||
svg.setAttribute(
|
||||
"aria-label",
|
||||
known.length === 0
|
||||
? T.pending
|
||||
: T.curveLabel(
|
||||
percent(chances[0] ?? 0.5),
|
||||
percent(Math.min(...chances)),
|
||||
percent(chances.at(-1) ?? 0.5),
|
||||
decisive === null ? "" : T.curveDecisive(decisive.game, decisive.turn),
|
||||
),
|
||||
);
|
||||
svg.dataset.points = JSON.stringify(points.map((p) => [p.game, p.turn, p.chance]));
|
||||
let selected: number | null = null;
|
||||
const draw = () => drawCurve(svg, summary, selected);
|
||||
redrawCurve = draw;
|
||||
draw();
|
||||
|
||||
// Lecture au doigt : glisser choisit le point sous le doigt (une
|
||||
// vibration légère à chaque changement de partie) ; lâcher garde la
|
||||
// bulle, qui ouvre la décision.
|
||||
const indexAt = (clientX: number): number => {
|
||||
const box = svg.getBoundingClientRect();
|
||||
const inner = Math.max(1, box.width - PAD.left - PAD.right);
|
||||
const step = points.length > 1 ? inner / (points.length - 1) : inner;
|
||||
const i = Math.round((clientX - box.left - PAD.left) / step);
|
||||
return Math.min(points.length - 1, Math.max(0, i));
|
||||
};
|
||||
const choose = (index: number) => {
|
||||
if (index === selected) {
|
||||
return;
|
||||
}
|
||||
const before = selected === null ? null : points[selected]?.game;
|
||||
selected = index;
|
||||
if (before !== undefined && before !== null && before !== points[index]?.game) {
|
||||
options.vibrate();
|
||||
}
|
||||
draw();
|
||||
};
|
||||
let dragging = false;
|
||||
svg.addEventListener("pointerdown", (event) => {
|
||||
if ((event.target as Element).closest(".match-bubble") !== null) {
|
||||
return;
|
||||
}
|
||||
dragging = true;
|
||||
svg.setPointerCapture?.(event.pointerId);
|
||||
choose(indexAt(event.clientX));
|
||||
});
|
||||
svg.addEventListener("pointermove", (event) => {
|
||||
if (dragging) {
|
||||
choose(indexAt(event.clientX));
|
||||
}
|
||||
});
|
||||
for (const end of ["pointerup", "pointercancel"] as const) {
|
||||
svg.addEventListener(end, () => {
|
||||
dragging = false;
|
||||
});
|
||||
}
|
||||
svg.addEventListener("keydown", (event) => {
|
||||
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const from = selected ?? (event.key === "ArrowLeft" ? points.length : -1);
|
||||
choose(
|
||||
Math.min(
|
||||
points.length - 1,
|
||||
Math.max(0, from + (event.key === "ArrowLeft" ? -1 : 1)),
|
||||
),
|
||||
);
|
||||
} else if (event.key === "Enter" && selected !== null) {
|
||||
const point = points[selected];
|
||||
if (point !== undefined) {
|
||||
event.preventDefault();
|
||||
location.hash = decisionHref(point.gameId, point.turn);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------------------------------- Partie par partie
|
||||
|
||||
function gamesCard(parent: HTMLElement, summary: MatchSummary): void {
|
||||
const card = element(parent, "section", { id: "match-games", className: "match-games" });
|
||||
element(card, "h2", { className: "overline", text: T.gamesTitle });
|
||||
const list = element(card, "ol", { className: "progression-list match-game-list" });
|
||||
for (const row of summary.rows) {
|
||||
const li = element(list, "li", { className: "progression-item" });
|
||||
li.dataset.game = String(row.number);
|
||||
const link = element(li, "a", { className: "progression-game match-game" });
|
||||
link.href = routeHash({ screen: "summary", game: row.id });
|
||||
const result = T.gameResult(row.result, row.cube);
|
||||
const points = T.gamePoints(row.result);
|
||||
const after = row.scoreAfter === null ? "" : matchScoreText(row.scoreAfter);
|
||||
link.setAttribute("aria-label", T.gameRowLabel(row.number, result, points, after));
|
||||
const text = element(link, "span", { className: "progression-text" });
|
||||
element(text, "strong", {
|
||||
text: `${T.gameRow(row.number)}${row.crawford ? ` · ${T.crawford}` : ""}`,
|
||||
});
|
||||
element(text, "span", {
|
||||
className: "caption",
|
||||
text: points === "" ? result : `${result} · ${points}`,
|
||||
});
|
||||
const score = element(link, "span", { className: "match-game-score", text: after });
|
||||
score.setAttribute("aria-hidden", "true");
|
||||
link.append(icon("chevron"));
|
||||
}
|
||||
element(card, "p", { className: "caption", text: T.scoreReminder });
|
||||
}
|
||||
|
||||
// ------------------------------------------------- Votre jeu
|
||||
|
||||
function playCard(parent: HTMLElement, summary: MatchSummary, phrases: MasterPhrases): void {
|
||||
const card = element(parent, "section", { id: "match-play", className: "analysis-card" });
|
||||
element(card, "h2", { className: "overline", text: T.playTitle });
|
||||
const tiles = element(card, "div", { className: "match-tiles" });
|
||||
for (const [key, rate] of [
|
||||
["all", summary.errorRate],
|
||||
["chequer", summary.chequer],
|
||||
["cube", summary.cube],
|
||||
] as const) {
|
||||
const tile = element(tiles, "div", { className: "match-tile" });
|
||||
tile.dataset.tile = key;
|
||||
element(tile, "span", { className: "caption", text: T.tiles[key] });
|
||||
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 box = element(card, "div", { className: "summary-gauges" });
|
||||
const level = summary.errorRate.level;
|
||||
const levelName = MATCH_TEXTS.levels[level].name;
|
||||
const play = element(box, "div", { id: "match-gauge-play", className: "gauge" });
|
||||
play.setAttribute("aria-label", REVIEW_TEXTS.playGauge(levelName));
|
||||
play.setAttribute("role", "img");
|
||||
element(play, "span", { className: "gauge-name", text: REVIEW_TEXTS.yourPlay });
|
||||
const track = element(play, "span", { className: "gauge-track" });
|
||||
element(track, "span", {
|
||||
className: `gauge-fill level-${COMPUTER_LEVELS.indexOf(level) + 1}`,
|
||||
});
|
||||
element(play, "span", { className: "gauge-value", text: levelName });
|
||||
const words = diceWords(phrases, summary.luck.rating);
|
||||
const dice = element(box, "div", { id: "match-gauge-dice", className: "gauge" });
|
||||
dice.setAttribute("aria-label", REVIEW_TEXTS.diceGauge(words));
|
||||
dice.setAttribute("role", "img");
|
||||
element(dice, "span", { className: "gauge-name", text: REVIEW_TEXTS.theDice });
|
||||
const centred = element(dice, "span", { className: "gauge-track centred" });
|
||||
element(centred, "span", {
|
||||
className: `gauge-fill dice ${DICE_SIDE[summary.luck.rating]}`,
|
||||
});
|
||||
element(dice, "span", { className: "gauge-value", text: words });
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- Le videau
|
||||
|
||||
function cubeCard(parent: HTMLElement, summary: MatchSummary, phrases: MasterPhrases): void {
|
||||
const card = element(parent, "section", { id: "match-cube", className: "analysis-card" });
|
||||
element(card, "h2", { className: "overline", text: T.cubeTitle });
|
||||
element(card, "p", {
|
||||
id: "match-cube-sentence",
|
||||
className: "match-sentence",
|
||||
text: matchCubeSentence(phrases, summary.cubeDecisions, summary.cubeErrors.length),
|
||||
});
|
||||
if (summary.cubeErrors.length > 0) {
|
||||
const list = element(card, "ul", { className: "match-cube-list" });
|
||||
for (const error of summary.cubeErrors) {
|
||||
const li = element(list, "li", { className: "match-cube-item" });
|
||||
li.dataset.kind = error.kind;
|
||||
const link = element(li, "a", { className: "match-cube-row" });
|
||||
link.href = decisionHref(error.gameId, error.turn);
|
||||
const where = T.cubeWhere(error.game, error.turn, matchScoreText(error.score));
|
||||
const loss = error.loss === null ? T.cubeLossPending : formatMatchLoss(error.loss);
|
||||
link.setAttribute(
|
||||
"aria-label",
|
||||
T.cubeRowLabel(CUBE_ERROR_WORDS[error.kind], where, loss),
|
||||
);
|
||||
const text = element(link, "span", { className: "progression-text" });
|
||||
element(text, "strong", { text: CUBE_ERROR_WORDS[error.kind] });
|
||||
element(text, "span", { className: "caption", text: where });
|
||||
const value = element(link, "span", { className: "match-loss", text: loss });
|
||||
value.dataset.verdict = error.advice.skill === "none" ? "good" : error.advice.skill;
|
||||
value.setAttribute("aria-hidden", "true");
|
||||
link.append(icon("chevron"));
|
||||
}
|
||||
}
|
||||
for (const sentence of matchCubeAgreements(phrases, cubeKindsWithoutError(summary))) {
|
||||
element(card, "p", { className: "match-agreement caption", text: sentence });
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------- Le moment décisif
|
||||
|
||||
function decisiveCard(
|
||||
parent: HTMLElement,
|
||||
summary: MatchSummary,
|
||||
phrases: MasterPhrases,
|
||||
): void {
|
||||
const card = element(parent, "section", {
|
||||
id: "match-decisive",
|
||||
className: "analysis-card",
|
||||
});
|
||||
element(card, "h2", { className: "overline", text: T.decisiveTitle });
|
||||
const moment = summary.decisive;
|
||||
if (moment === null) {
|
||||
element(card, "p", { className: "muted", text: T.decisiveNone });
|
||||
return;
|
||||
}
|
||||
element(card, "p", {
|
||||
id: "match-decisive-sentence",
|
||||
className: "match-sentence",
|
||||
text: decisiveSentence(phrases, moment),
|
||||
});
|
||||
const link = element(card, "a", {
|
||||
id: "match-decisive-link",
|
||||
className: "link-button",
|
||||
text: T.seeThisMove,
|
||||
});
|
||||
link.href = decisionHref(moment.gameId, moment.turn);
|
||||
}
|
||||
|
||||
// ------------------------------------------- La décision à revoir
|
||||
|
||||
function reviewCard(parent: HTMLElement, summary: MatchSummary, phrases: MasterPhrases): void {
|
||||
const card = element(parent, "section", {
|
||||
id: "match-to-review",
|
||||
className: "summary-review analysis-card",
|
||||
});
|
||||
element(card, "h2", { className: "overline", text: T.reviewTitle });
|
||||
const reviewed = summary.toReview;
|
||||
if (reviewed === null) {
|
||||
element(card, "p", { className: "summary-none", text: nothingToReview(phrases) });
|
||||
return;
|
||||
}
|
||||
const advice = reviewed.advice;
|
||||
const words = masterWords(phrases, advice);
|
||||
const body = element(card, "div", { className: "summary-review-body" });
|
||||
const box = element(body, "div", { className: "summary-board-box" });
|
||||
const svg = boardSvg(box, "match-board", "summary-board");
|
||||
svg.setAttribute("aria-label", REVIEW_TEXTS.toReviewBoard);
|
||||
void options
|
||||
.stepsBefore(reviewed.gameId, advice)
|
||||
.then((steps) => {
|
||||
if (steps !== null) {
|
||||
drawSteps(svg, steps, steps.halfMoves.length, true, "match-");
|
||||
}
|
||||
})
|
||||
.catch(() => undefined);
|
||||
const text = element(body, "div", { className: "summary-review-text" });
|
||||
const verdict = element(text, "p", { className: "summary-verdict" });
|
||||
verdict.dataset.verdict = words.verdict;
|
||||
verdict.append(icon(VERDICT_ICONS[words.verdict]), `${words.word} · ${words.context}`);
|
||||
element(text, "p", {
|
||||
className: "caption",
|
||||
text: T.reviewWhere(reviewed.game, reviewed.turn, matchScoreText(reviewed.score)),
|
||||
});
|
||||
if (reviewed.loss !== null) {
|
||||
const loss = element(text, "p", {
|
||||
id: "match-review-loss",
|
||||
className: "match-loss",
|
||||
text: T.lossOf(formatMatchLoss(reviewed.loss)),
|
||||
});
|
||||
loss.dataset.verdict = words.verdict;
|
||||
}
|
||||
element(text, "p", {
|
||||
className: "summary-master",
|
||||
text:
|
||||
advice.kind === "move"
|
||||
? REVIEW_TEXTS.yourMove(advice.played.notation)
|
||||
: REVIEW_TEXTS.yourDecision(REVIEW_TEXTS.cubeActions[advice.action]),
|
||||
});
|
||||
element(text, "p", { className: "summary-master", text: words.title });
|
||||
const links = element(card, "div", { className: "summary-review-actions" });
|
||||
const revisit = element(links, "a", {
|
||||
id: "match-revisit",
|
||||
className: "button secondary",
|
||||
text: T.review,
|
||||
});
|
||||
revisit.href = decisionHref(reviewed.gameId, reviewed.turn);
|
||||
const slot = element(links, "div", { className: "ask-ai-slot" });
|
||||
askAiLink(
|
||||
slot,
|
||||
"match-ask-ai",
|
||||
routeHash({ screen: "matchSummary", match: summary.match.id, ai: true }),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
show,
|
||||
hide() {
|
||||
drawn = "";
|
||||
redrawCurve = null;
|
||||
section.replaceChildren();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* La courbe : un point par décision (le début du match, puis chaque tour de
|
||||
* chaque partie), une seule ligne de 0 à 100 % ; un trait vertical entre
|
||||
* les parties, le score au début de chacune au-dessus, son nom court en
|
||||
* dessous ; la partie Crawford sur fond creusé ; la ligne des 50 % en
|
||||
* pointillés ; trois marques (moment décisif, décision à revoir, fin) ; la
|
||||
* 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;
|
||||
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
||||
svg.replaceChildren();
|
||||
const points = summary.curve;
|
||||
const inner = width - PAD.left - PAD.right;
|
||||
const step = points.length > 1 ? inner / (points.length - 1) : 0;
|
||||
const x = (i: number) => PAD.left + i * step;
|
||||
const y = (chance: number) => PAD.top + (1 - chance) * (height - PAD.top - PAD.bottom);
|
||||
|
||||
// Les parties : de leur premier point (le dernier de la précédente) à
|
||||
// leur dernier.
|
||||
const spans = summary.rows.map((row) => {
|
||||
const indexes = points.flatMap((p, i) => (p.game === row.number ? [i] : []));
|
||||
const first = indexes[0] ?? 0;
|
||||
const last = indexes.at(-1) ?? first;
|
||||
return { row, from: row.number === 1 ? first : Math.max(0, first - 1), to: last };
|
||||
});
|
||||
for (const span of spans) {
|
||||
if (span.row.crawford) {
|
||||
svgElement(svg, "rect", {
|
||||
x: x(span.from),
|
||||
y: PAD.top,
|
||||
width: Math.max(2, x(span.to) - x(span.from)),
|
||||
height: height - PAD.top - PAD.bottom,
|
||||
class: "match-crawford",
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const level of [1, 0.5, 0]) {
|
||||
svgElement(svg, "line", {
|
||||
x1: PAD.left,
|
||||
x2: width - PAD.right,
|
||||
y1: y(level),
|
||||
y2: y(level),
|
||||
class: level === 0.5 ? "curve-half" : "curve-axis",
|
||||
});
|
||||
const label = svgElement(svg, "text", {
|
||||
x: PAD.left - 6,
|
||||
y: y(level) + 4,
|
||||
class: "curve-label",
|
||||
"text-anchor": "end",
|
||||
});
|
||||
label.textContent = percent(level);
|
||||
}
|
||||
for (const span of spans) {
|
||||
if (span.row.number > 1) {
|
||||
svgElement(svg, "line", {
|
||||
x1: x(span.from),
|
||||
x2: x(span.from),
|
||||
y1: PAD.top,
|
||||
y2: height - PAD.bottom,
|
||||
class: "match-separator",
|
||||
});
|
||||
}
|
||||
const middle = (x(span.from) + x(span.to)) / 2;
|
||||
const score = svgElement(svg, "text", {
|
||||
x: middle,
|
||||
y: PAD.top - 9,
|
||||
class: "curve-label match-score",
|
||||
"text-anchor": "middle",
|
||||
});
|
||||
score.textContent = matchScoreText(span.row.scoreBefore);
|
||||
const name = svgElement(svg, "text", {
|
||||
x: middle,
|
||||
y: height - 8,
|
||||
class: "curve-label",
|
||||
"text-anchor": "middle",
|
||||
});
|
||||
name.textContent = T.gameShort(span.row.number);
|
||||
}
|
||||
|
||||
const known = points.flatMap((p, i) => (p.chance === null ? [] : [{ i, p, c: p.chance }]));
|
||||
if (known.length > 0) {
|
||||
svgElement(svg, "polyline", {
|
||||
points: known.map(({ i, c }) => `${x(i)},${y(c)}`).join(" "),
|
||||
class: "curve-line",
|
||||
});
|
||||
}
|
||||
const indexOf = (game: number, turn: number) =>
|
||||
points.findIndex((p) => p.game === game && p.turn === turn);
|
||||
const mark = (i: number, cls: string, r: number) => {
|
||||
const c = points[i]?.chance;
|
||||
if (i >= 0 && c !== null && c !== undefined) {
|
||||
svgElement(svg, "circle", { cx: x(i), cy: y(c), r, class: cls }).setAttribute(
|
||||
"aria-hidden",
|
||||
"true",
|
||||
);
|
||||
}
|
||||
};
|
||||
const decisive = summary.decisive;
|
||||
if (decisive !== null) {
|
||||
mark(indexOf(decisive.game, decisive.turn), "match-mark-ring", 8);
|
||||
}
|
||||
const reviewed = summary.toReview;
|
||||
if (reviewed !== null) {
|
||||
mark(indexOf(reviewed.game, reviewed.turn), "match-mark-review", 5);
|
||||
}
|
||||
if (summary.match.over) {
|
||||
mark(
|
||||
points.length - 1,
|
||||
summary.match.winner === "player" ? "match-mark-end won" : "match-mark-end",
|
||||
5,
|
||||
);
|
||||
}
|
||||
|
||||
// Le point choisi : un trait qui suit le doigt, et la bulle.
|
||||
const point = selected === null ? undefined : points[selected];
|
||||
if (selected !== null && point !== undefined) {
|
||||
svgElement(svg, "line", {
|
||||
x1: x(selected),
|
||||
x2: x(selected),
|
||||
y1: PAD.top,
|
||||
y2: height - PAD.bottom,
|
||||
class: "curve-cursor",
|
||||
});
|
||||
bubble(svg, summary, point, x(selected), width);
|
||||
}
|
||||
}
|
||||
|
||||
/** La bulle du point choisi : partie, coup, score, chances ; un lien SVG
|
||||
* vers la décision dans l'analyse. */
|
||||
function bubble(
|
||||
svg: SVGSVGElement,
|
||||
summary: MatchSummary,
|
||||
point: MatchCurvePoint,
|
||||
cx: number,
|
||||
width: number,
|
||||
): void {
|
||||
const row = summary.rows[point.game - 1];
|
||||
const score = row === undefined ? "" : matchScoreText(row.scoreBefore);
|
||||
const chance = point.chance === null ? REVIEW_TEXTS.curveUnknown : percent(point.chance);
|
||||
const link = svgElement(svg, "a", {
|
||||
href: decisionHref(point.gameId, point.turn),
|
||||
class: "match-bubble",
|
||||
id: "match-bubble",
|
||||
});
|
||||
link.setAttribute(
|
||||
"aria-label",
|
||||
`${T.bubble(point.game, point.turn, score, chance)}. ${T.bubbleOpen}`,
|
||||
);
|
||||
const left = Math.min(Math.max(4, cx - BUBBLE.width / 2), width - BUBBLE.width - 4);
|
||||
svgElement(link, "rect", {
|
||||
x: left,
|
||||
y: 2,
|
||||
width: BUBBLE.width,
|
||||
height: BUBBLE.height,
|
||||
rx: 8,
|
||||
class: "match-bubble-box",
|
||||
});
|
||||
const line1 = svgElement(link, "text", {
|
||||
x: left + 10,
|
||||
y: 19,
|
||||
class: "match-bubble-text",
|
||||
});
|
||||
line1.textContent = T.bubble(point.game, point.turn, score, chance);
|
||||
const line2 = svgElement(link, "text", {
|
||||
x: left + 10,
|
||||
y: 36,
|
||||
class: "match-bubble-hint",
|
||||
});
|
||||
line2.textContent = T.bubbleOpen;
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
// (domain/analysis/progression.ts), et la redessine quand une analyse en
|
||||
// arrière-plan se termine.
|
||||
|
||||
import type { PlayedMatch } from "../domain/analysis/match-analysis.js";
|
||||
import type { MasterPhrases } from "../domain/analysis/phrases.js";
|
||||
import { progressionSentence } from "../domain/analysis/phrases.js";
|
||||
import {
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
} from "../domain/analysis/progression.js";
|
||||
import { computerLevelOf } from "../domain/game/level.js";
|
||||
import { icon } from "./icons.js";
|
||||
import { type MatchLine, renderMatchLine } from "./match-line.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { PROGRESSION_TEXTS } from "./progression-texts.js";
|
||||
import { routeHash } from "./router.js";
|
||||
@@ -31,12 +33,17 @@ import { routeHash } from "./router.js";
|
||||
export interface ProgressionData {
|
||||
/** Les parties terminées, de la plus ancienne à la plus récente. */
|
||||
readonly entries: readonly ProgressionEntry[];
|
||||
/** Les matchs (étape 1l) : chacun tient en une ligne dans la liste, à
|
||||
* la place de ses parties (la courbe garde un point par partie). */
|
||||
readonly matches: readonly MatchLine[];
|
||||
/** Les phrases du maître (null : pas encore lues). */
|
||||
readonly phrases: MasterPhrases | null;
|
||||
}
|
||||
|
||||
export interface ProgressionViewOptions {
|
||||
readonly section: HTMLElement;
|
||||
/** « Reprendre » sur la ligne d'un match en cours. */
|
||||
readonly resumeMatch: (match: PlayedMatch) => void;
|
||||
}
|
||||
|
||||
export interface ProgressionView {
|
||||
@@ -129,6 +136,12 @@ export function createProgressionView(options: ProgressionViewOptions): Progress
|
||||
e.level,
|
||||
e.errorRate?.perDecision ?? null,
|
||||
]),
|
||||
matches: data.matches.map((m) => [
|
||||
m.match.id,
|
||||
m.match.games.map((g) => g.id),
|
||||
m.match.score,
|
||||
m.errorRate,
|
||||
]),
|
||||
},
|
||||
);
|
||||
if (key === drawn) {
|
||||
@@ -211,9 +224,29 @@ export function createProgressionView(options: ProgressionViewOptions): Progress
|
||||
|
||||
element(body, "h3", { className: "overline", text: PROGRESSION_TEXTS.listTitle });
|
||||
const list = element(body, "ol", { id: "progression-list", className: "progression-list" });
|
||||
// La plus récente d'abord, comme « Mes parties ».
|
||||
for (const entry of [...data.entries].reverse()) {
|
||||
list.append(item(entry));
|
||||
// La plus récente d'abord, comme « Mes parties » ; un match en une
|
||||
// ligne, à la date de sa partie la plus récente de la liste.
|
||||
const shown = new Set(data.entries.map((e) => e.id));
|
||||
const matches = data.matches.filter((m) => m.match.games.some((g) => shown.has(g.id)));
|
||||
const inMatch = new Set(matches.flatMap((m) => m.match.games.map((g) => g.id)));
|
||||
const lines = [
|
||||
...data.entries
|
||||
.filter((entry) => !inMatch.has(entry.id))
|
||||
.map((entry) => ({ at: entry.startedAt, add: () => list.append(item(entry)) })),
|
||||
...matches.map((line) => ({
|
||||
at: Math.max(
|
||||
...line.match.games.filter((g) => shown.has(g.id)).map((g) => g.startedAt),
|
||||
),
|
||||
add: () => {
|
||||
const li = document.createElement("li");
|
||||
li.className = "progression-item progression-match";
|
||||
renderMatchLine(li, line, () => options.resumeMatch(line.match));
|
||||
list.append(li);
|
||||
},
|
||||
})),
|
||||
].sort((a, b) => b.at - a.at);
|
||||
for (const line of lines) {
|
||||
line.add();
|
||||
}
|
||||
section.dataset.ready = String(waiting === 0);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import type { MatchSummary } from "../domain/analysis/match-analysis.js";
|
||||
import type { MasterPhrases } from "../domain/analysis/phrases.js";
|
||||
import type { Advice } from "../domain/game/advice.js";
|
||||
import type { GameJournal } from "../domain/game/events.js";
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
conceptPrompt,
|
||||
decisionPrompt,
|
||||
exercisesPrompt,
|
||||
matchPrompt,
|
||||
summaryPrompt,
|
||||
} from "../domain/prompts/prompts.js";
|
||||
import {
|
||||
@@ -44,6 +46,9 @@ export interface PromptsAccess {
|
||||
/** La position de la plus coûteuse des erreurs de ces parties (null :
|
||||
* aucune imprécision ni erreur). */
|
||||
readonly exercises: (journals: readonly GameJournal[]) => Promise<PromptPosition | null>;
|
||||
/** La position que montre le prompt du bilan du match (décision à
|
||||
* revoir, ou position finale). */
|
||||
readonly match: (summary: MatchSummary) => Promise<PromptPosition>;
|
||||
}
|
||||
|
||||
export interface PromptSourceOptions {
|
||||
@@ -63,6 +68,8 @@ export interface PromptSource {
|
||||
/** Le prompt « Créer des exercices » (progression, étape 1h), sur les
|
||||
* parties analysées, de la plus ancienne à la plus récente. */
|
||||
exercises(journals: readonly GameJournal[]): Promise<PromptResult>;
|
||||
/** Le prompt « Bilan de mon match » (étape 1l). */
|
||||
match(summary: MatchSummary): Promise<PromptResult>;
|
||||
}
|
||||
|
||||
async function fetchText(url: string): Promise<string> {
|
||||
@@ -128,6 +135,14 @@ export function createPromptSource(options: PromptSourceOptions): PromptSource {
|
||||
}
|
||||
return { text: exercisesPrompt(all, phrases, { journals, position }) };
|
||||
},
|
||||
async match(summary) {
|
||||
const [all, phrases, position] = await Promise.all([
|
||||
templates(),
|
||||
options.phrases(),
|
||||
options.access.match(summary),
|
||||
]);
|
||||
return { text: matchPrompt(all, phrases, { summary, position }) };
|
||||
},
|
||||
async concept(term, journal) {
|
||||
const [all, entry, example] = await Promise.all([
|
||||
templates(),
|
||||
|
||||
+21
-1
@@ -54,6 +54,9 @@ export type Route =
|
||||
readonly turn: number | null;
|
||||
readonly ai?: boolean;
|
||||
}
|
||||
/** #/matchs/<identifiant>/bilan : le bilan d'un match entier (étape
|
||||
* 1l) ; son prompt pour une IA : #/matchs/<identifiant>/bilan/ia. */
|
||||
| { readonly screen: "matchSummary"; readonly match: string; readonly ai?: boolean }
|
||||
/** #/progression : l'historique des parties et la courbe du taux
|
||||
* d'erreur (étape 1h) ; le prompt « Créer des exercices » :
|
||||
* #/progression/ia. */
|
||||
@@ -114,6 +117,12 @@ export function parseRoute(hash: string): Route {
|
||||
if (head === "parties" && rest.length > 1) {
|
||||
return gameReviewRoute(rest) ?? unknown;
|
||||
}
|
||||
if (head === "matchs") {
|
||||
const [match = "", part, ...more] = rest;
|
||||
return NAME.test(match) && part === "bilan" && more.length === 0
|
||||
? { screen: "matchSummary", match }
|
||||
: unknown;
|
||||
}
|
||||
if (rest.length > 1) {
|
||||
return unknown;
|
||||
}
|
||||
@@ -156,7 +165,15 @@ export function parseRoute(hash: string): Route {
|
||||
/** Les écrans qui ont une feuille de prompt pour une IA. */
|
||||
export type AiRoute = Extract<
|
||||
Route,
|
||||
{ screen: "explanation" | "summary" | "analysis" | "glossary" | "progression" }
|
||||
{
|
||||
screen:
|
||||
| "explanation"
|
||||
| "summary"
|
||||
| "analysis"
|
||||
| "glossary"
|
||||
| "progression"
|
||||
| "matchSummary";
|
||||
}
|
||||
>;
|
||||
|
||||
/** L'écran, avec sa feuille de prompt ouverte (null : écran sans prompt). */
|
||||
@@ -166,6 +183,7 @@ function aiRoute(route: Route): AiRoute | null {
|
||||
case "summary":
|
||||
case "analysis":
|
||||
case "progression":
|
||||
case "matchSummary":
|
||||
return route.ai === true ? null : { ...route, ai: true };
|
||||
case "glossary":
|
||||
return route.term === null || route.ai === true ? null : { ...route, ai: true };
|
||||
@@ -316,6 +334,8 @@ function screenHash(route: Route): string {
|
||||
: `#/parties/${route.game}/analyse/${route.turn}`;
|
||||
case "progression":
|
||||
return "#/progression";
|
||||
case "matchSummary":
|
||||
return `#/matchs/${route.match}/bilan`;
|
||||
case "menu":
|
||||
return "#/menu";
|
||||
case "newGame":
|
||||
|
||||
@@ -30,6 +30,7 @@ import { COMPUTER_LEVELS } from "../domain/game/level.js";
|
||||
import { VERDICT_ICONS } from "./advice-view.js";
|
||||
import { askAiLink, clearSheet } from "./ask-ai.js";
|
||||
import { icon } from "./icons.js";
|
||||
import { MATCH_SUMMARY_TEXTS } from "./match-summary-texts.js";
|
||||
import { MATCH_TEXTS } from "./match-texts.js";
|
||||
import { boardSvg, drawSteps } from "./move-board.js";
|
||||
import { REVIEW_TEXTS } from "./review-texts.js";
|
||||
@@ -49,6 +50,13 @@ export interface SummaryData {
|
||||
* l'écran des choix. */
|
||||
readonly afterLabel: string | null;
|
||||
readonly phrases: MasterPhrases | null;
|
||||
/** Une partie de match (étape 1l) : sa place et le bilan du match
|
||||
* (null : partie libre, ou partie rattachée à aucun match). */
|
||||
readonly match: {
|
||||
readonly id: string;
|
||||
readonly number: number;
|
||||
readonly length: number;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface SummaryViewOptions {
|
||||
@@ -137,6 +145,7 @@ export function createSummaryView(options: SummaryViewOptions): SummaryView {
|
||||
data.end?.title ?? "",
|
||||
data.end?.detail ?? "",
|
||||
data.afterLabel ?? "",
|
||||
JSON.stringify(data.match),
|
||||
ready,
|
||||
JSON.stringify(shown),
|
||||
].join("|");
|
||||
@@ -166,6 +175,7 @@ export function createSummaryView(options: SummaryViewOptions): SummaryView {
|
||||
return;
|
||||
}
|
||||
title.textContent = data.end.title;
|
||||
matchLine(data);
|
||||
const reading = element(panel, "p", {
|
||||
id: "summary-reading",
|
||||
className: "summary-reading",
|
||||
@@ -191,6 +201,25 @@ export function createSummaryView(options: SummaryViewOptions): SummaryView {
|
||||
actions(data);
|
||||
}
|
||||
|
||||
/** « Partie 2 du match en 5 points · Bilan du match » (charte, « Bilan
|
||||
* du match », accès). */
|
||||
function matchLine(data: SummaryData): void {
|
||||
const match = data.match;
|
||||
if (match === null) {
|
||||
return;
|
||||
}
|
||||
const line = element(panel, "p", {
|
||||
id: "summary-match",
|
||||
className: "caption summary-match",
|
||||
});
|
||||
line.append(`${MATCH_SUMMARY_TEXTS.gameOfMatch(match.number, match.length)} · `);
|
||||
const link = element(line, "a", {
|
||||
id: "summary-match-link",
|
||||
text: MATCH_SUMMARY_TEXTS.seeMatchSummary,
|
||||
});
|
||||
link.href = routeHash({ screen: "matchSummary", match: match.id });
|
||||
}
|
||||
|
||||
function counts(summary: GameSummary): void {
|
||||
const box = element(panel, "div", { id: "summary-counts", className: "summary-counts" });
|
||||
box.setAttribute("role", "list");
|
||||
|
||||
@@ -399,3 +399,22 @@ test("le prompt « Bilan de mon match » cite le videau en chances de gagner le
|
||||
assert.match(prompt, /partie 4, coup 1\) : la position avant ma décision/);
|
||||
assert.equal(position.positionId, "wN1tAwADAAAAAA");
|
||||
});
|
||||
|
||||
test("une décision de videau dont la perte s'écrirait 0,0 % n'est pas listée", () => {
|
||||
const fourth = comeback[3] as MatchGame;
|
||||
const review = fourth.journal.review;
|
||||
assert.ok(review?.matchLosses !== undefined);
|
||||
const tiny = Object.fromEntries(Object.keys(review.matchLosses).map((id) => [id, -0.0004]));
|
||||
const games = comeback.map((g, i) =>
|
||||
i === 3 ? { ...g, journal: { ...g.journal, review: { ...review, matchLosses: tiny } } } : g,
|
||||
);
|
||||
const match = groupMatches(games).matches[0];
|
||||
assert.ok(match !== undefined);
|
||||
const summary = summarizeMatch(match);
|
||||
assert.equal(summary.cubeErrors.length, 0);
|
||||
assert.equal(summary.cubeDecisions, 1);
|
||||
assert.equal(
|
||||
matchCubeSentence(phrases, summary.cubeDecisions, 0),
|
||||
"Une seule décision de videau, comme je l'aurais prise.",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -49,6 +49,9 @@ const TABLE: [string, Route][] = [
|
||||
// La progression (étape 1h) et son prompt « Créer des exercices ».
|
||||
["#/progression", { screen: "progression" }],
|
||||
["#/progression/ia", { screen: "progression", ai: true }],
|
||||
// Le bilan d'un match entier (étape 1l) et son prompt.
|
||||
["#/matchs/mh3k2-a1b2c3/bilan", { screen: "matchSummary", match: "mh3k2-a1b2c3" }],
|
||||
["#/matchs/mh3k2-a1b2c3/bilan/ia", { screen: "matchSummary", match: "mh3k2-a1b2c3", ai: true }],
|
||||
["#/menu", { screen: "menu" }],
|
||||
["#/nouvelle-partie", { screen: "newGame" }],
|
||||
["#/explication/12", { screen: "explanation", event: "12" }],
|
||||
@@ -131,6 +134,11 @@ test("une adresse inconnue est reconnue comme telle", () => {
|
||||
"#/parties/ab/ia",
|
||||
"#/explication/12/ia/ia",
|
||||
"#/progression/x",
|
||||
"#/matchs",
|
||||
"#/matchs/m1",
|
||||
"#/matchs/M1/bilan",
|
||||
"#/matchs/m1/bilan/x",
|
||||
"#/matchs/m1/analyse",
|
||||
"#/progression/ia/ia",
|
||||
]) {
|
||||
assert.equal(parseRoute(hash).screen, "unknown", hash);
|
||||
|
||||
Reference in New Issue
Block a user