Domaine : abandon proposé, accepté ou refusé (événements version 3)
Trois événements d'abandon et le champ resigned de GameEnded, migration des versions 1 et 2 testée ; points selon le videau, score et Crawford du match par le moteur ; export SGF à la manière de gnubg (RE[W+4R]), relu par gnubg de bureau. Phrases abandon.refus et abandon.accepte, fiche Abandon, scénarios Gherkin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e98497e5b1
commit
de32811bba
@@ -0,0 +1,143 @@
|
||||
// Étapes du scénario docs/scenarios/abandonner-une-partie.feature (ADR
|
||||
// 0008) : le domaine branché sur le vrai moteur, depuis des positions de
|
||||
// référence comparées à gnubg de bureau (tests/reference/analyses.json,
|
||||
// abandons resign-…).
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { BeforeAll, Given, setDefaultTimeout, Then, When } from "@cucumber/cucumber";
|
||||
import type { Cube } from "../../src/domain/game/cube.js";
|
||||
import type { Engine, ResultKind } from "../../src/domain/game/engine.js";
|
||||
import { Game, type ResignChoice } from "../../src/domain/game/game.js";
|
||||
import { firstGameOf, type Match } from "../../src/domain/game/match.js";
|
||||
import { fixedDice } from "../../src/domain/game/roll.js";
|
||||
import { TEXTS } from "../../src/ui/texts.js";
|
||||
import { loadNodeEngine } from "../support/node-engine.js";
|
||||
|
||||
setDefaultTimeout(60_000);
|
||||
|
||||
// Le joueur au trait subit une attaque : gammon perdu à 49 % (0 pli).
|
||||
const ATTACKED = "sp2DBwDgOfgAaA";
|
||||
// Une attaque où le gammon est moins probable (36 %).
|
||||
const LESS_GAMMONS = "tF2DBwDgc/ABUA";
|
||||
const CUBE_2_COMPUTER: Cube = { value: 2, owner: "computer" };
|
||||
|
||||
let engine: Engine;
|
||||
let game: Game;
|
||||
let choices: ResignChoice[];
|
||||
let answer: boolean;
|
||||
|
||||
BeforeAll(async () => {
|
||||
engine = await loadNodeEngine();
|
||||
});
|
||||
|
||||
function start(position: string, cube?: Cube, match?: Match): void {
|
||||
game = Game.start(engine, {
|
||||
dice: fixedDice([3, 1]),
|
||||
setup: { position, firstTurn: "player", ...(cube === undefined ? {} : { cube }) },
|
||||
...(match === undefined ? {} : { match }),
|
||||
});
|
||||
}
|
||||
|
||||
const KINDS: Record<string, ResultKind> = {
|
||||
"une partie simple": "single",
|
||||
"un gammon": "gammon",
|
||||
"un backgammon": "backgammon",
|
||||
};
|
||||
|
||||
Given("l'ordinateur vous attaque, avec le videau à 2 chez lui, et qu'un gammon est probable", () =>
|
||||
start(ATTACKED, CUBE_2_COMPUTER),
|
||||
);
|
||||
|
||||
Given(
|
||||
"l'ordinateur vous attaque, avec le videau à 2 chez lui, et qu'un gammon est moins probable",
|
||||
() => start(LESS_GAMMONS, CUBE_2_COMPUTER),
|
||||
);
|
||||
|
||||
Given("la même position se joue en partie libre, videau au centre", () => start(LESS_GAMMONS));
|
||||
|
||||
Given("l'ordinateur vous attaque dans un match en 7 points, à 0 partout", () =>
|
||||
start(ATTACKED, undefined, firstGameOf(7)),
|
||||
);
|
||||
|
||||
When(/^vous proposez d'abandonner (une partie simple|un gammon|un backgammon)$/, async (what) => {
|
||||
const kind = KINDS[what as string];
|
||||
assert.ok(kind !== undefined);
|
||||
answer = await game.resign(kind);
|
||||
});
|
||||
|
||||
Then("l'ordinateur refuse", () => {
|
||||
assert.equal(answer, false);
|
||||
assert.deepEqual(
|
||||
game.events.slice(-2).map((e) => e.type),
|
||||
["ResignationOffered", "ResignationDeclined"],
|
||||
);
|
||||
});
|
||||
|
||||
Then("l'ordinateur accepte", () => {
|
||||
assert.equal(answer, true);
|
||||
assert.deepEqual(
|
||||
game.events.slice(-3).map((e) => e.type),
|
||||
["ResignationOffered", "ResignationAccepted", "GameEnded"],
|
||||
);
|
||||
});
|
||||
|
||||
Then("la partie continue, et c'est à vous de lancer les dés", async () => {
|
||||
assert.equal(game.state.phase, "rolling");
|
||||
assert.equal(game.state.turn, "player");
|
||||
// Le drapeau reste disponible.
|
||||
assert.ok((await game.resignOptions()).length > 0);
|
||||
});
|
||||
|
||||
Then(/^la partie est perdue par abandon, (.+)$/, (text) => {
|
||||
const result = game.state.result;
|
||||
assert.ok(result !== null);
|
||||
assert.equal(result.winner, "computer");
|
||||
assert.equal(result.resigned, true);
|
||||
assert.equal(TEXTS.resignedResult(result.kind, result.points), `Perdue par abandon, ${text}`);
|
||||
// Plus rien à proposer : la partie est finie.
|
||||
assert.equal(game.state.phase, "over");
|
||||
});
|
||||
|
||||
Then("vous pouvez proposer une partie simple, un gammon ou un backgammon", async () => {
|
||||
choices = await game.resignOptions();
|
||||
assert.deepEqual(
|
||||
choices.map((c) => [c.kind, c.points]),
|
||||
[
|
||||
["single", 2],
|
||||
["gammon", 4],
|
||||
["backgammon", 6],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
Then("vous ne pouvez proposer qu'une partie simple", async () => {
|
||||
choices = await game.resignOptions();
|
||||
assert.deepEqual(
|
||||
choices.map((c) => [c.kind, c.points, c.matchAfter]),
|
||||
[["single", 1, null]],
|
||||
);
|
||||
});
|
||||
|
||||
Then("chaque choix montre le score qui en résulterait", async () => {
|
||||
choices = await game.resignOptions();
|
||||
assert.deepEqual(
|
||||
choices.map((c) => [c.kind, c.matchAfter?.score.player, c.matchAfter?.score.computer]),
|
||||
[
|
||||
["single", 0, 1],
|
||||
["gammon", 0, 2],
|
||||
["backgammon", 0, 3],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
Then(/^le score du match devient : vous (\d+), l'ordinateur (\d+)$/, (player, computer) => {
|
||||
const after = game.state.matchAfter;
|
||||
assert.ok(after !== null);
|
||||
assert.deepEqual(after.score, { player: Number(player), computer: Number(computer) });
|
||||
assert.equal(after.over, false);
|
||||
// Le match continue : la partie suivante reprend ce score.
|
||||
assert.deepEqual(game.nextGame?.match?.score, after.score);
|
||||
});
|
||||
Reference in New Issue
Block a user