Domaine : lire et écrire le lien d'une position (ADR 0013)
Le moteur écrit et décode le Match ID ; readPosition valide un lien, linkOf donne celui d'une partie, setupOf la partie à jouer depuis la position. Scénario « Partager une position », fiche « Lien de position ». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3cdd017768
commit
43031d1ec6
@@ -22,12 +22,19 @@ import type {
|
||||
Level,
|
||||
Luck,
|
||||
LuckRating,
|
||||
MatchDescription,
|
||||
MatchId,
|
||||
Move,
|
||||
MoveAnalysis,
|
||||
Ply,
|
||||
Skill,
|
||||
} from "../domain/game/engine.js";
|
||||
import { formatHalfMoves, type HalfMove, type PositionId } from "../domain/game/position.js";
|
||||
import {
|
||||
formatHalfMoves,
|
||||
type HalfMove,
|
||||
type PositionId,
|
||||
START_POSITION,
|
||||
} from "../domain/game/position.js";
|
||||
import type { Roll } from "../domain/game/roll.js";
|
||||
|
||||
/** Exécute une commande d'engine-cli et renvoie son JSON décodé ; la
|
||||
@@ -208,6 +215,35 @@ export function createWasmEngine(run: RunCommand): Engine {
|
||||
return { value: answer.luck, rating };
|
||||
},
|
||||
|
||||
encodeMatch: matchId,
|
||||
|
||||
async decodeMatch(id: MatchId): Promise<MatchDescription> {
|
||||
// engine-cli n'a pas de commande qui décode seule un Match ID :
|
||||
// l'évaluation à 0 pli (quelques millisecondes) le décode, le
|
||||
// valide (SetCubeInfo de gnubg) et le renvoie lisible.
|
||||
const answer = (await run(["--ply", "0", "eval", START_POSITION, id])) as {
|
||||
match: {
|
||||
match_length: number;
|
||||
score: [number, number];
|
||||
cube_value: number;
|
||||
cube_owner: number;
|
||||
player_on_roll: number;
|
||||
crawford: boolean;
|
||||
jacoby: boolean;
|
||||
};
|
||||
};
|
||||
const m = answer.match;
|
||||
return {
|
||||
matchLength: m.match_length,
|
||||
score: m.score,
|
||||
cubeValue: m.cube_value,
|
||||
cubeOwner: m.cube_owner === 0 || m.cube_owner === 1 ? m.cube_owner : -1,
|
||||
playerOnRoll: m.player_on_roll === 1 ? 1 : 0,
|
||||
crawford: m.crawford,
|
||||
jacoby: m.jacoby,
|
||||
};
|
||||
},
|
||||
|
||||
async checkHalfMoves(
|
||||
position: PositionId,
|
||||
roll: Roll,
|
||||
|
||||
Reference in New Issue
Block a user