Preserve Emperor gift opportunity before bot phase pass
Verify and publish checkpoint container / container (push) Successful in 10m48s

This commit is contained in:
Quintine committed 2026-11-16 13:32:27 +11:00
1 parent 021a8c3e7f
commit 0c64d320ea
10 files changed
+238 -5

No files matched your search

@@ -0,0 +1,25 @@
'use client';
import type {Action, GameView} from '@/game/engine';
/** This notice remains visible even when the Emperor has no spice to share. */
export function EmperorPhaseOpeningPriority({game, act, busy}: {
game: Pick<GameView, 'emperorPhaseOpeningPriority' | 'players'>;
act: (action:Action) => void;
busy: boolean;
}) {
const priority = game.emperorPhaseOpeningPriority;
if (!priority) return null;
const event = priority.event;
const recipient = game.players.find(player => player.id === priority.recipient)?.name ?? 'their ally';
const canContinue = !busy && priority.canContinue && !!event;
return <section className="notice space-y-3" aria-label="Emperor phase opening opportunity" aria-live="polite">
<h3>Emperor alliance opportunity</h3>
<p>Before the phase begins, the Emperor may share spice with {recipient}.</p>
{priority.canContinue
? <button type="button" className="game-action" disabled={!canContinue}
onClick={() => {if (canContinue && game.emperorPhaseOpeningPriority === priority && priority.canContinue && priority.event === event)
act({type:'emperorPhaseOpeningContinue', event});}}>Continue to phase</button>
: <p>Waiting for the Emperor to continue.</p>}
</section>;
}
+2
View File
@@ -2,6 +2,7 @@
import { SaphoArrivalOrder } from './sapho-arrival-order';
import { SaphoStationPriority } from './sapho-station-priority';
import { EmperorExtortionPriority } from './emperor-extortion-priority';
import { EmperorPhaseOpeningPriority } from './emperor-phase-opening-priority';
import { RicheseBidPromisePanel } from './richese-bid-promise-panel';
import { EarlyRicheseBidPromises } from './early-richese-bid-promises';
import { TravelPromises } from './travel-promises';
@@ -2572,6 +2573,7 @@ export function GameTable({
<span className="eyebrow">Phase opening</span>
<h2>Before {PHASES[g.phase]}</h2>
<EmperorTimingGift game={g} act={act} busy={busy} />
<EmperorPhaseOpeningPriority game={g} act={act} busy={busy} />
<p>
Play Amal now, or pass to begin this phase. Phase effects wait
until everyone has passed.
+9
View File
@@ -17,6 +17,15 @@ open mode gates.
## Current checkpoint and work
**Human Emperor priority at Basic Ix phase openings — 16 November. Prototyped /
Partial.** A final automated pass waits for the human Emperor's optional gift
and Continue, without revealing available spice. The original passes survive
gift or cancellation; Amal resets the opening and its opportunity. Seven
related files pass 38 cases; type checking, lint and production build pass.
The online ordering is provisional; other faction/module combinations and
deployed acceptance remain open.
[Scope](EMPEROR_ALLIANCE_TIMING.md#human-emperor-before-an-automated-ix-opening-pass--16-november-2026).
**Basic Emperor gifts at Nexus Richese cache sales — 16 November. Prototyped /
Partial.** Supported public Nexus games retain the original cache lot and
committed split through gift, cancellation and Continue. The separate audit
+16 -1
View File
@@ -1,5 +1,19 @@
# Emperor alliance gift timing
## Human Emperor before an automated Ix opening pass — 16 November 2026
In the existing supported Basic Ix opening, the final automated player waits
after a human Emperor has passed, giving the Emperor an explicit opportunity to
share spice or Continue. The public wait is independent of available spice or
private commitments. The original opening and prior passes survive an allowed
or canceled gift. Amal can still be played, resets passes and creates a fresh
opportunity; a stale Continue cannot release it. Other player types retain
their original actions. This neutral online ordering is provisional, not a
publisher timing ruling. [Runtime cases](../tests/emperor-phase-opening-bot-priority.test.ts)
and [controls](../tests/emperor-phase-opening-priority-controls.test.tsx)
exercise the existing Basic envelope, with a staged alliance and card custody.
Other faction and optional-module combinations remain open.
## Basic Nexus Richese cache gifts — 16 November 2026
Supported Basic Nexus games now offer the Emperor's gift before an allied
@@ -74,7 +88,8 @@ permits direct allied gifts for any reason and immediate collection. Applying
that power during the Basic opening is a provisional online timing
interpretation. The scope excludes other expansion families, optional modules,
competing continuations and outstanding commitments requiring a combined
planner. Bot seats may finish the opening before a human Emperor can act.
planner. At that checkpoint a bot could finish the opening before a human
Emperor could act; the newer section above covers the final automated pass.
Advanced and other interruption windows remain unfinished. Runtime evidence
covers [classic](../tests/emperor-phase-opening-gift.test.ts) and
[native Ix faction](../tests/emperor-ix-native-opening-gift.test.ts) games;
+7
View File
@@ -1,5 +1,12 @@
# Rule decision index
## Human Emperor before an automated Ix opening pass — 16 November 2026
An automated final pass waits for the human Emperor's optional gift or
Continue in the supported Basic Ix opening. The neutral online ordering is
provisional, not a new publisher ruling.
[Scope](EMPEROR_ALLIANCE_TIMING.md#human-emperor-before-an-automated-ix-opening-pass--16-november-2026).
## Basic Nexus Richese cache gifts — 16 November 2026
The existing provisional prepayment gift applies to supported Nexus cache
+1
View File
@@ -1634,6 +1634,7 @@ function policyActions(g: GameView): Action[] {
(level > 0 || variation(g, 'amal') > 0.4)
)
return [{ type: 'card', card: amal.id }];
if (g.emperorPhaseOpeningPriority?.waiting === me.id) return [];
return [{ type: 'ready' }];
}
const sapho = saphoAction(g);
+41 -3
View File
@@ -2583,6 +2583,9 @@ export type Game = {
territory: string;
} | null;
phaseOpening?: { passed: string[]; initialize: boolean } | null;
/** Distinguishes each new opening and each Amal reset without exposing hands. */
emperorPhaseOpeningGeneration?: number;
emperorPhaseOpeningGiftRelease?: { event: string; emperor: string };
sandtrout?: boolean;
techTokens?: TechState | null;
strongholdCards?: StrongholdState | null;
@@ -30537,7 +30540,7 @@ function emperorPhaseOpeningGiftSignature(g: Game, opening: {passed: string[]; i
opening, owner, recipient, amount]);
}
/** Initial Basic Ix opening support, with no independent competing windows. */
function emperorPhaseOpeningGiftQuote(g: Game, p: Player): {recipient: string; maximum: number} | null {
function emperorPhaseOpeningGiftPublicEligible(g: Game, p: Player): boolean {
if (g.advanced || g.status !== 'playing' || g.expansions.length !== 1 || g.expansions[0] !== 'ix' ||
g.players.some(seat => !['atreides', 'beneGesserit', 'emperor', 'fremen', 'guild', 'harkonnen', 'ixians', 'tleilaxu'].includes(seat.faction)) ||
g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || g.nexusCards ||
@@ -30547,7 +30550,11 @@ function emperorPhaseOpeningGiftQuote(g: Game, p: Player): {recipient: string; m
g.pendingRicheseGift || g.pendingNullentropy || g.pendingShipment || g.pendingGuildTransport ||
g.pendingArrivalOverlap || g.pendingAmbassador || g.pendingEmperorAuctionGift ||
p.faction !== 'emperor' || !p.ally ||
!g.players.some(seat => seat.id === p.ally && seat.ally === p.id) ||
!g.players.some(seat => seat.id === p.ally && seat.ally === p.id)) return false;
return true;
}
function emperorPhaseOpeningGiftQuote(g: Game, p: Player): {recipient: string; maximum: number} | null {
if (!emperorPhaseOpeningGiftPublicEligible(g, p) || !p.ally ||
liveShipmentPromises(g.shipmentPromises ?? [], p.id, g.turn).length ||
hasMovementPromises(g, p.id, true) || hasBribePromises(g, p.id, true) ||
liveRevivalPromises(g.revivalPromises ?? [], p.id, g.turn).some(row => row.answer) ||
@@ -30558,6 +30565,18 @@ function emperorPhaseOpeningGiftQuote(g: Game, p: Player): {recipient: string; m
const maximum = Math.max(0, uncommittedSpice(g, p));
return maximum > 0 ? {recipient: p.ally, maximum} : null;
}
/** A final automated pass must leave the human Emperor a neutral opportunity. */
function emperorPhaseOpeningPriority(g: Game): {event:string; emperor:string; recipient:string; waiting:string} | null {
const emperor = byFaction(g, 'emperor'), opening = g.phaseOpening;
if (!emperor || (emperor.bot ?? emperor.autopilot) || !opening ||
!emperorPhaseOpeningGiftPublicEligible(g, emperor) || !emperor.ally || !opening.passed.includes(emperor.id)) return null;
const remaining = g.players.filter(player => !opening.passed.includes(player.id));
if (remaining.length !== 1 || !(remaining[0].bot ?? remaining[0].autopilot)) return null;
const event = JSON.stringify(['emperorPhaseOpening', g.turn, g.phase,
g.emperorPhaseOpeningGeneration ?? 0, opening.initialize, emperor.id, emperor.ally, remaining[0].id]);
if (g.emperorPhaseOpeningGiftRelease?.event === event && g.emperorPhaseOpeningGiftRelease.emperor === emperor.id) return null;
return {event, emperor:emperor.id, recipient:emperor.ally, waiting:remaining[0].id};
}
function validateEmperorPhaseOpeningGift(g: Game, response: ResponseWindow) {
const parent = response.emperorPhaseOpeningGift;
if (!parent) return;
@@ -31166,7 +31185,10 @@ function openPhase(g: Game, initialize = true) {
if (g.homeworldRevival?.tleilaxu.low)
log(g, 'Tleilax began Revival at low population. Tleilaxu will receive no bank reward for other factions’ Free Revival this phase, even if Tleilax later returns to high population. Paid revival and Ghola income are unchanged.', { faction: 'tleilaxu', name: 'Tleilax low population' });
}
if (g.expansions.includes('ix')) g.phaseOpening = { passed: [], initialize };
if (g.expansions.includes('ix')) {
g.emperorPhaseOpeningGeneration = (g.emperorPhaseOpeningGeneration ?? 0) + 1;
g.phaseOpening = { passed: [], initialize };
}
else if (initialize) beginPhase(g);
}
function revivalOrderContext(g: Game) {
@@ -45127,6 +45149,14 @@ function applyActionInner(
payOrdinaryBribe(g, p, action);
return g;
}
if (t === 'emperorPhaseOpeningContinue') {
const priority = emperorPhaseOpeningPriority(g);
requireRule(priority && priority.emperor === id && action.event === priority.event &&
Object.keys(action).sort().join(',') === 'event,type',
'Continue only your current Emperor phase opening opportunity.');
g.emperorPhaseOpeningGiftRelease = {event:priority.event, emperor:id};
return g;
}
if (t === 'emperorGift' && g.phaseOpening && !g.response) {
const quote = emperorPhaseOpeningGiftQuote(g, p);
requireRule(quote && Object.keys(action).sort().join(',') === 'amount,type',
@@ -45151,6 +45181,8 @@ function applyActionInner(
'You have already passed the phase opening.',
);
if (t === 'ready') {
requireRule(emperorPhaseOpeningPriority(g)?.waiting !== id,
'Wait for the Emperor to finish the allied gift opportunity.');
if (execution === 'live') guardTurnActionOpening(g, id, true);
g.phaseOpening.passed.push(id);
if (g.phaseOpening.passed.length === g.players.length) {
@@ -45178,6 +45210,7 @@ function applyActionInner(
for (const player of g.players)
player.spice = Math.floor(player.spice / 2);
g.phaseOpening.passed = [];
g.emperorPhaseOpeningGeneration = (g.emperorPhaseOpeningGeneration ?? 0) + 1;
if (execution === 'live') guardTurnActionOpening(g, id, false);
log(
g,
@@ -50199,6 +50232,11 @@ export function viewGame(state: Game, id: string, now?: number) {
return priority ? {event:priority.event, recipient:priority.recipient, canContinue:priority.emperor === id} : null;
})(),
emperorPhaseOpeningGift: emperorPhaseOpeningGiftQuote(g, me),
emperorPhaseOpeningPriority: (() => {
const priority = emperorPhaseOpeningPriority(g);
return priority ? {event:priority.event, recipient:priority.recipient, waiting:priority.waiting,
canContinue:priority.emperor === id} : null;
})(),
emperorAuctionGiftPending: g.pendingEmperorAuctionGift
? { owner: g.pendingEmperorAuctionGift.owner } : null,
emperorAuctionGift: g.pendingEmperorAuctionGift?.owner === id && !g.response && !g.pendingKarama
+1 -1
View File
@@ -88,7 +88,7 @@ export const FACTION_RULES: Record<
'Give spice directly to your ally. After the response window it is immediately spendable, unlike a deferred bribe between non-allies.',
'In supported Basic ordinary auctions and Richese cache sales, including Nexus games, you may give your mutual ally spice after they win and before their original payment. Continue preserves the bid and pledged split; a canceled gift transfers nothing.',
'In supported Moritani games, including Basic games with other selected faction decks, you may also give spice while your ally is choosing whether to pay Extortion. The original choice resumes after the gift’s Karama response.',
'In supported Basic Ix-deck games with classic factions, Ixians or Tleilaxu, you may give an ally spice during the Amal phase opening, even after you have passed. The original opening resumes after the gift response.',
'In supported Basic Ix-deck games with classic factions, Ixians or Tleilaxu, you may give an ally spice during the Amal phase opening, even after you have passed. The original opening resumes after the gift response. If a final automated pass would close it, a human Emperor may share or continue first.',
'During Revival, pay two spice per extra allied force, up to three extra forces per turn. These are separate from the ally’s normal three-force allowance and may be purchased before or after ordinary revivals.',
'Spice gifts and extra revival uses have Karama response windows. Canceling a use spends neither the Emperor’s spice nor the extra-revival allowance.',
],
@@ -0,0 +1,101 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {applyAction, viewGame, type Action, type Game} from '../game/engine';
import {botActions, runBots} from '../game/bots';
import {DIFFICULTIES} from '../game/bot-profiles';
import {createTruthTurnAmalFixture} from './fixture-truth-turn-amal';
const act=(g:Game,id:string,action:Action)=>applyAction(g,id,action);
const player=(g:Game,id:string)=>{const p=g.players.find(row=>row.id===id);assert.ok(p);return p;};
function fixture(autopilot=false, spice=10) {
let game=createTruthTurnAmalFixture().game;
player(game,'emperor').ally='atreides';player(game,'atreides').ally='emperor';
player(game,'emperor').spice=spice;
const h=player(game,'harkonnen');
for(const card of h.hand.filter(row=>row.effect==='amal')) game.deck.push(card);
h.hand=h.hand.filter(row=>row.effect!=='amal');
game=act(game,'emperor',{type:'ready'});game=act(game,'atreides',{type:'ready'});
if(autopilot)player(game,'harkonnen').autopilot='Easy';else player(game,'harkonnen').bot='Easy';
return game;
}
function allow(game:Game) {
for(let n=0;game.response&&n<20;n++) {
const responder=game.players.find(p=>!game.response!.passed.includes(p.id));assert.ok(responder);
game=act(game,responder.id,{type:'passResponse'});
}
return game;
}
for(const autopilot of [false,true]) void test(`Basic human Emperor precedes final ${autopilot?'autopilot':'bot'} opening pass`,()=>{
let game=fixture(autopilot);
const original=structuredClone(game.phaseOpening);
const priority=viewGame(game,'emperor').emperorPhaseOpeningPriority;assert.ok(priority?.canContinue);
assert.deepEqual(viewGame(game,'harkonnen').emperorPhaseOpeningPriority,{...priority,canContinue:false});
for(const level of DIFFICULTIES) {
const view=viewGame(game,'harkonnen'),p=view.players.find(row=>row.id==='harkonnen')!;
if(autopilot)p.autopilot=level;else p.bot=level;
assert.ok(!botActions(view).some(action=>action.type==='ready'));
}
const before=structuredClone(game);
assert.throws(()=>act(game,'harkonnen',{type:'ready'}));
assert.throws(()=>act(game,'atreides',{type:'emperorPhaseOpeningContinue',event:priority.event}));
assert.throws(()=>act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:'stale'}));
assert.deepEqual(game,before);
game=runBots(game,5);assert.deepEqual(game.phaseOpening,original);
game=act(game,'emperor',{type:'emperorGift',amount:2});game=allow(game);
assert.deepEqual(game.phaseOpening,original);
assert.equal(player(game,'atreides').spice,player(before,'atreides').spice+2);
const waiting=viewGame(game,'emperor').emperorPhaseOpeningPriority;assert.ok(waiting?.canContinue);
game=act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:waiting.event});
assert.equal(viewGame(game,'emperor').emperorPhaseOpeningPriority,null);
assert.ok(botActions(viewGame(game,'harkonnen')).some(action=>action.type==='ready'));
game=runBots(game,1);assert.equal(game.phaseOpening,null);
});
void test('a zero-spice Emperor retains the same public opening opportunity',()=>{
const game=fixture(false,0),priority=viewGame(game,'atreides').emperorPhaseOpeningPriority;
assert.ok(priority);assert.equal(priority.canContinue,false);
assert.equal(viewGame(game,'emperor').emperorPhaseOpeningGift,null);
const done=act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:priority.event});
assert.equal(viewGame(done,'emperor').emperorPhaseOpeningPriority,null);
});
void test('a canceled gift returns to the same automated opening opportunity',()=>{
let game=fixture();
const h=player(game,'harkonnen');let card=h.hand.find(row=>row.effect==='karama');
if(!card) {
const source=[game.deck,...game.players.filter(p=>p.id!=='harkonnen').map(p=>p.hand)].find(zone=>zone.some(row=>row.effect==='karama'));assert.ok(source);
[card]=source.splice(source.findIndex(row=>row.effect==='karama'),1);h.hand.push(card);
}
const opening=structuredClone(game.phaseOpening),wallet=player(game,'emperor').spice;
game=act(game,'emperor',{type:'emperorGift',amount:1});
game=act(game,'harkonnen',{type:'card',mode:'cancel',card:card.id});
assert.deepEqual(game.phaseOpening,opening);assert.equal(player(game,'emperor').spice,wallet);
assert.ok(viewGame(game,'emperor').emperorPhaseOpeningPriority?.canContinue);
assert.deepEqual(runBots(game,4).phaseOpening,opening);
});
void test('playing Amal after Continue creates a fresh opening and invalidates the old release',()=>{
let game=fixture();const h=player(game,'harkonnen');
const source=[game.deck,...game.players.filter(p=>p.id!=='harkonnen').map(p=>p.hand)].find(zone=>zone.some(row=>row.effect==='amal'));assert.ok(source);
const [amal]=source.splice(source.findIndex(row=>row.effect==='amal'),1);h.hand.push(amal);
const old=viewGame(game,'emperor').emperorPhaseOpeningPriority!;
game=act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:old.event});
game=act(game,'harkonnen',{type:'card',card:amal.id});
assert.deepEqual(game.phaseOpening?.passed,[]);
game=act(game,'emperor',{type:'ready'});game=act(game,'atreides',{type:'ready'});
const fresh=viewGame(game,'emperor').emperorPhaseOpeningPriority;assert.ok(fresh);
assert.notEqual(fresh.event,old.event);
assert.throws(()=>act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:old.event}));
game=act(game,'emperor',{type:'emperorPhaseOpeningContinue',event:fresh.event});
game=act(game,'harkonnen',{type:'ready'});assert.equal(game.phaseOpening,null);
});
void test('unallied games and a bot Emperor do not create a human gift wait',()=>{
for(const variant of ['unallied','automated-emperor'] as const) {
const game=fixture();
if(variant==='unallied') {player(game,'emperor').ally=null;player(game,'atreides').ally=null;}
else player(game,'emperor').bot='Easy';
assert.equal(viewGame(game,'harkonnen').emperorPhaseOpeningPriority,null);
assert.ok(botActions(viewGame(game,'harkonnen')).some(action=>action.type==='ready'));
assert.equal(act(game,'harkonnen',{type:'ready'}).phaseOpening,null);
}
});
@@ -0,0 +1,35 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {Children, createElement, isValidElement} from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import {EmperorPhaseOpeningPriority} from '../components/emperor-phase-opening-priority';
import type {Action, GameView} from '../game/engine';
function input() {
const sent:Action[]=[];
const game={emperorPhaseOpeningPriority:{event:'opening',recipient:'ally',waiting:'bot',canContinue:true},
players:[{id:'ally',name:'Ally'}]} as unknown as Pick<GameView,'emperorPhaseOpeningPriority'|'players'>;
return {game,busy:false,sent,act:(action:Action)=>sent.push(action)};
}
function button(props:ReturnType<typeof input>) {
const panel=EmperorPhaseOpeningPriority(props);assert.ok(panel);
const control=Children.toArray(panel.props.children).find(row=>isValidElement(row)&&row.type==='button');
assert.ok(isValidElement<{onClick:()=>void;disabled:boolean}>(control));return control;
}
void test('the Emperor can continue the persistent opening notice',()=>{
const props=input(),html=renderToStaticMarkup(createElement(EmperorPhaseOpeningPriority,props));
assert.match(html,/share spice with Ally/);assert.match(html,/Continue to phase/);
button(props).props.onClick();assert.deepEqual(props.sent,[{type:'emperorPhaseOpeningContinue',event:'opening'}]);
});
void test('other viewers see the wait, and stale or busy controls do not submit',()=>{
const other=input();other.game.emperorPhaseOpeningPriority!.canContinue=false;
assert.match(renderToStaticMarkup(createElement(EmperorPhaseOpeningPriority,other)),/Waiting for the Emperor/);
for(const variant of ['busy','event','permission','replace','close'] as const) {
const props=input();if(variant==='busy')props.busy=true;const control=button(props);
if(variant==='event')props.game.emperorPhaseOpeningPriority!.event='other';
if(variant==='permission')props.game.emperorPhaseOpeningPriority!.canContinue=false;
if(variant==='replace')props.game.emperorPhaseOpeningPriority={...props.game.emperorPhaseOpeningPriority!};
if(variant==='close')props.game.emperorPhaseOpeningPriority=null;
control.props.onClick();assert.deepEqual(props.sent,[],variant);
}
});