Saisie du coup : pion à destination unique, validation, Annuler, dés estompés, videau confirmé
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2c5278965b
commit
2d934529d5
@@ -80,6 +80,15 @@ async function play(text: string): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Joue les demi-coups puis valide le coup, complet. */
|
||||
async function playAndConfirm(text: string): Promise<boolean> {
|
||||
if (!(await play(text))) {
|
||||
return false;
|
||||
}
|
||||
await game.confirmMove();
|
||||
return true;
|
||||
}
|
||||
|
||||
function lastEvent(): GameEvent {
|
||||
const event = game.events.at(-1);
|
||||
assert.ok(event !== undefined, "aucun événement");
|
||||
@@ -160,12 +169,62 @@ Then("la position n'a pas changé", () => {
|
||||
assert.equal(lastEvent().type, "DiceRolled");
|
||||
});
|
||||
|
||||
// ------------------------------------------ Valider ou reprendre son coup
|
||||
|
||||
Then("votre coup attend votre validation", async () => {
|
||||
assert.equal(accepted, true);
|
||||
assert.equal(game.moveComplete, true);
|
||||
// Rien n'est encore dans le journal, et plus aucun pion ne bouge.
|
||||
assert.equal(lastEvent().type, "DiceRolled");
|
||||
assert.equal(game.state.turn, "player");
|
||||
assert.deepEqual(await game.nextHalfMoves(), []);
|
||||
});
|
||||
|
||||
Then("vos dés sont tous marqués comme joués", () => {
|
||||
assert.ok(game.diceToPlay.length > 0);
|
||||
assert.ok(game.diceToPlay.every((die) => die.used));
|
||||
});
|
||||
|
||||
When("vous validez votre coup", async () => {
|
||||
await game.confirmMove();
|
||||
});
|
||||
|
||||
Then("seul votre {int} est marqué comme joué", (value: number) => {
|
||||
const used = game.diceToPlay.filter((die) => die.used);
|
||||
assert.deepEqual(
|
||||
used.map((die) => die.value),
|
||||
[value],
|
||||
);
|
||||
});
|
||||
|
||||
Then("chacun de vos pions jouables n'a plus qu'une case d'arrivée", async () => {
|
||||
const halfMoves = await game.nextHalfMoves();
|
||||
assert.ok(halfMoves.length > 0);
|
||||
const starts = halfMoves.map((h) => h.from);
|
||||
assert.equal(new Set(starts).size, starts.length);
|
||||
});
|
||||
|
||||
When("vous annulez le dernier demi-coup", () => {
|
||||
game.undoLastHalfMove();
|
||||
});
|
||||
|
||||
Then("il ne reste de joué que {word}", (text: string) => {
|
||||
assert.deepEqual(game.pendingHalfMoves, parseHalfMoves(text));
|
||||
assert.equal(game.moveComplete, false);
|
||||
assert.equal(lastEvent().type, "DiceRolled");
|
||||
});
|
||||
|
||||
Then("aucun de vos dés n'est marqué comme joué", () => {
|
||||
assert.ok(game.diceToPlay.length > 0);
|
||||
assert.ok(game.diceToPlay.every((die) => !die.used));
|
||||
});
|
||||
|
||||
// ------------------------------------------------------- L'ordinateur joue
|
||||
|
||||
Given("c'est au tour de l'ordinateur", async () => {
|
||||
// Vous commencez avec 3-1, puis l'ordinateur tirera 6-4.
|
||||
game = Game.start(engine, { dice: fixedDice([3, 1, 6, 4]) });
|
||||
assert.equal(await play("8/5 6/5"), true);
|
||||
assert.equal(await playAndConfirm("8/5 6/5"), true);
|
||||
assert.equal(game.state.turn, "computer");
|
||||
});
|
||||
|
||||
@@ -287,6 +346,52 @@ Then("vous pouvez revoir son coup", async () => {
|
||||
|
||||
// ------------------------------------------------------------------ Videau
|
||||
|
||||
// La confirmation elle-même est une question de l'interface (une fenêtre
|
||||
// « Doubler à 2 ? ») : ces étapes vérifient que rien n'est proposé tant que
|
||||
// vous n'avez pas confirmé, et ce qui suit votre confirmation.
|
||||
|
||||
Given("vous pouvez doubler", async () => {
|
||||
game = Game.start(engine, { setup: { position: START_POSITION, firstTurn: "player" } });
|
||||
assert.equal(game.state.phase, "rolling");
|
||||
});
|
||||
|
||||
When("vous demandez à doubler", async () => {
|
||||
assert.equal(await game.canDouble(), true);
|
||||
});
|
||||
|
||||
When("vous changez d'avis", () => {
|
||||
// Vous refermez la question : la partie n'est pas touchée.
|
||||
});
|
||||
|
||||
Then("rien n'est proposé à l'ordinateur", () => {
|
||||
assert.ok(!game.events.some((e) => e.type === "CubeOffered"));
|
||||
assert.equal(game.state.phase, "rolling");
|
||||
assert.equal(game.state.turn, "player");
|
||||
assert.deepEqual(game.state.cube, { value: 1, owner: null });
|
||||
});
|
||||
|
||||
When("vous confirmez", async () => {
|
||||
await game.double();
|
||||
});
|
||||
|
||||
Then("l'ordinateur prend ou passe, comme le recommande le moteur", async () => {
|
||||
const decision = await engine.cubeDecision(
|
||||
START_POSITION,
|
||||
{ value: 1, owner: "centered" },
|
||||
STANDARD_PLY,
|
||||
);
|
||||
const offered = game.events.findIndex((e) => e.type === "CubeOffered");
|
||||
const answer = game.events[offered + 1];
|
||||
assert.ok(offered >= 0 && answer !== undefined);
|
||||
if (decision.take) {
|
||||
assert.equal(answer.type, "CubeTaken");
|
||||
assert.deepEqual(game.state.cube, { value: 2, owner: "computer" });
|
||||
} else {
|
||||
assert.equal(answer.type, "CubeDropped");
|
||||
assert.deepEqual(game.state.result, { winner: "player", kind: "single", points: 1 });
|
||||
}
|
||||
});
|
||||
|
||||
Given("l'ordinateur vous propose de doubler", async () => {
|
||||
game = Game.start(engine, { setup: { position: COMPUTER_DOUBLES, firstTurn: "computer" } });
|
||||
await game.playComputerTurn();
|
||||
@@ -346,7 +451,7 @@ Given("un joueur a sorti tous ses pions", async () => {
|
||||
dice: fixedDice([6, 5]),
|
||||
});
|
||||
await game.roll();
|
||||
assert.equal(await play("6/off 5/off"), true);
|
||||
assert.equal(await playAndConfirm("6/off 5/off"), true);
|
||||
});
|
||||
|
||||
Then("le résultat indique le gagnant et les points gagnés", () => {
|
||||
|
||||
+13
-1
@@ -12,7 +12,14 @@ import type { BoardSide } from "../src/domain/game/engine.js";
|
||||
import { appendEvent, EMPTY_JOURNAL } from "../src/domain/game/events.js";
|
||||
import { parseHalfMoves, START_POSITION } from "../src/domain/game/position.js";
|
||||
import { createGameStore } from "../src/storage/game-store.js";
|
||||
import { boardModel, moveTargets, moveTrace, placeOf, pointSlot } from "../src/ui/board-model.js";
|
||||
import {
|
||||
boardModel,
|
||||
moveTargets,
|
||||
moveTrace,
|
||||
onlyHalfMove,
|
||||
placeOf,
|
||||
pointSlot,
|
||||
} from "../src/ui/board-model.js";
|
||||
import { parseFeature, parseGlossaryEntry, parseGlossaryIndex } from "../src/ui/help-text.js";
|
||||
import { TEXTS } from "../src/ui/texts.js";
|
||||
|
||||
@@ -65,6 +72,11 @@ test("les demi-coups possibles donnent les pions jouables et leurs cases d'arriv
|
||||
assert.deepEqual([...targets.keys()], ["p8", "bar-player", "p3"]);
|
||||
assert.deepEqual([...(targets.get("p8")?.keys() ?? [])], ["p5", "p7"]);
|
||||
assert.deepEqual(targets.get("p3")?.get("off-player"), { from: 3, to: 0 });
|
||||
// Un seul toucher suffit pour un pion à destination unique.
|
||||
assert.deepEqual(onlyHalfMove(targets, "p3"), { from: 3, to: 0 });
|
||||
assert.deepEqual(onlyHalfMove(targets, "bar-player"), { from: 25, to: 22 });
|
||||
assert.equal(onlyHalfMove(targets, "p8"), null);
|
||||
assert.equal(onlyHalfMove(targets, "p13"), null);
|
||||
});
|
||||
|
||||
test("traces d'un coup simple : une flèche par demi-coup, départs et arrivées", () => {
|
||||
|
||||
Reference in New Issue
Block a user