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

+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