fix(reference): Death Events remember a right-hand neighbour, not a board index

A Deathrattle summon used the dying minion's board index from before the
Death Creation Step removed anything. That index is stale when a minion to
its left dies in the same step, so the token landed one place too far right.

Each Death Event now records `before`: the nearest minion to the right that
is not dying in the same step. The position handed to the effect context is
resolved when the trigger resolves: the current index of `before`, or the
right end. Applied to the Rust and TS references of Modules 3-10.

Module 3 gains two tests, documented in scenarios.md:
test_03_summon_position_after_simultaneous_deaths (fails before the fix) and
test_03_simultaneous_summons_keep_board_order.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Fable 5.2 committed 2026-11-11 09:15:48 +01:00
1 parent 638549161f
commit 429137a6ef
79 files changed
+808 -236

No files matched your search

@@ -45,8 +45,8 @@ export class Ctx {
/** The chosen target, if any. */
readonly target?: EntityId,
/**
* The source's board position. For a Deathrattle, the source has left play,
* and this is the position its Death Event remembered.
* The source's board position. For a Deathrattle, the source has left play, and
* this is where it stood: immediately left of the minion its Death Event remembers.
*/
readonly position?: number,
) {}
@@ -161,7 +161,10 @@ function react(world: World, events: Event[]): void {
const times = activations(world, world.ownerOf(source), trigger.on);
for (let i = 0; i < times; i++) {
world.record({ type: "Triggered", source, on: trigger.on });
const position = event.type === "Destroyed" && event.id === source ? event.position : world.boardIndex(source);
const position =
event.type === "Destroyed" && event.id === source
? positionLeftOf(world, world.ownerOf(source), event.before)
: world.boardIndex(source);
const actions = trigger.effect(new Ctx(world, world.ownerOf(source), source, undefined, position));
// Depth-first: each action, and every reaction it causes, finishes before the next.
for (const action of actions) perform(world, action);
@@ -169,6 +172,17 @@ function react(world: World, events: Event[]): void {
}
}
/**
* The board index, right now, immediately left of `before` on `owner`'s board; the
* right end if `before` is undefined or no longer there. A Death Event remembers the
* minion, not an index, so this still holds after other minions have left or arrived.
*/
function positionLeftOf(world: World, owner: PlayerId, before: EntityId | undefined): number {
const board = world.zone(owner, "board");
const index = before === undefined ? -1 : board.indexOf(before);
return index < 0 ? board.length : index;
}
/**
* Who may respond to `event`, in order of play: every minion in play and, for a
* Death Event, the minion that died. It has left play, but its Deathrattle still answers.