The boobytrap keeps its secret
The public boobytrapPlaced event and every subsequent view shipped the four token cells in casting order — with the real trap always first, a tell readable by any client. Tokens are now stored and broadcast in canonical cell order while the truth lives only in realKey (and the caster's private event). Deterministic sort, no rng touched, replays unaffected; a test casts in reverse order and checks that position whispers nothing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015RCWSTnb1KYTPyL4GmhGnF
This commit is contained in:
co-authored by
Claude Fable 5
parent
8ba0a934cc
commit
eaa672236b
@@ -424,3 +424,34 @@ describe("boobytrap decoys die their own deaths", () => {
|
||||
throw new Error("setup: no approach to the blank token");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the boobytrap keeps its secret", () => {
|
||||
it("stored and broadcast cells are canonically ordered — position tells nothing", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const view = boardView(state);
|
||||
const open: Cell[] = [];
|
||||
for (const key of Object.keys(view.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
if (state.squareContents[key]) continue;
|
||||
open.push({ x, y });
|
||||
if (open.length === 4) break;
|
||||
}
|
||||
// Cast with the REAL trap deliberately last-sorting: reverse order.
|
||||
const reversed = [...open].reverse();
|
||||
const bt = giveCard(state, me.id, "boobytrap");
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: bt.instanceId, params: { cells: reversed },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const trap = r.state.boobytraps[0]!;
|
||||
const keys = trap.cells.map((c) => cellKey(c));
|
||||
expect([...keys].sort()).toEqual(keys); // canonical order, not casting order
|
||||
expect(trap.realKey).toBe(cellKey(reversed[0]!)); // the truth survives aside
|
||||
const placed = r.events.find((e) => e.type === "boobytrapPlaced");
|
||||
if (placed?.type === "boobytrapPlaced") {
|
||||
const evKeys = placed.cells.map((c) => cellKey(c));
|
||||
expect([...evKeys].sort()).toEqual(evKeys);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user