Moteur : chances de gagner le match (table de gnubg), export SGF d'un match entier

Commande mwc d'engine-cli et engine_match_chances_of : chances au score
(getMEAtScore) et conversion d'une équité (eq2mwc), comparées à gnubg de
bureau. Export d'un match entier en SGF, relu par gnubg (load match).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-12 23:55:51 +01:00
co-authored by Claude Opus 5.5
parent ee661661fd
commit f9b8663afb
21 changed files with 596 additions and 8 deletions
+41 -2
View File
@@ -15,8 +15,9 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { Game } from "../../src/domain/game/game.js";
import { exportSgf } from "../../src/domain/game/sgf.js";
import { Game, type NewGame } from "../../src/domain/game/game.js";
import { firstGameOf } from "../../src/domain/game/match.js";
import { exportMatchSgf, exportSgf } from "../../src/domain/game/sgf.js";
import { loadNodeEngine } from "../support/node-engine.js";
import { playMoves, playToTheEnd, seededDice, step } from "../support/play.js";
@@ -133,6 +134,44 @@ async function main(): Promise<void> {
}
game.goBackTo(original.head as string);
}
// Un match entier en 3 points (étape 1l), exporté d'un seul fichier :
// chaque partie à la suite, avec son numéro et le score avant elle. La
// première graine dont le match compte au moins trois parties.
for (let seed = 21; ; seed++) {
const dice = seededDice(seed);
const played: Game[] = [];
let next: Game | null = Game.start(engine, {
dice,
level: "0ply",
match: firstGameOf(3, "exemple"),
});
while (next !== null) {
await playToTheEnd(next, engine);
played.push(next);
const following: NewGame | null = next.nextGame;
next = following === null ? null : Game.start(engine, { ...following, dice });
}
if (played.length < 3) {
continue;
}
const sgf = await exportMatchSgf(
engine,
played.map((g) => g.journal),
{ playerName: "Vous", computerName: "Ordinateur", date: "2026-11-12" },
);
const expected = {
length: 3,
games: played.map((g) => ({
after: g.events.flatMap((e) => (e.type === "MovePlayed" ? [e.position] : [])),
result: g.state.result,
score: g.state.match?.score,
})),
};
writeFileSync(join(out, `match-${seed}.sgf`), sgf);
writeFileSync(join(out, `match-${seed}.json`), `${JSON.stringify(expected)}\n`);
files++;
break;
}
console.log(`${files} parties exportées dans ${out}`);
}