----------------------------- MODULE AbilityContracts ----------------------------- EXTENDS OperationContracts AbilityKinds9 == {"Static","Paid","Conditional","Play","BarrierInstruction"} AbilityShape9(kind,instructions) == kind \in AbilityKinds9 /\ IF kind = "Static" THEN Len(instructions) = 0 ELSE Len(instructions) > 0 AbilityTextPartition9(tokenCount,units) == /\ tokenCount \in Nat /\ UNION {units[id].tokens : id \in DOMAIN units} = 1..tokenCount /\ \A a,b \in DOMAIN units : a # b => units[a].tokens \cap units[b].tokens = {} /\ \A id \in DOMAIN units : AbilityShape9(units[id].kind,units[id].instructions) AbilityIsInterrupt9(actualInterruptFlag,actualInstructionContainsWould) == actualInterruptFlag \/ actualInstructionContainsWould ObjectAbilitySource9(object) == [kind |-> "Object",object |-> object,rule |-> "NoValue"] RuleAbilitySource9(rule) == [kind |-> "Rule",object |-> 0,rule |-> rule] AbilitySource9(origin,printedObject,recipient,effectCreator,rule) == CASE origin = "Printed" -> ObjectAbilitySource9(printedObject) [] origin = "Granted" -> ObjectAbilitySource9(recipient) [] origin = "Lingering" -> ObjectAbilitySource9(effectCreator) [] origin = "Rule" -> RuleAbilitySource9(rule) OpenAbilityResolution9(id,kind,source,sourceZone,instructions,caller) == [id |-> id,kind |-> kind,source |-> source,sourceZone |-> sourceZone,instructions |-> instructions, caller |-> caller,cursor |-> 1,phase |-> "Ready",firstImminent |-> FALSE,lastFinished |-> FALSE, detached |-> FALSE,complete |-> FALSE,returned |-> FALSE] DetachPaidAbility9(before,after,actualTriggerCostReceipt) == /\ before.kind = "Paid" /\ before.phase = "Ready" /\ ~before.detached /\ actualTriggerCostReceipt.abilityInstance = before.id /\ actualTriggerCostReceipt.allPaid /\ after = [before EXCEPT !.detached = TRUE] BeginAbilityInstructions9(before,after,actualSchedulerAllows,actualSourceEligible) == /\ before.phase = "Ready" /\ ~before.firstImminent /\ ~before.complete /\ before.id \in Nat \ {0} /\ before.kind \in AbilityKinds9 \ {"Static"} /\ Len(before.instructions) > 0 /\ actualSchedulerAllows /\ IF before.kind = "Paid" THEN before.detached ELSE actualSourceEligible /\ after = [before EXCEPT !.phase = "Imminent",!.firstImminent = TRUE, !.detached = @ \/ before.kind \in {"Conditional","BarrierInstruction"}] AbilityIsResolving9(f) == f.firstImminent /\ ~f.lastFinished PlayedSourceIsResolving9(playFrame) == playFrame.stage = "ProcedureCode3d7f756d78f7" /\ ~playFrame.complete ResolveCurrentInstruction9(before,after,actualInterruptWindowComplete) == /\ before.phase = "Imminent" /\ ~before.complete /\ actualInterruptWindowComplete /\ after = [before EXCEPT !.phase = "Resolving"] FinishAbilityInstruction9(before,after,actualInstructionReceipt) == /\ before.phase = "Resolving" /\ ~before.complete /\ actualInstructionReceipt.abilityInstance = before.id /\ actualInstructionReceipt.instruction = before.instructions[before.cursor] /\ actualInstructionReceipt.complete /\ after = IF before.cursor = Len(before.instructions) THEN [before EXCEPT !.phase = "Complete",!.lastFinished = TRUE,!.complete = TRUE] ELSE [before EXCEPT !.phase = "Between"] ContinueAbilityInstructions9(before,after,actualCheckpointAndAllNewerChainsComplete) == /\ before.phase = "Between" /\ ~before.complete /\ before.cursor < Len(before.instructions) /\ actualCheckpointAndAllNewerChainsComplete /\ after = [before EXCEPT !.cursor = @+1,!.phase = "Imminent"] ReturnAbility9(before,after,actualFinalCheckpointAndChainsComplete,caller) == /\ before.complete /\ ~before.returned /\ actualFinalCheckpointAndChainsComplete /\ caller = before.caller /\ after = [before EXCEPT !.returned = TRUE] PushChainGroup9(before,after,id,conditionSerial,abilities,usedGroupIds) == /\ id \in (Nat \ {0}) \ usedGroupIds /\ abilities # {} /\ IF Len(before) = 0 THEN conditionSerial \in Nat \ {0} ELSE conditionSerial > before[Len(before)].serial /\ after = Append(before,[id |-> id,serial |-> conditionSerial,pending |-> abilities]) NextChainMembers9(stack) == IF Len(stack)=0 THEN {} ELSE stack[Len(stack)].pending FinishChainMember9(before,after,ability,actualChildReturnReceipt) == /\ Len(before)>0 /\ ability \in NextChainMembers9(before) /\ actualChildReturnReceipt.abilityInstance = ability /\ actualChildReturnReceipt.returned /\ LET top == before[Len(before)] IN after = IF top.pending = {ability} THEN SubSeq(before,1,Len(before)-1) ELSE [before EXCEPT ![Len(before)].pending = @ \ {ability}] DetachedSourceTarget9(frame,objects,target) == /\ frame.detached /\ frame.source.kind = "Object" /\ target = frame.source.object /\ target \in DOMAIN objects /\ objects[target].zone = frame.sourceZone MaintainLingering9(before,after,actualExpiredEffectIds) == /\ actualExpiredEffectIds \subseteq DOMAIN before /\ after = [id \in DOMAIN before \ actualExpiredEffectIds |-> before[id]] AbilityUseDue9(kind,entirelyMandatory,actualTriggerCostPaid,actualOptionalEffectsResolved,actualOtherOptionalChoiceComplete) == CASE kind = "Paid" -> actualTriggerCostPaid [] kind = "Conditional" -> ~entirelyMandatory /\ actualOptionalEffectsResolved [] OTHER -> ~entirelyMandatory /\ actualOtherOptionalChoiceComplete RecordAbilityUse9(before,after,useId,abilityInstance,source,player,actualUseDue,events) == /\ useId \in (Nat \ {0}) \ DOMAIN before /\ player \in SetupPlayers /\ actualUseDue /\ LET entry == [tag |-> "AbilityUsed",useId |-> useId,abilityInstance |-> abilityInstance,source |-> source,player |-> player] IN /\ after = [id \in DOMAIN before \cup {useId} |-> IF id = useId THEN entry ELSE before[id]] /\ events = {entry} CounterPermissionUseSources9(actualPayment,permissionWitnesses) == IF ~actualPayment.complete THEN {} ELSE {permissionWitnesses[id].source : id \in {i \in DOMAIN permissionWitnesses : permissionWitnesses[i].paymentId = actualPayment.id /\ permissionWitnesses[i].allowsPayment /\ permissionWitnesses[i].paidCounters # {} /\ permissionWitnesses[i].paidCounters \subseteq actualPayment.paidCounterIds}} AbilitySourceItemInspectionMatches9(ability,event) == /\ ability.kind = "Conditional" /\ ability.sourceItemInspection /\ ability.source.kind = "Object" /\ event.tag = "ItemInspectionCard" /\ event.object = ability.source.object AbilityDefinition9(id,kind,source,provider) == [id |-> id,kind |-> kind,source |-> source,provider |-> provider,sourceItemInspection |-> FALSE, statedZones |-> {},rulesOnlyZones |-> {},ownPermissionModifier |-> FALSE,ownCostModifier |-> FALSE, ownProgressRequirement |-> FALSE,ownClaimObjectiveAdditionalCost |-> FALSE,allowsProgress |-> FALSE] ActivityContext9 == [inspectedItemObject |-> 0,encounteredObject |-> 0,encounterLive |-> FALSE, departureHolds |-> [id \in {} |-> id],instances |-> [id \in {} |-> id], persistentAbilities |-> {},lingeringAbilities |-> {},activeRules |-> {}] OpenDepartureHold9(beforeObjects,afterObjects,oldObject,newObject,abilityId,matchingInstances,actualDepartureReceipt, actualCardWasActive,actualCardIsActiveAfter,hold) == /\ oldObject \in DOMAIN beforeObjects /\ newObject \in DOMAIN afterObjects /\ beforeObjects[oldObject].form = "Card" /\ afterObjects[newObject].form = "Card" /\ beforeObjects[oldObject].card = afterObjects[newObject].card /\ beforeObjects[oldObject].zone # afterObjects[newObject].zone /\ oldObject # newObject /\ actualCardWasActive /\ ~actualCardIsActiveAfter /\ matchingInstances # {} /\ actualDepartureReceipt.oldObject = oldObject /\ actualDepartureReceipt.newObject = newObject /\ actualDepartureReceipt.ability = abilityId /\ actualDepartureReceipt.matchingInstances = matchingInstances /\ hold = [ability |-> abilityId,object |-> newObject,instances |-> matchingInstances] DepartureHoldLive9(hold,ability,objects,instances) == /\ hold.ability = ability.id /\ ability.kind = "Conditional" /\ ability.source.kind = "Object" /\ hold.object = ability.source.object /\ hold.object \in DOMAIN objects /\ \E id \in hold.instances \cap DOMAIN instances : instances[id].ability = ability.id /\ instances[id].sourceObject = hold.object /\ instances[id].status \in {"Pending","Triggered","Imminent","Resolving"} AbilityActive9(ability,objects,effectivePresentIds,actualDefaultCardActive,context) == IF ability.id \notin effectivePresentIds THEN FALSE ELSE IF ability.provider = "Lingering" THEN ability.id \in context.lingeringAbilities ELSE IF ability.source.kind = "Rule" THEN ability.source.rule \in context.activeRules ELSE IF ability.source.object \notin DOMAIN objects THEN FALSE ELSE LET o == objects[ability.source.object] IN IF o.form = "Counter" THEN TRUE ELSE IF SideBFacedown8(o) THEN FALSE ELSE actualDefaultCardActive \/ (ability.kind="Conditional" /\ ability.sourceItemInspection) \/ o.zone \in ability.statedZones \cup ability.rulesOnlyZones \/ ability.ownPermissionModifier \/ ability.ownCostModifier \/ ability.ownProgressRequirement \/ ability.ownClaimObjectiveAdditionalCost \/ (ability.allowsProgress /\ ActivationStatus8(o)="Dormant") \/ (IF ability.id \in DOMAIN context.departureHolds THEN DepartureHoldLive9(context.departureHolds[ability.id],ability,objects,context.instances) ELSE FALSE) \/ (ability.kind="BarrierInstruction" /\ ~o.deployed /\ context.encounterLive /\ context.encounteredObject=ability.source.object) \/ ability.id \in context.persistentAbilities EffectiveBarrierInstructions9(presentIds,definitions) == {id \in presentIds \cap DOMAIN definitions : definitions[id].kind = "BarrierInstruction"} EffectiveAbilityOrder9(presentIds,definitions,printedPlayOrder,actualBarrierInstructionOrder) == /\ SubIds6(printedPlayOrder) = {id \in presentIds \cap DOMAIN definitions : definitions[id].kind="Play"} /\ Len(printedPlayOrder) = Cardinality(SubIds6(printedPlayOrder)) /\ SubIds6(actualBarrierInstructionOrder) = EffectiveBarrierInstructions9(presentIds,definitions) /\ Len(actualBarrierInstructionOrder) = Cardinality(SubIds6(actualBarrierInstructionOrder)) EffectiveAbilityChange9(beforePresent,afterPresent,definitions,immutablePrintedPlayOrder,beforePlayOrder,afterPlayOrder) == /\ beforePlayOrder = immutablePrintedPlayOrder /\ afterPlayOrder = immutablePrintedPlayOrder /\ SubIds6(immutablePrintedPlayOrder) = {id \in beforePresent \cap DOMAIN definitions : definitions[id].kind="Play"} /\ SubIds6(immutablePrintedPlayOrder) = {id \in afterPresent \cap DOMAIN definitions : definitions[id].kind="Play"} TimingStructureKinds9 == {"Turn","TurnPhase","SchemaAtom138","TraversalPhase","Inspection","ItemInspection"} TimingRef9(kind,id) == [kind |-> kind,id |-> id] NoTimingRef9 == TimingRef9("NoValue",0) TimingRefValid9(ref) == ref.kind \in TimingStructureKinds9 /\ ref.id \in Nat \ {0} PriorityWindowKinds9 == {"NeutralValue00001","Paid","Reaction","Interrupt","MidItemInspection"} ActivePlayer9(turn) == TurnActivePlayer5(turn) InactivePlayer9(turn) == TurnOtherPlayer5(ActivePlayer9(turn)) PrioritySite9(route,step,phase,ref,active,turnId,traversalId,itemInspectionId,actionPoints,approachedBarrier,traversalEnding,live,timingLive) == [route |-> route,step |-> step,phase |-> phase,structure |-> ref,active |-> active, turnId |-> turnId,traversalId |-> traversalId,itemInspectionId |-> itemInspectionId,actionPoints |-> actionPoints, approachedBarrier |-> approachedBarrier,traversalEnding |-> traversalEnding,live |-> live,timingLive |-> timingLive] TurnPrioritySite9(turn,step,phaseId,actionPoints,actualProcedure) == LET info == IF turn.owner = "SideA" THEN SideAStepInfo5(step) ELSE SideBStepInfo5(step) steps == IF turn.owner = "SideA" THEN SetupRange(SideASteps5) ELSE SetupRange(SideBSteps5) IN PrioritySite9("Turn",step,turn.phase,TimingRef9("TurnPhase",phaseId),ActivePlayer9(turn),turn.id,0,0,actionPoints,0,FALSE, TurnFrameValid5(turn) /\ step \in steps /\ info.phase = turn.phase /\ actualProcedure.turn=turn /\ actualProcedure.step=step, ~turn.formalEnded) TraversalPrioritySite9(turn,r,approach,layout,actualProcedure) == PrioritySite9("SchemaAtom138",r.step,r.phase,TimingRef9("TraversalPhase",r.phaseId),ActivePlayer9(turn),turn.id,r.id,0,0, IF r.phase = "Approach" /\ approach.id = r.phaseId /\ approach.traversalId = r.id /\ approach.begun THEN ApproachedBarrier6(approach,layout) ELSE 0,FALSE, TurnFrameValid5(turn) /\ TraversalFrameValid6(r) /\ r.id \in Nat \ {0} /\ TraversalStepInfo6(r.step).phase = r.phase /\ actualProcedure.traversal=r /\ ~actualProcedure.returned,TraversalTimingPresent6(r) /\ ~r.ending) ItemInspectionPrioritySite9(turn,a,objects) == PrioritySite9("ItemInspection",a.step,"ItemInspection",TimingRef9("ItemInspection",a.id),ActivePlayer9(turn),turn.id,a.traversalId,a.id,0,0,FALSE, TurnFrameValid5(turn) /\ a.id \in Nat \ {0} /\ ~a.returned /\ (StillItemInspectioning7(a,objects) \/ (a.complete /\ a.beginMet)),StillItemInspectioning7(a,objects)) InspectionPrioritySite9(turn,b) == PrioritySite9("Inspection",b.step,"Inspection",TimingRef9("Inspection",b.id),ActivePlayer9(turn),turn.id,b.traversalId,0,0,0,FALSE, TurnFrameValid5(turn) /\ b.id \in Nat \ {0} /\ ~b.returned /\ (b.active \/ (b.complete /\ b.beginMet)),b.active /\ ~b.complete) BeginningRefAtSite9(ref,site) == ref = NoTimingRef9 \/ ref = site.structure \/ ref = TimingRef9("Turn",site.turnId) \/ (site.traversalId # 0 /\ ref = TimingRef9("SchemaAtom138",site.traversalId)) PaidWindowOptions9(site) == CASE site.route = "Turn" -> LET info == IF site.active = "SideA" THEN SideAStepInfo5(site.step) ELSE SideBStepInfo5(site.step) IN [paid |-> info.kind = "PaidWindow",nonBarrierActivation |-> "Activation" \in info.options, approachedBarrierActivation |-> FALSE,score |-> "ObjectiveCompletion" \in info.options] [] site.route = "SchemaAtom138" -> TraversalWindowOptions6(site.step) [] OTHER -> [paid |-> FALSE,nonBarrierActivation |-> FALSE,approachedBarrierActivation |-> FALSE,score |-> FALSE] WindowSiteAllowed9(kind,site) == /\ kind \in PriorityWindowKinds9 /\ site.live /\ TimingRefValid9(site.structure) /\ site.active \in SetupPlayers /\ site.turnId \in Nat \ {0} /\ CASE kind = "NeutralValue00001" -> /\ site.route = "Turn" /\ site.phase = "NeutralValue00001" /\ site.actionPoints \in Nat \ {0} /\ site.step = IF site.active = "SideA" THEN "ProcedureCode0e20572a4bab" ELSE "ProcedureCode989abc27e0c6" [] kind = "Paid" -> PaidWindowOptions9(site).paid /\ ~site.traversalEnding [] kind = "MidItemInspection" -> site.route = "ItemInspection" /\ site.step = "ProcedureCode1dd0e8f05be2" /\ ~site.traversalEnding [] OTHER -> TRUE /\ kind \in {"Reaction","Interrupt"} \/ site.timingLive ConditionalInstance9(id,ability,source,controller,mandatory,group,windowId,interrupt) == [id |-> id,ability |-> ability,source |-> source,controller |-> controller, mandatory |-> mandatory,group |-> group,windowId |-> windowId,interrupt |-> interrupt] ConditionalGroupValid9(instances,windowId,group,interrupt) == /\ group \in Nat \ {0} /\ \A id \in DOMAIN instances : /\ id \in Nat \ {0} /\ instances[id].id = id /\ instances[id].ability \in Nat \ {0} /\ instances[id].controller \in SetupPlayers /\ instances[id].mandatory \in BOOLEAN /\ instances[id].windowId = windowId /\ instances[id].group = group /\ instances[id].interrupt = interrupt /\ instances[id].source.kind \in {"Object","Rule"} /\ IF instances[id].source.kind="Object" THEN instances[id].source.object \in Nat \ {0} ELSE instances[id].source.rule # "NoValue" NoPriorityOption9 == [id |-> 0,kind |-> "NoValue",controller |-> "NoValue",ability |-> 0,instance |-> 0, source |-> RuleAbilitySource9("NoValue"),target |-> 0,newStructures |-> {}] PriorityOption9(id,kind,controller,ability,instance,source,target,newStructures) == [id |-> id,kind |-> kind,controller |-> controller,ability |-> ability,instance |-> instance, source |-> source,target |-> target,newStructures |-> newStructures] NewPriorityWindow9(id,kind,site,instances,group,beginning,instruction,effectRevision) == [id |-> id,kind |-> kind,site |-> site,open |-> TRUE,stage |-> "NeedCheckpoint", active |-> site.active,priority |-> IF kind = "MidItemInspection" THEN "SideB" ELSE site.active, reception |-> 1,checkpoint |-> 0,previousPass |-> FALSE,busy |-> NoPriorityOption9,busyTransaction |-> 0, members |-> instances,group |-> group,pending |-> DOMAIN instances,lostPending |-> {},triggered |-> {}, beginning |-> beginning,instruction |-> instruction,effectRevision |-> effectRevision] WindowTop9(stack) == stack[Len(stack)] ReplaceWindowTop9(stack,frame) == [stack EXCEPT ![Len(stack)] = frame] ActionablePriority9(stack) == IF Len(stack) = 0 THEN {} ELSE LET w == WindowTop9(stack) IN IF w.open /\ w.stage = "Ready" /\ w.checkpoint # 0 /\ w.busy.id = 0 /\ w.priority \in SetupPlayers THEN {w.priority} ELSE {} ReceivePriority9(w,player) == [w EXCEPT !.priority = player,!.reception = @+1,!.checkpoint = 0,!.stage = "NeedCheckpoint"] ClosePriorityWindow9(w) == [w EXCEPT !.open = FALSE,!.stage = "Closed",!.priority = "NoValue", !.pending = {},!.lostPending = @ \cup w.pending] PriorityOpeningSite9(stack,site) == [site EXCEPT !.traversalEnding = @ \/ (IF Len(stack)=0 THEN FALSE ELSE WindowTop9(stack).site.traversalEnding)] OpenPriorityWindow9(before,after,id,kind,site,instances,opening,usedWindowIds) == /\ id \in (Nat \ {0}) \ usedWindowIds /\ id \notin {before[i].id : i \in 1..Len(before)} /\ WindowSiteAllowed9(kind,PriorityOpeningSite9(before,site)) /\ opening.tag = "PriorityWindowOpening" /\ opening.windowId = id /\ opening.kind = kind /\ opening.site = site /\ opening.members = DOMAIN instances /\ opening.instances = instances /\ IF kind = "Reaction" THEN /\ DOMAIN instances # {} /\ ConditionalGroupValid9(instances,id,opening.group,FALSE) /\ opening.preparation = <<"ConditionsMet","PendingGroup">> /\ BeginningRefAtSite9(opening.beginning,site) ELSE IF kind = "Interrupt" THEN /\ ConditionalGroupValid9(instances,id,opening.group,TRUE) /\ opening.instruction.id \in Nat \ {0} /\ opening.instruction.abilityInstance \in Nat \ {0} /\ opening.instruction.index \in Nat \ {0} /\ opening.effectRevision \in Nat \ {0} /\ opening.preparation = <<"ExpectedEffects","ReplacementEffects","ConditionalPending">> /\ opening.modifiersExist /\ opening.beginning = NoTimingRef9 ELSE /\ instances = [x \in {} |-> x] /\ opening.group = 0 /\ opening.beginning = NoTimingRef9 /\ after = Append(before,NewPriorityWindow9(id,kind,PriorityOpeningSite9(before,site),instances,opening.group, opening.beginning,opening.instruction,opening.effectRevision)) CheckpointPriority9(before,after,actualCheckpoint) == /\ Len(before) > 0 /\ LET w == WindowTop9(before) IN /\ w.open /\ w.stage = "NeedCheckpoint" /\ w.priority \in SetupPlayers /\ w.busy.id = 0 /\ actualCheckpoint.tag = "NormalPriorityCheckpoint" /\ actualCheckpoint.id \in Nat \ {0} /\ actualCheckpoint.windowId = w.id /\ actualCheckpoint.reception = w.reception /\ actualCheckpoint.player = w.priority /\ actualCheckpoint.complete /\ actualCheckpoint.reactionsDrained /\ after = ReplaceWindowTop9(before,[w EXCEPT !.stage = "Ready",!.checkpoint = actualCheckpoint.id]) PendingOwned9(w,player,mandatoryOnly) == {id \in w.pending : w.members[id].controller = player /\ (~mandatoryOnly \/ w.members[id].mandatory)} ConditionalOptionMatches9(w,option) == /\ option.instance \in w.pending /\ LET i == w.members[option.instance] IN option.ability = i.ability /\ option.source = i.source /\ option.controller = i.controller InterruptEffectMatches9(w,actualCurrentEffect) == /\ actualCurrentEffect.tag = "CurrentImminentEffect" /\ actualCurrentEffect.windowId = w.id /\ actualCurrentEffect.instruction = w.instruction /\ actualCurrentEffect.revision \in Nat \ {0} /\ actualCurrentEffect.revision >= w.effectRevision /\ actualCurrentEffect.relevantConditional \subseteq DOMAIN w.members /\ actualCurrentEffect.paidInterruptAbilities \subseteq Nat \ {0} PaidActivationContext9(w) == [route |-> "Paid",open |-> w.open /\ w.stage = "Ready",kind |-> w.kind,priority |-> w.priority, step |-> w.site.step,approachedBarrier |-> w.site.approachedBarrier,nonBarrierActivationAllowed |-> PaidWindowOptions9(w.site).nonBarrierActivation] PriorityOptionAllowed9(w,option,objects,actualCurrentEffect) == CASE w.kind = "NeutralValue00001" -> option.kind = "NeutralValue00001" /\ option.controller = w.active [] w.kind = "Paid" -> /\ ~w.site.traversalEnding /\ CASE option.kind = "RegularPaid" -> TRUE [] option.kind = "Activation" -> /\ option.controller = "SideA" /\ option.target \in DOMAIN objects /\ objects[option.target].kind \in {"Facility","Attachment","Barrier"} /\ ActivationPermission8(option.target,objects[option.target],PaidActivationContext9(w)) [] option.kind = "ObjectiveCompletion" -> option.controller = "SideA" /\ PaidWindowOptions9(w.site).score [] OTHER -> FALSE [] w.kind = "Reaction" -> option.kind = "Conditional" /\ ConditionalOptionMatches9(w,option) [] w.kind = "Interrupt" -> /\ InterruptEffectMatches9(w,actualCurrentEffect) /\ CASE option.kind = "ConditionalInterrupt" -> ConditionalOptionMatches9(w,option) /\ option.instance \in actualCurrentEffect.relevantConditional [] option.kind = "PaidInterrupt" -> option.ability \in actualCurrentEffect.paidInterruptAbilities [] OTHER -> FALSE [] w.kind = "MidItemInspection" -> option.kind = "MidItemInspection" /\ option.controller = "SideB" [] OTHER -> FALSE PriorityOptionLegality9(w,option,actualLegality) == /\ option.id \in Nat \ {0} /\ option.controller = w.priority /\ actualLegality.tag = "PriorityOptionLegality" /\ actualLegality.windowId = w.id /\ actualLegality.reception = w.reception /\ actualLegality.option = option /\ actualLegality.legal /\ actualLegality.active /\ actualLegality.transactionId \in Nat \ {0} /\ actualLegality.costsPayable /\ \A ref \in option.newStructures : TimingRefValid9(ref) /\ ~w.site.traversalEnding \/ option.newStructures = {} StartPriorityOptionFrame9(w,option,transactionId) == [w EXCEPT !.stage = "Resolving",!.priority = "NoValue",!.busy = option,!.busyTransaction = transactionId, !.pending = IF option.kind \in {"Conditional","ConditionalInterrupt"} THEN @ \ {option.instance} ELSE @, !.triggered = IF option.kind \in {"Conditional","ConditionalInterrupt"} THEN @ \cup {option.instance} ELSE @] PriorityChoiceValid9(before,option,objects,actualLegality,actualCurrentEffect) == /\ Len(before) > 0 /\ LET w == WindowTop9(before) IN /\ w.open /\ w.stage = "Ready" /\ w.checkpoint # 0 /\ w.busy.id = 0 /\ PriorityOptionAllowed9(w,option,objects,actualCurrentEffect) /\ PriorityOptionLegality9(w,option,actualLegality) BeginPriorityOption9(before,after,option,objects,actualLegality,actualCurrentEffect) == /\ Len(before) > 0 /\ WindowTop9(before).kind # "MidItemInspection" /\ PriorityChoiceValid9(before,option,objects,actualLegality,actualCurrentEffect) /\ after = ReplaceWindowTop9(before,StartPriorityOptionFrame9(WindowTop9(before),option,actualLegality.transactionId)) BeginMidItemInspectionOption9(before,after,option,objects,actualLegality,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034) == /\ Len(before) > 0 /\ WindowTop9(before).kind = "MidItemInspection" /\ WindowTop9(before).site.structure = TimingRef9("ItemInspection",a.id) /\ option.target = a.object /\ option.ability = midOption.id /\ PriorityChoiceValid9(before,option,objects,actualLegality,[x \in {} |-> x]) /\ StillItemInspectioning7(a,objects) /\ a.step="ProcedureCode1dd0e8f05be2" /\ ~a.midUsed /\ ~a.midDone /\ ~a.midResolving /\ midOption \in PayableMidOptions7(options) /\ midOption.timing="MidItemInspection" /\ objects[a.object].zone # "SideADiscard" \/ ~midOption.trashesItemInspectioned /\ MidItemInspectionChoiceAllowed7(midOption.id,options,mustRetire,exampleFamily034) /\ afterItemInspection = a /\ after = ReplaceWindowTop9(before,StartPriorityOptionFrame9(WindowTop9(before),option,actualLegality.transactionId)) PriorityPaymentMatches9(w,actualPayment) == /\ actualPayment.tag="PriorityOptionPayment" /\ actualPayment.windowId=w.id /\ actualPayment.option=w.busy /\ actualPayment.transactionId=w.busyTransaction /\ actualPayment.allTriggerCostsPaid /\ actualPayment.costCheckpointAndReactionsDrained PayMidItemInspectionOption9(stack,a,afterItemInspection,objects,midOption,options,mustRetire,exampleFamily034,actualPayment) == /\ Len(stack)>0 /\ LET w == WindowTop9(stack) IN /\ w.kind="MidItemInspection" /\ w.busy.id # 0 /\ w.stage \in {"Resolving","Closed"} /\ w.site.structure=TimingRef9("ItemInspection",a.id) /\ w.busy.target=a.object /\ w.busy.ability=midOption.id /\ PriorityPaymentMatches9(w,actualPayment) /\ UseMidItemInspection7(a,afterItemInspection,objects,midOption,options,mustRetire,exampleFamily034, actualPayment.allTriggerCostsPaid,actualPayment.costCheckpointAndReactionsDrained) CompletePriorityOptionFrame9(w) == LET idle == [w EXCEPT !.busy = NoPriorityOption9,!.busyTransaction = 0,!.previousPass = FALSE] IN IF ~w.open THEN idle ELSE IF w.kind \in {"NeutralValue00001","MidItemInspection"} THEN ClosePriorityWindow9(idle) ELSE ReceivePriority9(idle,w.busy.controller) PriorityOptionReturnValid9(before,actualReturn) == /\ Len(before) > 0 /\ LET w == WindowTop9(before) IN /\ w.busy.id # 0 /\ w.stage \in {"Resolving","Closed"} /\ actualReturn.tag = "PriorityOptionReturn" /\ actualReturn.windowId = w.id /\ actualReturn.option = w.busy /\ actualReturn.transactionId \in Nat \ {0} /\ actualReturn.transactionId = w.busyTransaction /\ PriorityPaymentMatches9(w,actualReturn.triggerPayment) /\ actualReturn.allCostsPaid /\ actualReturn.optionComplete /\ actualReturn.childrenReturned /\ actualReturn.reactionsDrained CompletePriorityOption9(before,after,actualReturn) == /\ Len(before)>0 /\ WindowTop9(before).kind # "MidItemInspection" /\ PriorityOptionReturnValid9(before,actualReturn) /\ after = ReplaceWindowTop9(before,CompletePriorityOptionFrame9(WindowTop9(before))) CompleteMidItemInspectionOption9(before,after,actualReturn,a,afterItemInspection) == /\ Len(before)>0 /\ WindowTop9(before).kind = "MidItemInspection" /\ WindowTop9(before).site.structure = TimingRef9("ItemInspection",a.id) /\ PriorityOptionReturnValid9(before,actualReturn) /\ FinishMidItemInspection7(a,afterItemInspection,TRUE) /\ after = ReplaceWindowTop9(before,CompletePriorityOptionFrame9(WindowTop9(before))) CanPassPriority9(w,actualCurrentEffect) == CASE w.kind = "Paid" -> TRUE [] w.kind = "Reaction" -> PendingOwned9(w,w.priority,TRUE) = {} [] w.kind = "Interrupt" -> InterruptEffectMatches9(w,actualCurrentEffect) /\ PendingOwned9(w,w.priority,TRUE) \cap actualCurrentEffect.relevantConditional = {} [] OTHER -> FALSE PassPriorityFrame9(w) == IF w.kind = "Reaction" THEN LET optional == PendingOwned9(w,w.priority,FALSE) lost == [w EXCEPT !.pending = @ \ optional,!.lostPending = @ \cup optional] IN IF w.priority = w.active THEN ReceivePriority9(lost,TurnOtherPlayer5(w.active)) ELSE ClosePriorityWindow9(lost) ELSE IF w.previousPass THEN ClosePriorityWindow9(w) ELSE ReceivePriority9([w EXCEPT !.previousPass = TRUE],TurnOtherPlayer5(w.priority)) PassPriority9(before,after,player,actualCurrentEffect) == /\ Len(before)>0 /\ LET w == WindowTop9(before) IN /\ w.open /\ w.stage = "Ready" /\ w.checkpoint # 0 /\ w.busy.id = 0 /\ w.priority = player /\ CanPassPriority9(w,actualCurrentEffect) /\ after = ReplaceWindowTop9(before,PassPriorityFrame9(w)) PassMidItemInspection9(before,after,a,afterItemInspection,objects,options,mustRetire,exampleFamily034) == /\ Len(before)>0 /\ LET w == WindowTop9(before) IN /\ w.kind = "MidItemInspection" /\ w.open /\ w.stage = "Ready" /\ w.priority = "SideB" /\ w.checkpoint # 0 /\ w.busy.id = 0 /\ w.site.structure = TimingRef9("ItemInspection",a.id) /\ DeclineMidItemInspection7(a,afterItemInspection,objects,options,mustRetire,exampleFamily034,TRUE) /\ after = ReplaceWindowTop9(before,ClosePriorityWindow9(w)) CancelBeginningReactions9(before,after,actualEnd) == /\ actualEnd.tag = "TimingStructureEnded" /\ TimingRefValid9(actualEnd.structure) /\ after = [i \in 1..Len(before) |-> IF before[i].open /\ before[i].kind = "Reaction" /\ before[i].beginning = actualEnd.structure THEN ClosePriorityWindow9(before[i]) ELSE before[i]] PopClosedPriorityWindow9(before,after) == /\ Len(before)>0 /\ ~WindowTop9(before).open /\ WindowTop9(before).busy.id = 0 /\ LET rest == SubSeq(before,1,Len(before)-1) IN after = IF Len(rest)>0 /\ WindowTop9(rest).open /\ WindowTop9(rest).stage = "Ready" THEN ReplaceWindowTop9(rest,ReceivePriority9(WindowTop9(rest),WindowTop9(rest).priority)) ELSE rest LegacyPriorityWindow9(w) == [id |-> w.id,kind |-> w.kind,open |-> w.open,priority |-> IF w.stage="Ready" THEN w.priority ELSE "NoValue", step |-> w.site.step,traversalId |-> w.site.traversalId, phaseId |-> IF w.site.structure.kind = "TraversalPhase" THEN w.site.structure.id ELSE 0, beginPhaseId |-> IF w.beginning.kind = "TraversalPhase" THEN w.beginning.id ELSE 0, beginItemInspectionId |-> IF w.beginning.kind = "ItemInspection" THEN w.beginning.id ELSE 0, beginInspectionId |-> IF w.beginning.kind = "Inspection" THEN w.beginning.id ELSE 0, pending |-> w.pending,lostPending |-> w.lostPending] TraversalEndCleanupClass9(w) == IF w.kind="Paid" THEN "Close" ELSE IF w.kind="Reaction" /\ w.beginning.kind="TraversalPhase" THEN "CloseBegin" ELSE "CompleteNormally" TraversalEndCleanupFrame9(w) == LET marked == [w EXCEPT !.site.traversalEnding=TRUE] IN IF TraversalEndCleanupClass9(w) \in {"Close","CloseBegin"} THEN ClosePriorityWindow9(marked) ELSE marked TraversalEndCleanupReceiptMatches9(stack,cleanupId,actualCleanup) == /\ cleanupId \in Nat \ {0} /\ actualCleanup.tag="TraversalEndWindowCleanup" /\ actualCleanup.id=cleanupId /\ actualCleanup.traversalId \in Nat /\ actualCleanup.encounterId \in Nat /\ actualCleanup.traversalId # 0 \/ actualCleanup.encounterId # 0 /\ actualCleanup.endInstructionId \in Nat \ {0} /\ actualCleanup.windowIds \subseteq {stack[i].id : i \in 1..Len(stack)} /\ DOMAIN actualCleanup.windows = actualCleanup.windowIds /\ \A i \in 1..Len(stack) : stack[i].id \in actualCleanup.windowIds => actualCleanup.windows[stack[i].id]=stack[i] /\ stack[i].open ApplyTraversalEndWindowPolicy9(before,after,cleanupId,actualCleanup) == /\ TraversalEndCleanupReceiptMatches9(before,cleanupId,actualCleanup) /\ after = [i \in 1..Len(before) |-> IF before[i].id \in actualCleanup.windowIds THEN TraversalEndCleanupFrame9(before[i]) ELSE before[i]] PriorityWindowValid9(w) == /\ w.id \in Nat \ {0} /\ w.kind \in PriorityWindowKinds9 /\ w.active=w.site.active /\ w.stage \in {"NeedCheckpoint","Ready","Resolving","Closed"} /\ w.open = (w.stage # "Closed") /\ w.reception \in Nat \ {0} /\ w.previousPass \in BOOLEAN /\ w.pending \cup w.lostPending \cup w.triggered = DOMAIN w.members /\ w.pending \cap w.lostPending = {} /\ w.pending \cap w.triggered = {} /\ w.lostPending \cap w.triggered = {} /\ IF w.kind \in {"Reaction","Interrupt"} THEN ConditionalGroupValid9(w.members,w.id,w.group,w.kind="Interrupt") ELSE w.members = [x \in {} |-> x] /\ w.group=0 /\ IF w.stage \in {"Ready","NeedCheckpoint"} THEN /\ w.priority \in SetupPlayers /\ w.busy.id=0 /\ w.busyTransaction=0 /\ w.checkpoint \in Nat /\ (w.checkpoint=0) = (w.stage="NeedCheckpoint") /\ (w.kind="NeutralValue00001" => w.priority=w.active) /\ (w.kind="MidItemInspection" => w.priority="SideB") ELSE w.priority="NoValue" /\ IF w.busy.id=0 THEN w.busyTransaction=0 /\ w.stage # "Resolving" ELSE w.busyTransaction \in Nat \ {0} /\ w.stage \in {"Resolving","Closed"} PriorityStackValid9(stack) == /\ \A i \in 1..Len(stack) : PriorityWindowValid9(stack[i]) /\ Cardinality({stack[i].id : i \in 1..Len(stack)}) = Len(stack) /\ Cardinality(ActionablePriority9(stack)) <= 1 TextClasses93 == {"SchemaAtom043","Restriction","Instruction","Declaration","AbilityFlag"} ConditionKinds93 == {"Cost","Trigger","Static"} RestrictionKinds93 == {"OwnCost","CardTimingLocation","AbilityUse","Payment","Hosting","Variable","Unpreventable"} AbilityFlagKinds93 == {"ItemInspection","Interface","Interrupt","Persistent","Threat","OncePerTurn"} TextUnit93(id,category,subtype,primary,value) == [id |-> id,category |-> category,subtype |-> subtype,primary |-> primary,value |-> value] TextUnitIds93(units,category) == {units[i].id : i \in {j \in 1..Len(units) : units[j].category=category}} FlagPresent93(units,flag) == \E i \in 1..Len(units) : units[i].category="AbilityFlag" /\ units[i].subtype=flag TextUnitsValid93(units) == /\ Cardinality({units[i].id : i \in 1..Len(units)})=Len(units) /\ \A i \in 1..Len(units) : /\ units[i].id \in Nat \ {0} /\ units[i].category \in TextClasses93 /\ units[i].primary \in BOOLEAN /\ CASE units[i].category="SchemaAtom043" -> units[i].subtype \in ConditionKinds93 [] units[i].category="Restriction" -> units[i].subtype \in RestrictionKinds93 [] units[i].category="AbilityFlag" -> units[i].subtype \in AbilityFlagKinds93 [] OTHER -> units[i].subtype="NoValue" /\ TextUnitIds93(units,"Instruction")={} \/ TextUnitIds93(units,"Declaration")={} FlagPrefixValid93(units,arrowAfterFlags) == /\ (TextUnitIds93(units,"AbilityFlag") # {}) => arrowAfterFlags /\ \A i,j \in 1..Len(units) : units[i].category="AbilityFlag" /\ units[j].category # "AbilityFlag" => i> ELSE <<1>>) /\ a.kind="Static" \/ TextUnitIds93(a.units,"Declaration")={} /\ ~a.barrierInstructionPrefix \/ ~a.paidPrefix.present /\ \A i \in {j \in 1..Len(a.units) : a.units[j].category="AbilityFlag"} : CASE a.units[i].subtype="ItemInspection" -> a.kind="Paid" /\ a.side="SideB" [] a.units[i].subtype="Interface" -> a.kind="Paid" /\ a.side="SideB" [] a.units[i].subtype="Interrupt" -> a.kind \in {"Paid","Conditional"} [] a.units[i].subtype="Persistent" -> a.side="SideA" [] a.units[i].subtype="Threat" -> a.units[i].value \in Nat [] a.units[i].subtype="OncePerTurn" -> a.kind \in {"Paid","Conditional"} WholeAbilityRestrictionGate93(a,actualRestrictions) == /\ actualRestrictions.tag="AbilityRestrictions" /\ actualRestrictions.ability=a.id /\ actualRestrictions.source=a.source /\ DOMAIN actualRestrictions.results=TextUnitIds93(a.units,"Restriction") /\ \A id \in DOMAIN actualRestrictions.results : actualRestrictions.results[id] ConditionReceiptMatches93(unit,ability,actualCondition) == /\ unit.category="SchemaAtom043" /\ actualCondition.tag="ConditionEvaluation" /\ actualCondition.ability=ability /\ actualCondition.unit=unit.id /\ actualCondition.kind=unit.subtype /\ CASE unit.subtype="Cost" -> actualCondition.paid [] unit.subtype="Trigger" -> actualCondition.eventOccurred [] unit.subtype="Static" -> actualCondition.propertyHolds DeclarationApplies93(active,conditionHolds) == active /\ conditionHolds ThreatFlagGate93(units,points) == \A i \in {j \in 1..Len(units) : units[j].category="AbilityFlag" /\ units[j].subtype="Threat"} : MaxOf(points["SideA"],points["SideB"]) >= units[i].value FlagActivity93(a,effectivePresentIds,actualOrdinaryActivity,actualLivePersistentAbilities,points) == /\ a.id \in effectivePresentIds /\ actualOrdinaryActivity \/ (FlagPresent93(a.units,"Persistent") /\ a.side="SideA" /\ a.id \in actualLivePersistentAbilities) /\ ThreatFlagGate93(a.units,points) ItemInspectionFlagTiming93(a,w) == ~FlagPresent93(a.units,"ItemInspection") \/ (a.kind="Paid" /\ a.side="SideB" /\ w.kind="MidItemInspection" /\ w.site.step="ProcedureCode1dd0e8f05be2") InterfaceFlagTiming93(a,actor,source,sourceSubtypes,localAbility,context,sourceStrength,barrierStrength,barrierSubtypes,targets) == ~FlagPresent93(a.units,"Interface") \/ (/\ a.kind="Paid" /\ actor="SideB" /\ BarrierResponseCardTechnique(source,sourceSubtypes) /\ sourceStrength.exists /\ barrierStrength.exists /\ sourceStrength.amount >= barrierStrength.amount /\ InterfaceAbilityLocalGate(actor,source,sourceSubtypes,localAbility,context,sourceStrength,barrierStrength,barrierSubtypes,targets)) InterruptFlagTiming93(a,w,actualRelevance) == ~FlagPresent93(a.units,"Interrupt") \/ (/\ a.kind \in {"Paid","Conditional"} /\ w.kind="Interrupt" /\ actualRelevance.tag="InterruptRelevance" /\ actualRelevance.windowId=w.id /\ actualRelevance.instruction=w.instruction /\ actualRelevance.ability=a.id /\ actualRelevance.source=a.source /\ actualRelevance.relevant) OncePerTurnAllowed93(a,turnId,ledger) == ~FlagPresent93(a.units,"OncePerTurn") \/ ~\E id \in DOMAIN ledger : ledger[id].turnId=turnId /\ ledger[id].ability=a.id /\ ledger[id].source=a.source RecordTurnAbilityUse93(before,after,a,turnId,instance,actualUse) == /\ turnId \in Nat \ {0} /\ instance.ability=a.id /\ instance.source=a.source /\ actualUse.tag="AbilityUsed" /\ actualUse.useId \in (Nat \ {0}) \ DOMAIN before /\ actualUse.abilityInstance=instance.id /\ actualUse.source=a.source /\ actualUse.player=a.controller /\ after = [id \in DOMAIN before \cup {actualUse.useId} |-> IF id=actualUse.useId THEN [turnId |-> turnId,ability |-> a.id,source |-> a.source,useId |-> actualUse.useId] ELSE before[id]] OpenInstruction93(id,origin,abilityInstance,source,sourceZone,index,ruleStep,steps,requiresTargets) == [id |-> id,origin |-> origin,abilityInstance |-> abilityInstance,source |-> source,sourceZone |-> sourceZone, index |-> index,ruleStep |-> ruleStep, steps |-> steps,requiresTargets |-> requiresTargets,targets |-> {},announced |-> FALSE, phase |-> "Planning",cursor |-> 1,revision |-> 0,completedSteps |-> <<>>] InstructionPlanMatches93(plan,ability,index) == /\ plan.origin="Ability" /\ plan.abilityInstance=ability.id /\ plan.source=ability.source /\ plan.sourceZone=ability.sourceZone /\ index \in 1..Len(ability.instructions) /\ plan.index=index /\ plan.id=ability.instructions[index] PreImminentAbilityPlan93(plan,ability) == /\ CASE ability.phase="Ready" -> ability.cursor=1 /\ ~ability.firstImminent /\ InstructionPlanMatches93(plan,ability,1) [] ability.phase="Between" -> AbilityIsResolving9(ability) /\ InstructionPlanMatches93(plan,ability,ability.cursor+1) [] OTHER -> FALSE RuleInstructionPlan93(plan,actualRuleStep) == /\ plan.origin="Rule" /\ plan.abilityInstance=0 /\ plan.index=0 /\ plan.source=RuleAbilitySource9(plan.ruleStep) /\ plan.sourceZone="NoValue" /\ plan.ruleStep # "NoValue" /\ plan.ruleStep=actualRuleStep AnnounceInstructionTargets93(before,after,actualTargets,abilityFrame,actualRuleStep) == /\ before.phase="Planning" /\ actualTargets.tag="InstructionTargets" /\ actualTargets.instruction=before.id /\ actualTargets.abilityInstance=before.abilityInstance /\ actualTargets.valid /\ actualTargets.source=before.source /\ actualTargets.sourceZone=before.sourceZone /\ actualTargets.index=before.index /\ IF before.origin="Ability" THEN PreImminentAbilityPlan93(before,abilityFrame) ELSE RuleInstructionPlan93(before,actualRuleStep) /\ after=[before EXCEPT !.targets=actualTargets.targets,!.announced=TRUE] InstructionPlanReady93(plan) == /\ plan.phase="Planning" /\ plan.id \in Nat \ {0} /\ Len(plan.steps)>0 /\ ~plan.requiresTargets \/ plan.announced InstructionEntryReceipt93(plan,actualEntry) == /\ actualEntry.tag="AbilityInstructionEntry" /\ actualEntry.abilityInstance=plan.abilityInstance /\ actualEntry.instruction=plan.id /\ actualEntry.index=plan.index /\ actualEntry.source=plan.source /\ actualEntry.sourceZone=plan.sourceZone EnterFirstAbilityInstruction93(beforeAbility,afterAbility,before,after,actualEntry) == /\ beforeAbility.cursor=1 /\ InstructionPlanReady93(before) /\ InstructionPlanMatches93(before,beforeAbility,1) /\ InstructionEntryReceipt93(before,actualEntry) /\ BeginAbilityInstructions9(beforeAbility,afterAbility,actualEntry.schedulerAllows,actualEntry.sourceEligible) /\ after=[before EXCEPT !.phase="Imminent"] EnterNextAbilityInstruction93(beforeAbility,afterAbility,before,after,actualEntry) == /\ InstructionPlanReady93(before) /\ InstructionPlanMatches93(before,beforeAbility,beforeAbility.cursor+1) /\ InstructionEntryReceipt93(before,actualEntry) /\ ContinueAbilityInstructions9(beforeAbility,afterAbility,actualEntry.checkpointAndAllNewerChainsComplete) /\ after=[before EXCEPT !.phase="Imminent"] EnterRuleInstruction93(before,after,actualRuleStep) == /\ InstructionPlanReady93(before) /\ RuleInstructionPlan93(before,actualRuleStep) /\ after=[before EXCEPT !.phase="Imminent"] InstructionImminentAtOrigin93(plan,ability,actualRuleStep) == /\ plan.phase="Imminent" /\ IF plan.origin="Ability" THEN /\ plan.abilityInstance \in Nat \ {0} /\ plan.index \in Nat \ {0} /\ ability.phase="Imminent" /\ InstructionPlanMatches93(plan,ability,ability.cursor) ELSE RuleInstructionPlan93(plan,actualRuleStep) InstructionWindowRef93(plan) == [origin |-> plan.origin,id |-> plan.id,abilityInstance |-> plan.abilityInstance,index |-> plan.index, source |-> plan.source,sourceZone |-> plan.sourceZone,ruleStep |-> plan.ruleStep,revision |-> plan.revision] InstructionProfileMatches93(ref,plan) == /\ ref.origin=plan.origin /\ ref.id=plan.id /\ ref.abilityInstance=plan.abilityInstance /\ ref.index=plan.index /\ ref.source=plan.source /\ ref.sourceZone=plan.sourceZone /\ ref.ruleStep=plan.ruleStep OpenInstructionInterrupt93(before,after,id,site,instances,opening,usedWindowIds,plan,ability,actualRuleStep) == /\ InstructionImminentAtOrigin93(plan,ability,actualRuleStep) /\ plan.id \in Nat \ {0} /\ plan.revision \in Nat /\ id \in (Nat \ {0}) \ usedWindowIds /\ id \notin {before[i].id : i \in 1..Len(before)} /\ WindowSiteAllowed9("Interrupt",PriorityOpeningSite9(before,site)) /\ plan.origin="Rule" => site.step=actualRuleStep /\ opening.tag="PriorityWindowOpening" /\ opening.windowId=id /\ opening.kind="Interrupt" /\ opening.site=site /\ opening.members=DOMAIN instances /\ opening.instances=instances /\ ConditionalGroupValid9(instances,id,opening.group,TRUE) /\ opening.instruction=InstructionWindowRef93(plan) /\ opening.effectRevision \in Nat \ {0} /\ opening.preparation= <<"ExpectedEffects","ReplacementEffects","ConditionalPending">> /\ opening.modifiersExist /\ opening.beginning=NoTimingRef9 /\ after=Append(before,NewPriorityWindow9(id,"Interrupt",PriorityOpeningSite9(before,site),instances, opening.group,NoTimingRef9,opening.instruction,opening.effectRevision)) InstructionInterruptReturnMatches93(plan,actualReturn) == /\ actualReturn.tag="InstructionInterruptReturn" /\ actualReturn.instruction=plan.id /\ actualReturn.origin=plan.origin /\ actualReturn.abilityInstance=plan.abilityInstance /\ actualReturn.index=plan.index /\ actualReturn.source=plan.source /\ actualReturn.sourceZone=plan.sourceZone /\ actualReturn.revision=plan.revision /\ actualReturn.complete /\ actualReturn.windowId \in Nat /\ actualReturn.openingRevision \in Nat /\ actualReturn.openingRevision <= plan.revision ReturnInstructionInterrupt93(before,after,plan,ability,actualRuleStep,actualReturn) == /\ Len(before)>0 /\ InstructionImminentAtOrigin93(plan,ability,actualRuleStep) /\ InstructionInterruptReturnMatches93(plan,actualReturn) /\ LET w == WindowTop9(before) IN /\ w.kind="Interrupt" /\ InstructionProfileMatches93(w.instruction,plan) /\ w.pending={} /\ actualReturn.windowId=w.id /\ actualReturn.openingRevision=w.instruction.revision /\ PopClosedPriorityWindow9(before,after) NoInstructionInterrupt93(plan,ability,actualRuleStep,actualNoModifiers,actualReturn) == /\ InstructionImminentAtOrigin93(plan,ability,actualRuleStep) /\ actualNoModifiers.tag="NoInstructionInterruptModifiers" /\ actualNoModifiers.instruction=InstructionWindowRef93(plan) /\ actualNoModifiers.conditionalInstances={} /\ actualNoModifiers.paidInterruptAbilities={} /\ InstructionInterruptReturnMatches93(plan,actualReturn) /\ actualReturn.windowId=0 /\ actualReturn.openingRevision=plan.revision AlterImminentInstruction93(before,after,actualModification) == /\ before.phase="Imminent" /\ actualModification.tag="InstructionModification" /\ actualModification.instruction=before.id /\ actualModification.revision=before.revision /\ actualModification.authorized /\ Len(actualModification.steps)>0 /\ after=[before EXCEPT !.steps=actualModification.steps,!.revision=@+1] AlterAbilityInstruction93(ability,before,after,actualModification) == /\ ability.phase="Imminent" /\ InstructionPlanMatches93(before,ability,ability.cursor) /\ AlterImminentInstruction93(before,after,actualModification) BeginAtomicInstruction93(before,after,actualInterruptReturn) == /\ before.phase="Imminent" /\ actualInterruptReturn.tag="InstructionInterruptReturn" /\ actualInterruptReturn.instruction=before.id /\ actualInterruptReturn.revision=before.revision /\ actualInterruptReturn.complete /\ after=[before EXCEPT !.phase="Resolving"] BeginAbilityInstructionAtomic93(beforeAbility,afterAbility,before,after,actualInterruptReturn) == /\ InstructionPlanMatches93(before,beforeAbility,beforeAbility.cursor) /\ InstructionInterruptReturnMatches93(before,actualInterruptReturn) /\ BeginAtomicInstruction93(before,after,actualInterruptReturn) /\ ResolveCurrentInstruction9(beforeAbility,afterAbility,actualInterruptReturn.complete) BeginRuleInstructionAtomic93(before,after,actualRuleStep,actualInterruptReturn) == /\ RuleInstructionPlan93(before,actualRuleStep) /\ InstructionInterruptReturnMatches93(before,actualInterruptReturn) /\ BeginAtomicInstruction93(before,after,actualInterruptReturn) CarryInstructionStep93(before,after,actualStep) == /\ before.phase="Resolving" /\ actualStep.tag="InstructionStepReturn" /\ actualStep.instruction=before.id /\ actualStep.index=before.cursor /\ actualStep.step=before.steps[before.cursor] /\ actualStep.complete /\ after=[before EXCEPT !.completedSteps=Append(@,before.steps[before.cursor]),!.cursor=@+1, !.phase=IF before.cursor=Len(before.steps) THEN "Complete" ELSE "Resolving"] CarryAbilityInstructionStep93(beforeAbility,afterAbility,before,after,actualStep) == /\ beforeAbility.phase="Resolving" /\ InstructionPlanMatches93(before,beforeAbility,beforeAbility.cursor) /\ CarryInstructionStep93(before,after,actualStep) /\ IF before.cursor=Len(before.steps) THEN FinishAbilityInstruction9(beforeAbility,afterAbility, [abilityInstance |-> beforeAbility.id,instruction |-> before.id,complete |-> actualStep.complete]) ELSE afterAbility=beforeAbility StaticConditionIds94(a) == {a.units[i].id : i \in {j \in 1..Len(a.units) : a.units[j].category="SchemaAtom043" /\ a.units[j].subtype="Static"}} StaticAbilityActive94(definition,syntax,objects,present,actualDefaultActive,context,points) == /\ definition.kind="Static" /\ syntax.kind="Static" /\ definition.id=syntax.id /\ definition.source=syntax.source /\ AbilityTextValid93(syntax) /\ FlagActivity93(syntax,present,AbilityActive9(definition,objects,present,actualDefaultActive,context),context.persistentAbilities,points) StaticConditionSnapshot94(a,actualConditions) == /\ actualConditions.tag="StaticConditionSnapshot" /\ actualConditions.ability=a.id /\ actualConditions.source=a.source /\ DOMAIN actualConditions.receipts=StaticConditionIds94(a) StaticPartApplies94(a,part,active,actualConditions) == /\ a.kind="Static" /\ part.id \in TextUnitIds93(a.units,"Declaration") \cup TextUnitIds93(a.units,"Restriction") /\ part.ability=a.id /\ active /\ StaticConditionSnapshot94(a,actualConditions) /\ part.conditions \subseteq StaticConditionIds94(a) /\ \A id \in part.conditions : LET unit == a.units[CHOOSE i \in 1..Len(a.units) : a.units[i].id=id] IN ConditionReceiptMatches93(unit,a.id,actualConditions.receipts[id]) StaticProjection94(a,part,currentValue) == [ability |-> a.id,source |-> a.source,part |-> part.id,target |-> part.target,property |-> part.property, mode |-> "Continuous",value |-> currentValue,duration |-> NoTimingRef9,window |-> NoTimingRef9,resolving |-> FALSE,lingering |-> FALSE] ObserveStaticDeclarations94(a,parts,active,actualConditions,currentValues,after) == /\ a.kind="Static" /\ DOMAIN currentValues=DOMAIN parts /\ DOMAIN parts=TextUnitIds93(a.units,"Declaration") /\ StaticConditionSnapshot94(a,actualConditions) /\ \A id \in DOMAIN parts : parts[id].id=id /\ parts[id].ability=a.id /\ after=[id \in {i \in DOMAIN parts : StaticPartApplies94(a,parts[i],active,actualConditions)} |-> StaticProjection94(a,parts[id],currentValues[id])] ObserveCurrentStaticDeclarations94(definition,syntax,objects,present,actualDefaultActive,context,points,parts,actualConditions,currentValues,after) == ObserveStaticDeclarations94(syntax,parts,StaticAbilityActive94(definition,syntax,objects,present,actualDefaultActive,context,points), actualConditions,currentValues,after) ObserveStaticRestrictions94(a,parts,active,actualConditions,after) == /\ a.kind="Static" /\ DOMAIN parts=TextUnitIds93(a.units,"Restriction") /\ StaticConditionSnapshot94(a,actualConditions) /\ \A id \in DOMAIN parts : parts[id].id=id /\ parts[id].ability=a.id /\ after={id \in DOMAIN parts : StaticPartApplies94(a,parts[id],active,actualConditions)} ObserveCurrentStaticRestrictions94(definition,syntax,objects,present,actualDefaultActive,context,points,parts,actualConditions,after) == ObserveStaticRestrictions94(syntax,parts,StaticAbilityActive94(definition,syntax,objects,present,actualDefaultActive,context,points),actualConditions,after) Specimen0203HostedOnBarrier94(objects,Specimen0203) == IF Specimen0203 \notin DOMAIN objects THEN FALSE ELSE LET host == objects[Specimen0203].host IN IF host \notin DOMAIN objects THEN FALSE ELSE objects[host].form="Card" /\ objects[host].kind="Barrier" Specimen0203AdditionalMoveConstraint94(objects,Specimen0203,target,actualBarrierPositions) == IF ~Specimen0203HostedOnBarrier94(objects,Specimen0203) THEN TRUE ELSE LET host == objects[Specimen0203].host IN /\ {host,target} \subseteq DOMAIN actualBarrierPositions /\ actualBarrierPositions[host].targetSite=actualBarrierPositions[target].targetSite \/ actualBarrierPositions[host].position=actualBarrierPositions[target].position ModifyValuePreservingSpecifications94(before,after,newAmount) == /\ before.amount \in Int /\ newAmount \in Int /\ after=[before EXCEPT !.amount=newAmount] HostedPowerCount94(objects,host) == Cardinality({id \in DOMAIN objects : objects[id].form="Counter" /\ objects[id].kind="Power" /\ objects[id].host=host}) Specimen0189Values94(objects,source) == [id \in {10,11} |-> IF id=10 THEN 2+HostedPowerCount94(objects,source) ELSE 1+HostedPowerCount94(objects,source)] Specimen0100PaidStrengthDuration94(effect,host,turnId,actualShorterThanTurn) == IF effect.mode="Continuous" THEN effect ELSE IF effect.originKind="Paid" /\ effect.property="Strength" /\ effect.boost.target=host /\ effect.boost.amount>0 /\ turnId \in Nat \ {0} /\ actualShorterThanTurn THEN [effect EXCEPT !.boost.hasExplicit=TRUE,!.boost.explicit=TimingRef9("Turn",turnId)] ELSE effect Specimen0100CurrentPaidDuration94(definition,syntax,objects,present,actualDefaultActive,context,points,effect,turnId,actualShorterThanTurn) == IF ~StaticAbilityActive94(definition,syntax,objects,present,actualDefaultActive,context,points) THEN effect ELSE IF definition.source.kind # "Object" THEN effect ELSE LET source == definition.source.object IN IF source \notin DOMAIN objects THEN effect ELSE IF objects[source].host=0 THEN effect ELSE Specimen0100PaidStrengthDuration94(effect,objects[source].host,turnId,actualShorterThanTurn) PaidIsInterrupt95(d) == AbilityIsInterrupt9(FlagPresent93(d.syntax.units,"Interrupt"),d.instructionHasWould) PaidRequiredWindows95(d) == (IF IsAction5(TRUE,d.triggerCost) THEN {"NeutralValue00001"} ELSE {}) \cup (IF PaidIsInterrupt95(d) THEN {"Interrupt"} ELSE {}) \cup (IF FlagPresent93(d.syntax.units,"ItemInspection") \/ d.ruleTiming="BasicRetire" THEN {"MidItemInspection"} ELSE {}) PaidWindowKinds95(d) == LET required == PaidRequiredWindows95(d) IN IF required={} THEN {"Paid"} ELSE IF Cardinality(required)=1 THEN required ELSE {} PaidAlwaysOptional95(d) == d.syntax.kind="Paid" EncounterLive95(e) == e.id \in Nat \ {0} /\ ~e.aborted /\ e.stage \in {"BeginReactions","Paid","BarrierInstructions"} EncounterTimingLive95(e,actualControl) == /\ EncounterLive95(e) /\ TraversalFrameValid6(actualControl.traversal) /\ e.id \notin actualControl.phaseEndedIds /\ e.traversalId=0 \/ (e.traversalId=actualControl.traversal.id /\ TraversalTimingPresent6(actualControl.traversal)) EncounterPaidSite95(turn,e,actualControl) == PrioritySite9("SchemaAtom138","ProcedureCode8b3260c0010f","Encounter",TimingRef9("TraversalPhase",e.id),turn.owner,turn.id,e.traversalId,0,0,0,FALSE, TurnFrameValid5(turn) /\ e.stage="Paid" /\ EncounterTimingLive95(e,actualControl), e.stage="Paid" /\ EncounterTimingLive95(e,actualControl)) PaidEncounterLive95(c) == EncounterTimingLive95(c.encounter,c.traversalControl) PaidWindowContext95(c,w) == IF w.kind="Paid" /\ w.site.route="SchemaAtom138" /\ w.site.step="ProcedureCode8b3260c0010f" THEN /\ w.site.structure=TimingRef9("TraversalPhase",c.encounter.id) /\ w.site.traversalId=c.encounter.traversalId /\ PaidEncounterLive95(c) ELSE TRUE PaidTraversalContextBound95(c) == /\ TraversalFrameValid6(c.traversal) /\ c.traversalControl.traversal=c.traversal /\ c.traversalControl.phaseEndedIds \subseteq Nat \ {0} PaidReferenceContext95(reference,c,witness) == IF reference="Approach" THEN /\ witness.structure=TimingRef9("TraversalPhase",c.approach.id) /\ witness.traversalId=c.approach.traversalId /\ PaidTraversalContextBound95(c) /\ c.traversal.phaseId \notin c.traversalControl.phaseEndedIds ELSE /\ witness.structure=TimingRef9("TraversalPhase",c.encounter.id) /\ witness.traversalId=c.encounter.traversalId PaidReferenceStipulations95(d,reference,barrierCard,requirements,c) == /\ barrierCard \in DOMAIN c.objects /\ c.objects[barrierCard].form="Card" /\ c.objects[barrierCard].kind="Barrier" /\ requirements.subtypes \subseteq c.subtypes[barrierCard] /\ ~requirements.activated \/ ActivationStatus8(c.objects[barrierCard])="ItemActivated" /\ LET witness == c.references[reference] IN /\ witness.tag="PaidBarrierReference" /\ witness.ability=d.syntax.id /\ witness.source=d.syntax.source /\ witness.reference=reference /\ witness.barrierCard=barrierCard /\ PaidReferenceContext95(reference,c,witness) /\ DOMAIN witness.results=requirements.otherIds /\ \A id \in DOMAIN witness.results : witness.results[id] PaidEffectTiming95(d,c) == /\ ~d.canSuppressBarrierInstructions \/ PaidEncounterLive95(c) /\ ~d.refersApproachedBarrier \/ (/\ TraversalTimingPresent6(c.traversal) /\ ~c.traversal.ending /\ c.traversal.phase="Approach" /\ c.approach.id=c.traversal.phaseId /\ c.approach.traversalId=c.traversal.id /\ c.approach.begun /\ PaidReferenceStipulations95(d,"Approach",ApproachedBarrier6(c.approach,c.layout),d.approachRequirements,c)) /\ ~d.refersEncounteredBarrier \/ (PaidEncounterLive95(c) /\ PaidReferenceStipulations95(d,"Encounter",c.encounter.barrierCard,d.encounterRequirements,c)) PaidSourceUseAllowed95(d,c) == ~\E p \in c.useProhibitions : p.source=d.syntax.source /\ p.traversalId=c.traversal.id /\ TraversalTimingPresent6(c.traversal) PaidOtherRestrictions95(d,c) == /\ c.otherRestrictions.tag="OtherPaidRestrictions" /\ c.otherRestrictions.ability=d.syntax.id /\ c.otherRestrictions.source=d.syntax.source /\ DOMAIN c.otherRestrictions.results=d.otherRestrictionIds /\ \A id \in DOMAIN c.otherRestrictions.results : c.otherRestrictions.results[id] PaidInterfaceTiming95(d,c,site) == IF ~FlagPresent93(d.syntax.units,"Interface") THEN TRUE ELSE LET source == d.syntax.source.object barrierCard == c.encounter.barrierCard IN /\ d.syntax.source.kind="Object" /\ {source,barrierCard} \subseteq DOMAIN c.objects /\ InterfaceFlagTiming93(d.syntax,d.syntax.controller,c.objects[source],c.subtypes[source], [isInterface |-> TRUE,presentActive |-> TRUE,restriction |-> d.interfaceSubtype], [encounterActive |-> PaidEncounterLive95(c),step |-> site.step, barrierForm |-> c.objects[barrierCard].form,barrierKind |-> c.objects[barrierCard].kind,barrierId |-> barrierCard,barrierInstructions |-> SubIds6(c.encounter.order)], c.strengths[source],c.strengths[barrierCard],c.subtypes[barrierCard],{}) PaidEligibility95(d,c,w) == /\ PaidTraversalContextBound95(c) /\ PaidWindowContext95(c,w) /\ d.syntax.kind="Paid" /\ d.activity.kind="Paid" /\ d.activity.id=d.syntax.id /\ d.activity.source=d.syntax.source /\ AbilityTextValid93(d.syntax) /\ Len(d.triggerCost)>0 /\ Len(d.instructions)>0 /\ d.ruleTiming \in {"NoValue","BasicRetire"} /\ d.ruleTiming="BasicRetire" => d.syntax.source=RuleAbilitySource9("BasicRetire") /\ WindowSiteAllowed9(w.kind,w.site) /\ w.kind \in PaidWindowKinds95(d) /\ w.priority=d.syntax.controller /\ w.active=c.turn.owner /\ w.site.turnId=c.turn.id /\ FlagActivity93(d.syntax,c.present,AbilityActive9(d.activity,c.objects,c.present,c.defaultActive, c.activity),c.activity.persistentAbilities,c.points) /\ WholeAbilityRestrictionGate93(d.syntax,c.ownRestrictions) /\ PaidOtherRestrictions95(d,c) /\ OncePerTurnAllowed93(d.syntax,c.turn.id,c.uses) /\ PaidSourceUseAllowed95(d,c) /\ PaidEffectTiming95(d,c) /\ PaidInterfaceTiming95(d,c,w.site) /\ IF PaidIsInterrupt95(d) THEN /\ InterruptEffectMatches9(w,c.currentEffect) /\ d.syntax.id \in c.currentEffect.paidInterruptAbilities /\ c.paidRelevance.tag="PaidInterruptRelevance" /\ c.paidRelevance.windowId=w.id /\ c.paidRelevance.instruction=w.instruction /\ c.paidRelevance.revision=c.currentEffect.revision /\ [ability |-> d.syntax.id,source |-> d.syntax.source] \in c.paidRelevance.eligible ELSE TRUE PaidOptionKind95(windowKind) == CASE windowKind="NeutralValue00001" -> "NeutralValue00001" [] windowKind="Paid" -> "RegularPaid" [] windowKind="Interrupt" -> "PaidInterrupt" [] windowKind="MidItemInspection" -> "MidItemInspection" [] OTHER -> "Invalid" PaidOptionMatches95(d,option,w) == option.kind=PaidOptionKind95(w.kind) /\ option.ability=d.syntax.id /\ option.source=d.syntax.source /\ option.controller=d.syntax.controller OpenPaidProcedure95(id,d,option,window,transaction,sourceZone) == [id |-> id,definition |-> d,option |-> option,windowId |-> window.id,transaction |-> transaction, ability |-> OpenAbilityResolution9(id,"Paid",d.syntax.source,sourceZone,d.instructions,window.id), turnId |-> window.site.turnId,initialCheckpoint |-> window.checkpoint,phase |-> "PayCosts",costPaid |-> FALSE,checkpoint |-> 0,heldSourceIds |-> {},heldIds |-> {},sourceForfeited |-> FALSE] PaidProcedureAtTop95(stack,p) == /\ Len(stack)>0 /\ LET w == WindowTop9(stack) IN w.id=p.windowId /\ w.busy=p.option /\ w.busyTransaction=p.transaction /\ w.stage \in {"Resolving","Closed"} ReservePaidAbility95(before,after,p,id,d,c,option,legality,usedAbilityInstances) == /\ Len(before)>0 /\ id \in (Nat \ {0}) \ usedAbilityInstances /\ PaidEligibility95(d,c,WindowTop9(before)) /\ PaidOptionMatches95(d,option,WindowTop9(before)) /\ BeginPriorityOption9(before,after,option,c.objects,legality,c.currentEffect) /\ p=OpenPaidProcedure95(id,d,option,WindowTop9(before),legality.transactionId, IF d.syntax.source.kind="Object" THEN c.objects[d.syntax.source.object].zone ELSE "Rule") ReservePaidMidItemInspection95(before,after,p,id,d,c,option,legality,usedAbilityInstances,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034) == /\ Len(before)>0 /\ id \in (Nat \ {0}) \ usedAbilityInstances /\ PaidEligibility95(d,c,WindowTop9(before)) /\ PaidOptionMatches95(d,option,WindowTop9(before)) /\ BeginMidItemInspectionOption9(before,after,option,c.objects,legality,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034) /\ p=OpenPaidProcedure95(id,d,option,WindowTop9(before),legality.transactionId, IF d.syntax.source.kind="Object" THEN c.objects[d.syntax.source.object].zone ELSE "Rule") PaidPhysicalHosted95(objects,source) == {id \in DOMAIN objects : objects[id].host=source /\ (objects[id].form="Card" \/ (objects[id].form="Counter" /\ ~objects[id].virtual))} ProtectedPaidTransit95(current,oldObject,p,forfeited) == LET base == SetAsideTransit4(current,oldObject.zone,oldObject.loc,p.transaction,p.id,TRUE,forfeited) IN [object |-> base.object,originZone |-> base.originZone,originLocation |-> base.originLocation, effect |-> base.effect,ability |-> base.ability,protected |-> base.protected,cleanupStage |-> base.cleanupStage, originFace |-> oldObject.face,originDeployed |-> oldObject.deployed,originForm |-> oldObject.form] PaidPaymentProof95(p,beforeObjects,afterObjects,actualPayment) == /\ p.phase="PayCosts" /\ ~p.costPaid /\ actualPayment.tag="PaidTriggerPayment" /\ actualPayment.abilityInstance=p.id /\ actualPayment.transactionId=p.transaction /\ actualPayment.ability=p.definition.syntax.id /\ actualPayment.source=p.ability.source /\ actualPayment.triggerCost=p.definition.triggerCost /\ actualPayment.beforeObjects=beforeObjects /\ actualPayment.afterObjects=afterObjects /\ actualPayment.announced /\ actualPayment.allPaid /\ actualPayment.additionalCostsPaid /\ actualPayment.restrictionsBefore /\ actualPayment.restrictionsAfter /\ actualPayment.simultaneousProcedureComplete /\ IF p.ability.source.kind="Rule" THEN ~actualPayment.sourceUninstalled /\ ~actualPayment.sourceForfeited /\ actualPayment.sourceAfter=0 ELSE LET source == p.ability.source.object IN /\ source \in DOMAIN beforeObjects /\ actualPayment.sourceAfter \in Nat /\ actualPayment.sourceAfter # source => source \notin DOMAIN afterObjects /\ IF actualPayment.sourceAfter=0 THEN beforeObjects[source].form="Counter" /\ beforeObjects[source].card="none" /\ source \notin DOMAIN afterObjects ELSE /\ actualPayment.sourceAfter \in DOMAIN afterObjects /\ afterObjects[actualPayment.sourceAfter].card=beforeObjects[source].card /\ beforeObjects[source].zone # afterObjects[actualPayment.sourceAfter].zone => actualPayment.sourceAfter # source /\ actualPayment.sourceUninstalled = (beforeObjects[source].deployed /\ (IF actualPayment.sourceAfter=0 THEN TRUE ELSE ~afterObjects[actualPayment.sourceAfter].deployed)) /\ actualPayment.sourceForfeited = (\E op \in actualPayment.paidOperations : op.kind="Forfeit" /\ op.object=source) /\ actualPayment.sourceForfeited => beforeObjects[source].zone \in SetupObjectiveZones PaidHeldTransfer95(p,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualPayment) == LET source == p.ability.source.object hosted == IF p.ability.source.kind="Object" THEN PaidPhysicalHosted95(beforeObjects,source) ELSE {} protect == (actualPayment.sourceUninstalled \/ actualPayment.sourceForfeited) /\ p.definition.refersHosted selected == IF protect THEN hosted ELSE {} IN /\ HostedCostSetAsideChoice4(hosted,DOMAIN successors,actualPayment.sourceUninstalled \/ actualPayment.sourceForfeited,p.definition.refersHosted) /\ DOMAIN beforeObjects \subseteq usedIds /\ FreshSuccessors8(selected,successors,usedIds) /\ actualPayment.sourceAfter # 0 /\ actualPayment.sourceAfter # source => actualPayment.sourceAfter \notin usedIds /\ \A old \in selected : LET new == successors[old] IN /\ new \in DOMAIN afterObjects /\ old \notin DOMAIN afterObjects /\ afterObjects[new].card=beforeObjects[old].card /\ afterObjects[new].host=0 /\ IF beforeObjects[old].card="none" THEN afterObjects[new].form="Counter" /\ afterObjects[new].kind=beforeObjects[old].kind /\ ~afterObjects[new].virtual ELSE TRUE /\ SetAsideEntryPost4(afterObjects[new],FALSE,FALSE,TRUE) /\ afterTransits=[id \in (DOMAIN beforeTransits \ selected) \cup {successors[old] : old \in selected} |-> IF id \in {successors[old] : old \in selected} THEN ProtectedPaidTransit95(id,beforeObjects[CHOOSE old \in selected : successors[old]=id],p,actualPayment.sourceForfeited) ELSE beforeTransits[id]] /\ SetAsideTrackingValid4(afterObjects,afterTransits) /\ IF actualPayment.sourceForfeited THEN ForfeitObjectivePost8(beforeObjects,afterObjects,source,actualPayment.sourceAfter,usedIds) ELSE TRUE CommitPaidTrigger95(stack,before,after,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualPayment,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) == /\ PaidProcedureAtTop95(stack,before) /\ PaidPaymentProof95(before,beforeObjects,afterObjects,actualPayment) /\ PaidHeldTransfer95(before,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualPayment) /\ LET a == [before.ability EXCEPT !.detached=TRUE] used == [tag |-> "AbilityUsed",useId |-> useId,abilityInstance |-> before.id,source |-> before.ability.source,player |-> before.definition.syntax.controller] IN /\ DetachPaidAbility9(before.ability,a,[abilityInstance |-> before.id,allPaid |-> actualPayment.allPaid]) /\ RecordAbilityUse9(beforeUses,afterUses,useId,before.id,before.ability.source,before.definition.syntax.controller, AbilityUseDue9("Paid",FALSE,actualPayment.allPaid,FALSE,FALSE),{used}) /\ RecordTurnAbilityUse93(beforeTurnUses,afterTurnUses,before.definition.syntax,before.turnId, [id |-> before.id,ability |-> before.definition.syntax.id,source |-> before.ability.source],used) /\ OncePerTurnAllowed93(before.definition.syntax,before.turnId,beforeTurnUses) /\ events={used} \cup actualPayment.publicEvents /\ after=[before EXCEPT !.ability=a,!.phase="CostCheckpoint",!.costPaid=TRUE, !.heldSourceIds=DOMAIN successors,!.heldIds={successors[id] : id \in DOMAIN successors},!.sourceForfeited=actualPayment.sourceForfeited] PayPaidTrigger95(stack,before,after,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualPayment,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) == /\ PaidProcedureAtTop95(stack,before) /\ WindowTop9(stack).kind # "MidItemInspection" /\ CommitPaidTrigger95(stack,before,after,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualPayment,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) PaidProtectionAlive95(p) == p.costPaid /\ ~p.ability.lastFinished PaidHeldProvenance95(p,objects,transits) == \A id \in p.heldIds \cap DOMAIN objects : objects[id].zone="SetAside" => /\ id \in DOMAIN transits /\ transits[id].protected /\ transits[id].ability=p.id /\ transits[id].effect=p.transaction /\ transits[id].cleanupStage=IF p.sourceForfeited THEN "ProcedureCode76ca53ad9dd0" ELSE "ProcedureCode96bfa1b6a970" PaidHeldObject95(p,objects,transits,object) == /\ object \in p.heldIds \cap DOMAIN objects \cap DOMAIN transits /\ objects[object].zone="SetAside" /\ transits[object].protected /\ transits[object].ability=p.id PaidOwnerCanQuery95(p,objects,transits,object,queryAbility) == /\ PaidProtectionAlive95(p) /\ PaidHeldObject95(p,objects,transits,object) /\ queryAbility=p.id /\ p.phase \in {"Targets","Imminent","Resolve"} /\ SetAsideAbilityCanSee4(transits[object],queryAbility,TRUE,FALSE) /\ IF p.phase="Targets" THEN p.checkpoint \in Nat \ {0} ELSE CostAsideStillHosted4(transits[object],queryAbility,TRUE,AbilityIsResolving9(p.ability)) PaidHeldCounters95(p,objects,transits,kind) == {id \in p.heldIds \cap DOMAIN objects : objects[id].form="Counter" /\ objects[id].kind=kind /\ PaidOwnerCanQuery95(p,objects,transits,id,p.id)} PaidEffectiveHeldCount95(p,objects,transits,kind,actualCounterView,result) == /\ actualCounterView.tag="HeldCounterCount" /\ actualCounterView.abilityInstance=p.id /\ actualCounterView.source=p.ability.source /\ actualCounterView.kind=kind /\ actualCounterView.physicalIds=PaidHeldCounters95(p,objects,transits,kind) /\ actualCounterView.effectiveCount \in Nat /\ result=actualCounterView.effectiveCount /\ actualCounterView.modifierIds={} => result=Cardinality(actualCounterView.physicalIds) PaidAsideExitView95(p,transit,queryAbility,destination) == LET own == queryAbility=p.id /\ p.phase \in {"Targets","Imminent","Resolve"} /\ PaidProtectionAlive95(p) base == SetAsideExitView4(transit,queryAbility,own,FALSE,destination) IN [fromZone |-> base.fromZone,fromLocation |-> base.fromLocation,toZone |-> base.toZone, fromFace |-> IF own THEN "Up" ELSE transit.originFace,wasDeployed |-> transit.originDeployed] PaidCleanupIds95(p,objects,transits,stage) == CostAsideCleanupIds4(transits,objects,IF p.ability.lastFinished THEN {p.id} ELSE {},stage) PaidConvertedAsideIds95(p,objects,transits) == {id \in p.heldIds \cap DOMAIN objects \cap DOMAIN transits : objects[id].zone="SetAside" /\ transits[id].originForm="Counter" /\ objects[id].card # "none"} NormalizePaidConverted95(stack,p,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds,actualNormalization) == LET due == PaidConvertedAsideIds95(p,beforeObjects,beforeTransits) IN /\ p.phase="CostCheckpoint" /\ p.costPaid /\ PaidProcedureAtTop95(stack,p) /\ actualNormalization.tag="PaidCostConversion" /\ actualNormalization.abilityInstance=p.id /\ actualNormalization.transactionId=p.transaction /\ actualNormalization.sources=due /\ actualNormalization.beforeObjects=beforeObjects /\ actualNormalization.afterObjects=afterObjects /\ actualNormalization.complete /\ actualNormalization.normalConversionAndRetireRules /\ FreshSuccessors8(due,successors,usedIds) /\ DOMAIN beforeObjects \subseteq usedIds /\ DOMAIN afterObjects=(DOMAIN beforeObjects \ due) \cup {successors[id] : id \in due} /\ \A id \in DOMAIN beforeObjects \ due : afterObjects[id]=beforeObjects[id] /\ \A id \in due : LET new == successors[id] IN afterObjects[new].form="Card" /\ afterObjects[new].card=beforeObjects[id].card /\ afterObjects[new].zone=actualNormalization.ownerDiscard[id] /\ actualNormalization.ownerDiscard[id] \in {"SideADiscard","SideBDiscard"} /\ ~afterObjects[new].deployed /\ afterObjects[new].host=0 /\ afterTransits=[id \in DOMAIN beforeTransits \ due |-> beforeTransits[id]] PaidCheckpoint95(stack,before,after,objects,transits,actualCheckpoint) == /\ PaidProcedureAtTop95(stack,before) /\ before.phase \in {"CostCheckpoint","InstructionCheckpoint"} /\ actualCheckpoint.tag="PaidCheckpoint" /\ actualCheckpoint.id \in Nat \ {0} /\ actualCheckpoint.abilityInstance=before.id /\ actualCheckpoint.transactionId=before.transaction /\ actualCheckpoint.phase=before.phase /\ actualCheckpoint.source=before.ability.source /\ actualCheckpoint.complete /\ actualCheckpoint.allNewerChainsComplete /\ PaidHeldProvenance95(before,objects,transits) /\ PaidConvertedAsideIds95(before,objects,transits)={} /\ IF before.ability.lastFinished THEN PaidCleanupIds95(before,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(before,objects,transits,"ProcedureCode96bfa1b6a970") = {} ELSE TRUE /\ after=[before EXCEPT !.checkpoint=actualCheckpoint.id, !.phase=IF before.ability.lastFinished THEN "Complete" ELSE "Targets"] EnterPaidInstruction95(stack,before,after,plan,afterPlan,actualTargets,actualEntry) == /\ PaidProcedureAtTop95(stack,before) /\ before.phase="Targets" /\ before.costPaid /\ before.checkpoint \in Nat \ {0} /\ ~plan.announced /\ actualEntry.checkpointId=before.checkpoint /\ LET announced == [plan EXCEPT !.targets=actualTargets.targets,!.announced=TRUE] a == IF before.ability.phase="Ready" THEN [before.ability EXCEPT !.phase="Imminent",!.firstImminent=TRUE] ELSE [before.ability EXCEPT !.cursor=@+1,!.phase="Imminent"] IN /\ AnnounceInstructionTargets93(plan,announced,actualTargets,before.ability,"NoValue") /\ IF before.ability.phase="Ready" THEN EnterFirstAbilityInstruction93(before.ability,a,announced,afterPlan,actualEntry) ELSE EnterNextAbilityInstruction93(before.ability,a,announced,afterPlan,actualEntry) /\ after=[before EXCEPT !.ability=a,!.phase="Imminent",!.checkpoint=0] OpenPaidInstructionInterrupt95(beforeStack,afterStack,p,plan,id,site,instances,opening,usedWindowIds) == /\ PaidProcedureAtTop95(beforeStack,p) /\ p.phase="Imminent" /\ OpenInstructionInterrupt93(beforeStack,afterStack,id,site,instances,opening,usedWindowIds,plan,p.ability,"NoValue") ResolvePaidAfterInterrupt95(beforeStack,afterStack,before,after,plan,afterPlan,actualReturn) == /\ before.phase="Imminent" /\ ReturnInstructionInterrupt93(beforeStack,afterStack,plan,before.ability,"NoValue",actualReturn) /\ PaidProcedureAtTop95(afterStack,before) /\ LET a == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,a,plan,afterPlan,actualReturn) /\ after=[before EXCEPT !.ability=a,!.phase="Resolve"] ResolvePaidWithoutInterrupt95(stack,before,after,plan,afterPlan,actualNoModifiers,actualReturn) == /\ before.phase="Imminent" /\ PaidProcedureAtTop95(stack,before) /\ NoInstructionInterrupt93(plan,before.ability,"NoValue",actualNoModifiers,actualReturn) /\ LET a == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,a,plan,afterPlan,actualReturn) /\ after=[before EXCEPT !.ability=a,!.phase="Resolve"] CarryPaidInstruction95(stack,before,after,plan,afterPlan,actualStep) == /\ before.phase="Resolve" /\ PaidProcedureAtTop95(stack,before) /\ LET a == IF plan.cursor=Len(plan.steps) THEN IF before.ability.cursor=Len(before.ability.instructions) THEN [before.ability EXCEPT !.phase="Complete",!.lastFinished=TRUE,!.complete=TRUE] ELSE [before.ability EXCEPT !.phase="Between"] ELSE before.ability IN /\ CarryAbilityInstructionStep93(before.ability,a,plan,afterPlan,actualStep) /\ after=[before EXCEPT !.ability=a,!.checkpoint=0, !.phase=IF afterPlan.phase="Complete" THEN "InstructionCheckpoint" ELSE "Resolve"] FinishPaidProcedure95(beforeStack,afterStack,before,after,actualReturn) == /\ before.phase="Complete" /\ before.checkpoint \in Nat \ {0} /\ PaidProcedureAtTop95(beforeStack,before) /\ actualReturn.finalCheckpointId=before.checkpoint /\ LET a == [before.ability EXCEPT !.returned=TRUE] IN /\ ReturnAbility9(before.ability,a,TRUE,before.windowId) /\ CompletePriorityOption9(beforeStack,afterStack,actualReturn) /\ after=[before EXCEPT !.ability=a,!.phase="Returned"] PayPaidMidItemInspection95(stack,before,after,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds, actualPayment,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034,beginDrain,itemInspectionEvents) == /\ PaidProcedureAtTop95(stack,before) /\ WindowTop9(stack).kind="MidItemInspection" /\ WindowTop9(stack).site.structure=TimingRef9("ItemInspection",a.id) /\ before.option.target=a.object /\ before.option.ability=midOption.id /\ beginDrain.tag="MidItemInspectionBeginDrained" /\ beginDrain.itemInspectionId=a.id /\ beginDrain.windowId=before.windowId /\ beginDrain.checkpointId=before.initialCheckpoint /\ beginDrain.checkpointId \in Nat \ {0} /\ beginDrain.complete /\ CommitPaidTrigger95(stack,before,after,beforeObjects,afterObjects,beforeTransits,afterTransits,successors,usedIds, actualPayment,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) /\ LET used == [a EXCEPT !.midUsed=TRUE,!.midResolving=TRUE] IN /\ UseMidItemInspection7(a,used,beforeObjects,midOption,options,mustRetire,exampleFamily034,actualPayment.allPaid,beginDrain.complete) /\ ItemInspectionMovementOutcome7(used,afterItemInspection,afterObjects,TRUE,itemInspectionEvents) FinishPaidMidItemInspection95(beforeStack,afterStack,before,after,actualReturn,a,afterItemInspection) == /\ before.phase="Complete" /\ before.checkpoint \in Nat \ {0} /\ PaidProcedureAtTop95(beforeStack,before) /\ actualReturn.finalCheckpointId=before.checkpoint /\ LET resolved == [before.ability EXCEPT !.returned=TRUE] IN /\ ReturnAbility9(before.ability,resolved,TRUE,before.windowId) /\ CompleteMidItemInspectionOption9(beforeStack,afterStack,actualReturn,a,afterItemInspection) /\ after=[before EXCEPT !.ability=resolved,!.phase="Returned"] PaidHeldInteraction95(p,objects,transits,object,queryAbility) == IF PaidHeldObject95(p,objects,transits,object) THEN PaidOwnerCanQuery95(p,objects,transits,object,queryAbility) ELSE TRUE CleanupPaidHeld95(p,beforeObjects,afterObjects,beforeTransits,afterTransits,stage,successors,usedIds,actualCleanup) == LET due == PaidCleanupIds95(p,beforeObjects,beforeTransits,stage) counters == {id \in due : BankPhysicalToken4(beforeObjects[id])} cards == due \ counters IN /\ p.phase="InstructionCheckpoint" /\ p.ability.lastFinished /\ stage \in {"ProcedureCode76ca53ad9dd0","ProcedureCode96bfa1b6a970"} /\ actualCleanup.tag="PaidHostedCleanup" /\ actualCleanup.abilityInstance=p.id /\ actualCleanup.transactionId=p.transaction /\ actualCleanup.stage=stage /\ actualCleanup.sources=due /\ actualCleanup.beforeObjects=beforeObjects /\ actualCleanup.afterObjects=afterObjects /\ actualCleanup.complete /\ actualCleanup.normalRetireAndCounterRules /\ FreshSuccessors8(cards,successors,usedIds) /\ DOMAIN beforeObjects \subseteq usedIds /\ DOMAIN afterObjects=(DOMAIN beforeObjects \ due) \cup {successors[id] : id \in cards} /\ \A id \in DOMAIN beforeObjects \ due : afterObjects[id]=beforeObjects[id] /\ \A id \in cards : LET new == successors[id] IN afterObjects[new].card=beforeObjects[id].card /\ afterObjects[new].zone=actualCleanup.ownerDiscard[id] /\ actualCleanup.ownerDiscard[id] \in {"SideBDiscard","SideADiscard"} /\ afterObjects[new].host=0 /\ ~afterObjects[new].deployed /\ afterTransits=[id \in DOMAIN beforeTransits \ due |-> beforeTransits[id]] Specimen0090ResourceUnits95(effectiveClusterCount) == 2*effectiveClusterCount ExampleFamily040Deploy95(p,plan,beforeObjects,afterObjects,transits,old,new,actualDeploy) == /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ plan.phase="Resolving" /\ old \in plan.targets /\ p.definition.syntax.source.kind="Object" /\ p.phase="Resolve" /\ PaidOwnerCanQuery95(p,beforeObjects,transits,old,p.id) /\ beforeObjects[old].form="Card" /\ old \notin DOMAIN afterObjects /\ new \in DOMAIN afterObjects /\ afterObjects[new].card=beforeObjects[old].card /\ actualDeploy.tag="ExampleFamily040Deploy" /\ actualDeploy.abilityInstance=p.id /\ actualDeploy.old=old /\ actualDeploy.new=new /\ actualDeploy.discount=1 /\ actualDeploy.deployProcedureComplete /\ SideBPaidDeployPost(afterObjects[new],"SideB",afterObjects[new].kind,actualDeploy.allDeployCostsPaid,actualDeploy.allowed) ExampleFamily048Move95(p,plan,objects,transits,selected,target,actualProgressEligible) == /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ plan.phase="Resolving" /\ target \in plan.targets /\ p.phase="Resolve" /\ selected \subseteq PaidHeldCounters95(p,objects,transits,"Progress") /\ target \in DOMAIN objects /\ actualProgressEligible.tag="ProgressEligibleTarget" /\ actualProgressEligible.abilityInstance=p.id /\ actualProgressEligible.target=target /\ actualProgressEligible.allowed ConditionalKey96(d) == [ability |-> d.syntax.id,source |-> d.syntax.source] ConditionalInterrupt96(d) == AbilityIsInterrupt9(FlagPresent93(d.syntax.units,"Interrupt"),d.instructionHasWould) ConditionalWindowKind96(d) == IF ConditionalInterrupt96(d) THEN "Interrupt" ELSE "Reaction" ConditionalEventKinds96(d) == d.trigger.kinds ConditionalActorMatches96(d,actor) == d.trigger.actor="SchemaAtom016" \/ actor=(IF d.trigger.actor="Controller" THEN d.syntax.controller ELSE d.trigger.actor) ConditionalClasses96(d) == (IF "EncounterBarrier" \in ConditionalEventKinds96(d) /\ d.trigger.subject="SchemaAtom149" /\ ConditionalActorMatches96(d,"SideB") THEN {"WhenEncountered"} ELSE {}) \cup (IF "Deployed" \in ConditionalEventKinds96(d) /\ d.trigger.subject="SchemaAtom149" /\ \E p \in SetupPlayers : ConditionalActorMatches96(d,p) THEN {"WhenDeployed"} ELSE {}) \cup (IF "ObjectivePlacementd" \in ConditionalEventKinds96(d) /\ d.trigger.subject="SchemaAtom149" /\ d.syntax.cardKind="Objective" /\ ConditionalActorMatches96(d,"SideA") THEN {"WhenScored"} ELSE {}) ConditionalOptional96(d) == {} \in d.effectChoices \/ FlagPresent93(d.syntax.units,"OncePerTurn") ConditionalDefinitionValid96(d) == /\ d.syntax.kind="Conditional" /\ d.activity.kind="Conditional" /\ d.syntax.id \in Nat \ {0} /\ d.syntax.source.kind \in {"Object","Rule"} /\ IF d.syntax.source.kind="Object" THEN d.syntax.source.object \in Nat \ {0} ELSE d.syntax.source.rule # "NoValue" /\ d.activity.id=d.syntax.id /\ d.activity.source=d.syntax.source /\ AbilityTextValid93(d.syntax) /\ IF d.activity.provider="Lingering" THEN d.delayedEffect \in Nat \ {0} ELSE d.delayedEffect=0 /\ d.primaryKind \in {"Trigger","Static"} /\ Len(d.instructions)>0 /\ d.primaryKind="Trigger" => ConditionalEventKinds96(d) # {} /\ \E i \in 1..Len(d.syntax.units) : d.syntax.units[i].primary /\ d.syntax.units[i].subtype=d.primaryKind /\ d.effectChoices # {} /\ d.optionalParts \subseteq UNION d.effectChoices /\ DOMAIN d.partsByInstruction=SubIds6(d.instructions) /\ UNION {d.partsByInstruction[id] : id \in DOMAIN d.partsByInstruction}=UNION d.effectChoices ConditionalActivityContext96(d,snapshot) == [snapshot.activity EXCEPT !.departureHolds=IF ConditionalKey96(d) \in DOMAIN snapshot.holds THEN [id \in {d.syntax.id} |-> snapshot.holds[ConditionalKey96(d)]] ELSE [id \in {} |-> id], !.lingeringAbilities=@ \cup {snapshot.effects[id].definition.syntax.id : id \in DOMAIN snapshot.effects}] ConditionalActive96(d,snapshot) == /\ d.delayedEffect=0 \/ (d.delayedEffect \in DOMAIN snapshot.effects /\ snapshot.effects[d.delayedEffect].definition=d) /\ FlagActivity93(d.syntax,snapshot.present, AbilityActive9(d.activity,snapshot.objects,snapshot.present,snapshot.ordinaryActivity[ConditionalKey96(d)],ConditionalActivityContext96(d,snapshot)), snapshot.activity.persistentAbilities,snapshot.points) ConditionalLiveInstance96(i) == i.status \in {"Pending","Imminent","Resolving"} ConditionalSibling96(d,instances) == \E id \in DOMAIN instances : instances[id].member.ability=d.syntax.id /\ instances[id].member.source=d.syntax.source /\ ConditionalLiveInstance96(instances[id]) TriggerPattern96(d,event) == /\ event.kind \in ConditionalEventKinds96(d) /\ event.scopeKind="Global" \/ (event.scopeKind="Ability" /\ event.scopeDefinition=ConditionalKey96(d)) /\ d.trigger.subject="SchemaAtom016" \/ (d.trigger.subject="SchemaAtom149" /\ event.object=d.syntax.source.object) /\ ConditionalActorMatches96(d,event.actor) /\ d.trigger.side="SchemaAtom016" \/ event.side=d.trigger.side TriggerStipulations96(d,event,actualCondition) == /\ actualCondition.tag="ConditionalTriggerStipulations" /\ actualCondition.ability=d.syntax.id /\ actualCondition.source=d.syntax.source /\ actualCondition.occurrence=event.id /\ actualCondition.snapshotId=event.snapshot.id /\ DOMAIN actualCondition.results=d.triggerRequirements /\ \A id \in DOMAIN actualCondition.results : actualCondition.results[id] StaticPrimaryTruth96(d,cp,actualCondition) == /\ actualCondition.tag="ConditionalStaticTruth" /\ actualCondition.ability=d.syntax.id /\ actualCondition.source=d.syntax.source /\ actualCondition.checkpointId=cp.id /\ actualCondition.snapshotId=cp.beginSnapshot.id /\ actualCondition.condition=d.primaryCondition /\ actualCondition.holds StaticRetryAllowed96(d,ledger) == ConditionalKey96(d) \notin DOMAIN ledger.throttle \/ ledger.throttle[ConditionalKey96(d)] < ledger.stepSerial ConditionalActivityRows96(instances) == [id \in DOMAIN instances |-> [ability |-> instances[id].member.ability, sourceObject |-> instances[id].member.source.object,status |-> instances[id].status]] SnapshotWithConditionalRegistry96(snapshot,ledger) == [snapshot EXCEPT !.holds=ledger.holds,!.effects=ledger.effects,!.activity.instances=ConditionalActivityRows96(ledger.instances)] ConditionalRegistrySnapshotBound96(snapshot,ledger) == snapshot.holds=ledger.holds /\ snapshot.effects=ledger.effects /\ snapshot.activity.instances=ConditionalActivityRows96(ledger.instances) ConditionalEpochMap96(ledger,definitions) == [key \in DOMAIN ledger.activationEpoch \cup DOMAIN definitions |-> IF key \in DOMAIN ledger.activationEpoch THEN ledger.activationEpoch[key] ELSE 0] ConditionalSnapshotBound96(snapshot,ledger) == /\ ConditionalRegistrySnapshotBound96(snapshot,ledger) /\ snapshot.activationEpoch=ConditionalEpochMap96(ledger,snapshot.definitions) /\ snapshot.activationSerial=ledger.activationSerial ConditionalDefinitionsStable96(beforeSnapshot,afterSnapshot) == \A key \in DOMAIN beforeSnapshot.definitions \cap DOMAIN afterSnapshot.definitions : beforeSnapshot.definitions[key]=afterSnapshot.definitions[key] ConditionalActivityLosses96(beforeSnapshot,afterSnapshot) == {key \in DOMAIN beforeSnapshot.definitions : ConditionalActive96(beforeSnapshot.definitions[key],beforeSnapshot) /\ (IF key \in DOMAIN afterSnapshot.definitions THEN ~ConditionalActive96(afterSnapshot.definitions[key],afterSnapshot) ELSE TRUE)} ConditionalInstanceCurrent96(instance,definitions,snapshot) == IF instance.definition \notin DOMAIN definitions THEN FALSE ELSE instance.definitionCopy=definitions[instance.definition] /\ ConditionalActive96(definitions[instance.definition],snapshot) /\ instance.activationEpoch=snapshot.activationEpoch[instance.definition] ConditionalActivityLedger96(before,definitions,snapshot) == [before EXCEPT !.instances=[id \in DOMAIN @ |-> IF @[id].status="Pending" /\ ~ConditionalInstanceCurrent96(@[id],definitions,snapshot) THEN [@[id] EXCEPT !.status="Lost"] ELSE @[id]]] SyncConditionalWindows96(before,after,beforeLedger,afterLedger) == after=[i \in 1..Len(before) |-> LET lost == {id \in before[i].pending \cap DOMAIN beforeLedger.instances : afterLedger.instances[id].status # "Pending"} IN [before[i] EXCEPT !.pending=@ \ lost,!.lostPending=@ \cup lost]] SyncConditionalActivity96(before,after,beforeStack,afterStack,definitions,snapshot) == /\ ConditionalSnapshotBound96(snapshot,before) /\ definitions=snapshot.definitions /\ after=ConditionalActivityLedger96(before,definitions,snapshot) /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) ObserveConditionalActivity96(before,candidate,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) == /\ ConditionalSnapshotBound96(beforeSnapshot,before) /\ ConditionalRegistrySnapshotBound96(afterSnapshot,candidate) /\ ConditionalDefinitionsStable96(beforeSnapshot,afterSnapshot) /\ \A effect \in DOMAIN before.effects \cap DOMAIN candidate.effects : before.effects[effect]=candidate.effects[effect] /\ LET lost == ConditionalActivityLosses96(beforeSnapshot,afterSnapshot) keys == DOMAIN before.activationEpoch \cup DOMAIN beforeSnapshot.definitions \cup DOMAIN afterSnapshot.definitions epochs == [key \in keys |-> (IF key \in DOMAIN before.activationEpoch THEN before.activationEpoch[key] ELSE 0)+(IF key \in lost THEN 1 ELSE 0)] serial == before.activationSerial+(IF lost={} THEN 0 ELSE 1) observed == [candidate EXCEPT !.activationEpoch=epochs,!.activationSerial=serial] IN /\ afterSnapshot.activationEpoch=epochs /\ afterSnapshot.activationSerial=serial /\ after=ConditionalActivityLedger96(observed,afterSnapshot.definitions,afterSnapshot) /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) DelayedConditionalEventScope96(d,ledger,event) == IF d.delayedEffect=0 THEN TRUE ELSE IF d.delayedEffect \notin DOMAIN ledger.effects THEN FALSE ELSE LET effect == ledger.effects[d.delayedEffect] IN IF effect.association="IfSuccessfulInspection" /\ event.kind="Inspection" THEN /\ event.kind="Inspection" /\ event.step="ProcedureCoded75d879e00ff" /\ event.traversal.id=effect.traversalId /\ TraversalInspectionModifierApplies6([traversalId |-> effect.traversalId],event.traversal,event.siteInspection) ELSE effect.triggerStructure=NoTimingRef9 \/ event.structure=effect.triggerStructure ReboundConditionalDefinition96(original,newObject) == [original EXCEPT !.syntax.source=ObjectAbilitySource9(newObject),!.activity.source=ObjectAbilitySource9(newObject)] DepartureMatchedEvents96(d,cp,conditions,departure) == {id \in DOMAIN cp.occurrences : cp.occurrences[id].effectId=departure.effectId /\ TriggerPattern96(departure.originalDefinition,cp.occurrences[id]) /\ TriggerStipulations96(departure.originalDefinition,cp.occurrences[id],conditions[id])} DepartureCurrentGate96(d,cp) == /\ ConditionalDefinitionValid96(d) /\ ~ConditionalInterrupt96(d) /\ d.primaryKind="Trigger" /\ d.syntax.source.kind="Object" /\ d.syntax.source.object \in DOMAIN cp.processingSnapshot.objects /\ ~SideBFacedown8(cp.processingSnapshot.objects[d.syntax.source.object]) /\ FlagActivity93(d.syntax,cp.processingSnapshot.present,TRUE,cp.processingSnapshot.activity.persistentAbilities,cp.processingSnapshot.points) DepartureCandidates96(definitions,cp,conditions,departures) == UNION {IF key \in DOMAIN definitions /\ DepartureCurrentGate96(definitions[key],cp) THEN {[definition |-> key,occurrence |-> id] : id \in DepartureMatchedEvents96(definitions[key],cp,conditions[key],departures[key])} ELSE {} : key \in DOMAIN departures} DepartureAuthority96(d,cp,conditions,allocation,departure,hold) == LET matched == DepartureMatchedEvents96(d,cp,conditions,departure) ids == {allocation[[definition |-> ConditionalKey96(d),occurrence |-> event]] : event \in matched} old == departure.oldObject new == departure.newObject IN /\ departure.tag="ConditionalDepartureRecognition" /\ departure.checkpointId=cp.id /\ d=ReboundConditionalDefinition96(departure.originalDefinition,new) /\ departure.originalDefinition.syntax.source=ObjectAbilitySource9(old) /\ ConditionalDefinitionValid96(departure.originalDefinition) /\ departure.originalDefinition.activity.provider \in {"Printed","Granted"} /\ ConditionalKey96(departure.originalDefinition) \in DOMAIN departure.beforeSnapshot.definitions /\ departure.beforeSnapshot.definitions[ConditionalKey96(departure.originalDefinition)]=departure.originalDefinition /\ matched # {} /\ \E event \in matched : cp.occurrences[event].object=old /\ cp.occurrences[event].movement.tag="SourceZoneChange" /\ cp.occurrences[event].movement.oldObject=old /\ cp.occurrences[event].movement.newObject=new /\ cp.occurrences[event].movement.beforeSnapshot=departure.beforeSnapshot /\ departure.holdReceipt.matchingOccurrences=matched /\ departure.holdReceipt.effectId=departure.effectId /\ old \in DOMAIN departure.beforeSnapshot.objects /\ new \in DOMAIN cp.processingSnapshot.objects /\ old \notin DOMAIN cp.processingSnapshot.objects /\ DOMAIN departure.beforeSnapshot.objects \subseteq departure.beforeSnapshot.usedObjects /\ FreshSuccessors8({old},[id \in {old} |-> new],departure.beforeSnapshot.usedObjects) /\ OpenDepartureHold9(departure.beforeSnapshot.objects,cp.processingSnapshot.objects,old,new,d.syntax.id,ids, departure.holdReceipt,departure.beforeSnapshot.cardActivity[old],cp.processingSnapshot.cardActivity[new],hold) CheckpointCandidates96(definitions,ledger,cp,conditions) == UNION {IF ~ConditionalDefinitionValid96(definitions[key]) \/ ConditionalInterrupt96(definitions[key]) \/ ~ConditionalActive96(definitions[key],cp.processingSnapshot) THEN {} ELSE IF definitions[key].primaryKind="Trigger" THEN {[definition |-> key,occurrence |-> event] : event \in {id \in DOMAIN cp.occurrences : TriggerPattern96(definitions[key],cp.occurrences[id]) /\ DelayedConditionalEventScope96(definitions[key],ledger,cp.occurrences[id]) /\ TriggerStipulations96(definitions[key],cp.occurrences[id],conditions[key][id])}} ELSE IF StaticPrimaryTruth96(definitions[key],cp,conditions[key][0]) /\ ~ConditionalSibling96(definitions[key],ledger.instances) /\ StaticRetryAllowed96(definitions[key],ledger) THEN {[definition |-> key,occurrence |-> 0]} ELSE {} : key \in DOMAIN definitions} NewConditionalLedger96(initialSnapshot) == [lastCheckpoint |-> 0,checkpointIds |-> {},checkpoints |-> [id \in {} |-> id],serial |-> 0,lastSnapshot |-> initialSnapshot,processed |-> {},instances |-> [id \in {} |-> id], throttle |-> [key \in {} |-> key],stepSerial |-> 0,activationEpoch |-> initialSnapshot.activationEpoch,activationSerial |-> initialSnapshot.activationSerial,interruptRecognitions |-> {},usedDelayedEffects |-> {},usedDelayedDefinitions |-> {},effects |-> [id \in {} |-> id],holds |-> [key \in {} |-> key]] ConditionalMember96(id,d,windowId,group) == ConditionalInstance9(id,d.syntax.id,d.syntax.source,d.syntax.controller,~ConditionalOptional96(d),group,windowId,ConditionalInterrupt96(d)) NewConditionalInstance96(id,d,cp,eventId,windowId,group) == [member |-> ConditionalMember96(id,d,windowId,group),definition |-> ConditionalKey96(d),definitionCopy |-> d,status |-> "Pending", primaryKind |-> d.primaryKind,activationEpoch |-> cp.processingSnapshot.activationEpoch[ConditionalKey96(d)], checkpointId |-> cp.id,occurrence |-> eventId,hadSnapshot |-> cp.previousSnapshot, expected |-> [index \in {} |-> index],used |-> FALSE] CheckpointBatchValid96(before,cp,candidates,allocation,bindings) == /\ cp.tag="ConditionalCheckpoint" /\ cp.point="ProcedureCodee605a78f5d5e" /\ cp.id \in (Nat \ {0}) \ before.checkpointIds /\ cp.previousCheckpoint=before.lastCheckpoint /\ cp.serial=before.serial+1 /\ cp.previousSnapshot=before.lastSnapshot /\ cp.processingSnapshot.point="ProcedureCodee605a78f5d5e" /\ cp.processingSnapshot.checkpointId=cp.id /\ cp.beginSnapshot.checkpointId=cp.id /\ cp.beginSnapshot.point="CheckpointBeginning" /\ cp.stepSerial=before.stepSerial /\ DOMAIN cp.occurrences \cap before.processed={} /\ \A id \in DOMAIN cp.occurrences : cp.occurrences[id].id=id /\ id \in Nat \ {0} /\ DOMAIN allocation=candidates /\ DOMAIN bindings=candidates /\ {allocation[key] : key \in candidates} \subseteq (Nat \ {0}) \ DOMAIN before.instances /\ Cardinality({allocation[key] : key \in candidates})=Cardinality(candidates) /\ Cardinality({bindings[key] : key \in candidates})<=1 /\ \A key \in candidates : bindings[key].kind="Reaction" /\ bindings[key].windowId \in Nat \ {0} /\ bindings[key].group \in Nat \ {0} /\ bindings[key].checkpointId=cp.id ProcessConditionalCheckpointCore96(before,after,definitions,cp,conditions,allocation,bindings,departures,holds) == LET stable == ConditionalActivityLedger96(before,definitions,cp.processingSnapshot) candidates == CheckpointCandidates96(definitions,stable,cp,conditions) \cup DepartureCandidates96(definitions,cp,conditions,departures) departureKeys == {key.definition : key \in DepartureCandidates96(definitions,cp,conditions,departures)} ids == {allocation[key] : key \in candidates} IN /\ definitions=cp.processingSnapshot.definitions /\ ConditionalDefinitionsStable96(before.lastSnapshot,cp.processingSnapshot) /\ \A key \in DOMAIN definitions : key=ConditionalKey96(definitions[key]) /\ ConditionalDefinitionValid96(definitions[key]) /\ ConditionalSnapshotBound96(cp.processingSnapshot,before) /\ CheckpointBatchValid96(before,cp,candidates,allocation,bindings) /\ DOMAIN holds=departureKeys /\ \A key \in departureKeys : DepartureAuthority96(definitions[key],cp,conditions[key],allocation,departures[key],holds[key]) /\ after=[stable EXCEPT !.activationEpoch=cp.processingSnapshot.activationEpoch,!.holds=[key \in DOMAIN @ \cup departureKeys |-> IF key \in departureKeys THEN holds[key] ELSE @[key]],!.lastCheckpoint=cp.id,!.checkpointIds=@ \cup {cp.id}, !.checkpoints=[id \in DOMAIN @ \cup {cp.id} |-> IF id=cp.id THEN [caller |-> cp.caller] ELSE @[id]],!.serial=cp.serial,!.lastSnapshot=cp.processingSnapshot, !.processed=@ \cup DOMAIN cp.occurrences, !.instances=[id \in DOMAIN @ \cup ids |-> IF id \in ids THEN LET key == CHOOSE k \in candidates : allocation[k]=id d == definitions[key.definition] IN NewConditionalInstance96(id,d,cp,key.occurrence,bindings[key].windowId,bindings[key].group) ELSE @[id]]] /\ \A key \in departureKeys : ConditionalActive96(definitions[key],SnapshotWithConditionalRegistry96(cp.processingSnapshot,after)) ProcessConditionalCheckpoint96(before,after,beforeStack,afterStack,definitions,cp,conditions,allocation,bindings,departures,holds,usedWindowIds) == /\ ProcessConditionalCheckpointCore96(before,after,definitions,cp,conditions,allocation,bindings,departures,holds) /\ \A key \in DOMAIN bindings : bindings[key].windowId \notin usedWindowIds \cup {beforeStack[i].id : i \in 1..Len(beforeStack)} /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) ConditionalWindowMembers96(instances,windowId) == [id \in {i \in DOMAIN instances : instances[i].member.windowId=windowId /\ instances[i].status="Pending"} |-> instances[id].member] OpenConditionalReaction96(before,after,ledger,windowId,site,opening,usedWindows) == LET members == ConditionalWindowMembers96(ledger.instances,windowId) IN /\ DOMAIN members # {} /\ OpenPriorityWindow9(before,after,windowId,"Reaction",site,members,opening,usedWindows) CreateConditionalInterrupt96(before,after,id,d,plan,parent,ruleStep,snapshot,prepared,windowId,group,usedWindowIds) == /\ ConditionalSnapshotBound96(snapshot,before) /\ ConditionalKey96(d) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(d)]=d /\ windowId \notin usedWindowIds /\ ConditionalDefinitionValid96(d) /\ ConditionalInterrupt96(d) /\ ConditionalActive96(d,snapshot) /\ InstructionImminentAtOrigin93(plan,parent,ruleStep) /\ id \in (Nat \ {0}) \ DOMAIN before.instances /\ prepared.tag="ConditionalInterruptMatch" /\ prepared.instruction=InstructionWindowRef93(plan) /\ prepared.ability=d.syntax.id /\ prepared.source=d.syntax.source /\ prepared.snapshotId=snapshot.id /\ prepared.matches /\ prepared.occurrence \in Nat \ {0} /\ [definition |-> ConditionalKey96(d),occurrence |-> prepared.occurrence] \notin before.interruptRecognitions /\ windowId \in Nat \ {0} /\ group \in Nat \ {0} /\ IF d.primaryKind="Static" THEN ~ConditionalSibling96(d,before.instances) /\ StaticRetryAllowed96(d,before) ELSE TRUE /\ LET instance == [member |-> ConditionalMember96(id,d,windowId,group),definition |-> ConditionalKey96(d),definitionCopy |-> d,status |-> "Pending", primaryKind |-> d.primaryKind,activationEpoch |-> snapshot.activationEpoch[ConditionalKey96(d)], checkpointId |-> before.lastCheckpoint,occurrence |-> prepared.occurrence, hadSnapshot |-> before.lastSnapshot,expected |-> [i \in {} |-> i],used |-> FALSE] IN after=[before EXCEPT !.activationEpoch=snapshot.activationEpoch, !.interruptRecognitions=@ \cup {[definition |-> ConditionalKey96(d),occurrence |-> prepared.occurrence]}, !.instances=[i \in DOMAIN @ \cup {id} |-> IF i=id THEN instance ELSE @[i]]] HadProgressZero96(instance,object) == IF object \in DOMAIN instance.hadSnapshot.progress THEN instance.hadSnapshot.progress[object]=0 ELSE TRUE InstructionLinkGate96(currentSnapshot,player) == currentSnapshot.link[player]>=2 OpenConditionalProcedure96(id,d,w,option,transaction,sourceZone) == [id |-> id,definition |-> d,windowId |-> w.id,option |-> option,transaction |-> transaction,turnId |-> w.site.turnId, ability |-> OpenAbilityResolution9(id,"Conditional",d.syntax.source,sourceZone,d.instructions,w.id), phase |-> "Targets",checkpoint |-> 0] ConditionalAtTop96(stack,p) == PaidProcedureAtTop95(stack,p) ConditionalUseOptionalParts96(d) == IF ConditionalOptional96(d) THEN UNION d.effectChoices ELSE d.optionalParts ConditionalProcedureBound96(ledger,p) == /\ p.id \in DOMAIN ledger.instances /\ LET instance == ledger.instances[p.id] IN /\ instance.definition=ConditionalKey96(p.definition) /\ instance.definitionCopy=p.definition /\ p.ability.id=p.id /\ p.ability.kind="Conditional" /\ p.ability.source=instance.member.source /\ p.ability.instructions=p.definition.instructions /\ p.ability.caller=p.windowId /\ p.windowId=instance.member.windowId /\ p.option.instance=p.id /\ p.option.ability=instance.member.ability /\ p.option.source=instance.member.source /\ p.option.controller=instance.member.controller /\ p.transaction \in Nat \ {0} BeginConditionalResolution96(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,d,snapshot,id,option,legality,currentEffect,plan,afterPlan,targets,entry,turnUses,restrictions) == /\ ConditionalSnapshotBound96(snapshot,beforeLedger) /\ ConditionalDefinitionValid96(d) /\ id \in DOMAIN beforeLedger.instances /\ beforeLedger.instances[id].status="Pending" /\ beforeLedger.instances[id].definition=ConditionalKey96(d) /\ ConditionalKey96(d) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(d)]=d /\ beforeLedger.instances[id].definitionCopy=d /\ ConditionalInstanceCurrent96(beforeLedger.instances[id],[key \in {ConditionalKey96(d)} |-> d],snapshot) /\ Len(beforeStack)>0 /\ WindowTop9(beforeStack).kind=ConditionalWindowKind96(d) /\ id \in DOMAIN WindowTop9(beforeStack).members /\ WindowTop9(beforeStack).members[id]=beforeLedger.instances[id].member /\ option.instance=id /\ option.ability=d.syntax.id /\ option.source=d.syntax.source /\ option.kind=IF ConditionalInterrupt96(d) THEN "ConditionalInterrupt" ELSE "Conditional" /\ WholeAbilityRestrictionGate93(d.syntax,restrictions) /\ OncePerTurnAllowed93(d.syntax,WindowTop9(beforeStack).site.turnId,turnUses) /\ BeginPriorityOption9(beforeStack,afterStack,option,snapshot.objects,legality,currentEffect) /\ p=OpenConditionalProcedure96(id,d,WindowTop9(beforeStack),option,legality.transactionId, IF d.syntax.source.kind="Rule" THEN "Rule" ELSE IF d.syntax.source.object \in DOMAIN snapshot.objects THEN snapshot.objects[d.syntax.source.object].zone ELSE "NoValue") /\ ~plan.announced /\ entry.sourceEligible=ConditionalActive96(d,snapshot) /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [p.ability EXCEPT !.phase="Imminent",!.firstImminent=TRUE,!.detached=TRUE] IN /\ AnnounceInstructionTargets93(plan,announced,targets,p.ability,"NoValue") /\ EnterFirstAbilityInstruction93(p.ability,imminent,announced,afterPlan,entry) /\ afterP=[p EXCEPT !.ability=imminent,!.phase="Imminent"] /\ afterLedger=[beforeLedger EXCEPT !.instances[id].status="Imminent"] /\ ConditionalProcedureBound96(afterLedger,afterP) ObserveConditionalExpected96(before,after,p,plan,actualExpected) == /\ ConditionalProcedureBound96(before,p) /\ p.phase="Imminent" /\ InstructionImminentAtOrigin93(plan,p.ability,"NoValue") /\ p.id \in DOMAIN before.instances /\ before.instances[p.id].status="Imminent" /\ plan.index \notin DOMAIN before.instances[p.id].expected /\ actualExpected.tag="ConditionalExpectedEffects" /\ actualExpected.point="ExpectedEffectsBeforeInterrupt" /\ actualExpected.instruction=InstructionWindowRef93(plan) /\ after=[before EXCEPT !.instances[p.id].expected=[i \in DOMAIN @ \cup {plan.index} |-> IF i=plan.index THEN [instruction |-> InstructionWindowRef93(plan),effects |-> actualExpected.effects] ELSE @[i]]] OpenConditionalInstructionInterrupt96(beforeLedger,afterLedger,beforeStack,afterStack,p,plan,id,site,instances,opening,usedWindowIds,actualExpected) == /\ ConditionalAtTop96(beforeStack,p) /\ ObserveConditionalExpected96(beforeLedger,afterLedger,p,plan,actualExpected) /\ OpenInstructionInterrupt93(beforeStack,afterStack,id,site,instances,opening,usedWindowIds,plan,p.ability,"NoValue") ResolveConditionalAfterInterrupt96(beforeLedger,afterLedger,beforeStack,afterStack,beforeP,afterP,plan,afterPlan,clearance) == /\ ConditionalProcedureBound96(beforeLedger,beforeP) /\ beforeLedger.instances[beforeP.id].status="Imminent" /\ beforeP.phase="Imminent" /\ plan.index \in DOMAIN beforeLedger.instances[beforeP.id].expected /\ clearance.openingRevision=beforeLedger.instances[beforeP.id].expected[plan.index].instruction.revision /\ ReturnInstructionInterrupt93(beforeStack,afterStack,plan,beforeP.ability,"NoValue",clearance) /\ ConditionalAtTop96(afterStack,beforeP) /\ LET resolving == [beforeP.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(beforeP.ability,resolving,plan,afterPlan,clearance) /\ afterP=[beforeP EXCEPT !.ability=resolving,!.phase="Resolve"] /\ afterLedger=[beforeLedger EXCEPT !.instances[beforeP.id].status="Resolving"] ResolveConditionalWithoutInterrupt96(beforeLedger,afterLedger,stack,beforeP,afterP,plan,afterPlan,noModifiers,clearance,actualExpected) == /\ ConditionalAtTop96(stack,beforeP) /\ LET observed == [beforeLedger EXCEPT !.instances[beforeP.id].expected=[i \in DOMAIN @ \cup {plan.index} |-> IF i=plan.index THEN [instruction |-> InstructionWindowRef93(plan),effects |-> actualExpected.effects] ELSE @[i]]] resolving == [beforeP.ability EXCEPT !.phase="Resolving"] IN /\ ObserveConditionalExpected96(beforeLedger,observed,beforeP,plan,actualExpected) /\ NoInstructionInterrupt93(plan,beforeP.ability,"NoValue",noModifiers,clearance) /\ BeginAbilityInstructionAtomic93(beforeP.ability,resolving,plan,afterPlan,clearance) /\ afterP=[beforeP EXCEPT !.ability=resolving,!.phase="Resolve"] /\ afterLedger=[observed EXCEPT !.instances[beforeP.id].status="Resolving"] RecordConditionalExecutionUse96(before,after,p,plan,actualExecution,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) == /\ ConditionalProcedureBound96(before,p) /\ p.phase="Resolve" /\ p.id \in DOMAIN before.instances /\ before.instances[p.id].status="Resolving" /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ plan.phase="Resolving" /\ actualExecution.tag="ConditionalEffectExecution" /\ actualExecution.instruction=InstructionWindowRef93(plan) /\ actualExecution.abilityInstance=p.id /\ actualExecution.source=p.ability.source /\ actualExecution.partIds \subseteq p.definition.partsByInstruction[plan.id] /\ LET optional == actualExecution.partIds \cap ConditionalUseOptionalParts96(p.definition) first == optional # {} /\ ~before.instances[p.id].used used == [tag |-> "AbilityUsed",useId |-> useId,abilityInstance |-> p.id,source |-> p.ability.source,player |-> p.definition.syntax.controller] IN IF first THEN /\ OncePerTurnAllowed93(p.definition.syntax,p.turnId,beforeTurnUses) /\ AbilityUseDue9("Conditional",ConditionalUseOptionalParts96(p.definition)={},FALSE,TRUE,FALSE) /\ RecordAbilityUse9(beforeUses,afterUses,useId,p.id,p.ability.source,p.definition.syntax.controller,TRUE,{used}) /\ RecordTurnAbilityUse93(beforeTurnUses,afterTurnUses,p.definition.syntax,p.turnId, [id |-> p.id,ability |-> p.definition.syntax.id,source |-> p.ability.source],used) /\ after=[before EXCEPT !.instances[p.id].used=TRUE] /\ events={used} ELSE after=before /\ afterUses=beforeUses /\ afterTurnUses=beforeTurnUses /\ events={} LoseConditionalPendingKeys96(instances,keys) == [id \in DOMAIN instances |-> IF instances[id].status="Pending" /\ instances[id].definition \in keys THEN [instances[id] EXCEPT !.status="Lost"] ELSE instances[id]] ConditionalExpectedEmpty96(instance,instructions) == DOMAIN instance.expected=1..Len(instructions) /\ \A i \in DOMAIN instance.expected : instance.expected[i].effects={} EffectsAfterConditionalResolution96(effects,d) == IF d.delayedEffect=0 THEN effects ELSE IF d.delayedEffect \in DOMAIN effects /\ effects[d.delayedEffect].definition=d /\ effects[d.delayedEffect].policy="UntilResolution" THEN [id \in DOMAIN effects \ {d.delayedEffect} |-> effects[id]] ELSE effects CarryConditionalInstructionCore96(before,after,beforeStack,afterStack,beforeP,afterP,plan,afterPlan,actualStep) == /\ ConditionalProcedureBound96(before,beforeP) /\ ConditionalAtTop96(beforeStack,beforeP) /\ beforeP.phase="Resolve" /\ before.instances[beforeP.id].status="Resolving" /\ plan.index \in DOMAIN before.instances[beforeP.id].expected /\ LET a == IF plan.cursor=Len(plan.steps) THEN IF beforeP.ability.cursor=Len(beforeP.ability.instructions) THEN [beforeP.ability EXCEPT !.phase="Complete",!.lastFinished=TRUE,!.complete=TRUE] ELSE [beforeP.ability EXCEPT !.phase="Between"] ELSE beforeP.ability last == a.lastFinished effects == IF last THEN EffectsAfterConditionalResolution96(before.effects,beforeP.definition) ELSE before.effects expired == {ConditionalKey96(before.effects[id].definition) : id \in DOMAIN before.effects \ DOMAIN effects} changed == [before.instances EXCEPT ![beforeP.id].status=IF last THEN "Complete" ELSE "Resolving"] throttle == last /\ beforeP.definition.primaryKind="Static" /\ ConditionalExpectedEmpty96(before.instances[beforeP.id],beforeP.ability.instructions) IN /\ CarryAbilityInstructionStep93(beforeP.ability,a,plan,afterPlan,actualStep) /\ last => DOMAIN before.instances[beforeP.id].expected=1..Len(beforeP.ability.instructions) /\ afterP=[beforeP EXCEPT !.ability=a,!.checkpoint=0,!.phase=IF afterPlan.phase="Complete" THEN "InstructionCheckpoint" ELSE "Resolve"] /\ after=[before EXCEPT !.instances=LoseConditionalPendingKeys96(changed,expired),!.effects=effects, !.throttle=IF throttle THEN [key \in DOMAIN @ \cup {ConditionalKey96(beforeP.definition)} |-> IF key=ConditionalKey96(beforeP.definition) THEN before.stepSerial ELSE @[key]] ELSE @] /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) ConditionalInstructionCheckpointCore96(stack,before,after,actualCheckpoint) == /\ ConditionalAtTop96(stack,before) /\ before.phase="InstructionCheckpoint" /\ actualCheckpoint.tag="ConditionalInstructionCheckpoint" /\ actualCheckpoint.id \in Nat \ {0} /\ actualCheckpoint.abilityInstance=before.id /\ actualCheckpoint.transactionId=before.transaction /\ actualCheckpoint.source=before.ability.source /\ actualCheckpoint.instruction=before.ability.instructions[before.ability.cursor] /\ actualCheckpoint.index=before.ability.cursor /\ actualCheckpoint.complete /\ actualCheckpoint.allNewerChainsComplete /\ after=[before EXCEPT !.checkpoint=actualCheckpoint.id,!.phase=IF before.ability.lastFinished THEN "Complete" ELSE "Targets"] EnterNextConditionalInstruction96(beforeLedger,afterLedger,stack,before,after,plan,afterPlan,actualTargets,entry) == /\ ConditionalProcedureBound96(beforeLedger,before) /\ beforeLedger.instances[before.id].status="Resolving" /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status="Imminent"] /\ ConditionalAtTop96(stack,before) /\ before.phase="Targets" /\ before.checkpoint \in Nat \ {0} /\ ~plan.announced /\ entry.checkpointId=before.checkpoint /\ LET announced == [plan EXCEPT !.targets=actualTargets.targets,!.announced=TRUE] imminent == [before.ability EXCEPT !.cursor=@+1,!.phase="Imminent"] IN /\ AnnounceInstructionTargets93(plan,announced,actualTargets,before.ability,"NoValue") /\ EnterNextAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.phase="Imminent",!.checkpoint=0] FinishConditionalProcedure96(beforeStack,afterStack,before,after,actualReturn) == /\ ConditionalAtTop96(beforeStack,before) /\ before.phase="Complete" /\ before.checkpoint \in Nat \ {0} /\ actualReturn.finalCheckpointId=before.checkpoint /\ LET returned == [before.ability EXCEPT !.returned=TRUE] IN /\ ReturnAbility9(before.ability,returned,TRUE,before.windowId) /\ CompletePriorityOption9(beforeStack,afterStack,actualReturn) /\ after=[before EXCEPT !.ability=returned,!.phase="Returned"] ConditionalPendingAfterWindows96(before,afterStack) == [before EXCEPT !.instances=[id \in DOMAIN @ |-> IF @[id].status="Pending" /\ \E i \in 1..Len(afterStack) : afterStack[i].id=@[id].member.windowId /\ id \notin afterStack[i].pending THEN [@[id] EXCEPT !.status="Lost"] ELSE @[id]]] PassConditionalPriorityCore96(beforeLedger,afterLedger,beforeStack,afterStack,player,currentEffect) == /\ PassPriority9(beforeStack,afterStack,player,currentEffect) /\ afterLedger=ConditionalPendingAfterWindows96(beforeLedger,afterStack) CancelConditionalBeginningCore96(beforeLedger,afterLedger,beforeStack,afterStack,actualEnd) == /\ CancelBeginningReactions9(beforeStack,afterStack,actualEnd) /\ afterLedger=ConditionalPendingAfterWindows96(beforeLedger,afterStack) ObserveConditionalTimingStep96(before,after,actualStep) == /\ actualStep.tag="TimingStructureStepCompleted" /\ TimingRefValid9(actualStep.structure) /\ actualStep.procedureId \in Nat \ {0} /\ actualStep.step # "NoValue" /\ actualStep.previousSerial=before.stepSerial /\ actualStep.serial=before.stepSerial+1 /\ after=[before EXCEPT !.stepSerial=actualStep.serial] AdvanceConditionalTraversalStep96(before,after,beforeControl,afterControl,layout,activated,e,m,work,newPhaseId,actualComplete,actualCheckpointDrained,actualStep) == /\ AdvanceNormalTraversalStep6(beforeControl,afterControl,layout,activated,e,m,work,newPhaseId,actualComplete,actualCheckpointDrained,{}) /\ actualStep.structure=TimingRef9("TraversalPhase",beforeControl.traversal.phaseId) /\ actualStep.procedureId=beforeControl.traversal.id /\ actualStep.step=beforeControl.traversal.step /\ ObserveConditionalTimingStep96(before,after,actualStep) DelayedDurationValid96(duration) == duration=NoTimingRef9 \/ TimingRefValid9(duration) \/ (duration.kind="Stated" /\ duration.id \in Nat \ {0}) ExpireDelayedConditionalDurationCore96(before,after,beforeStack,afterStack,actualExpiry) == /\ actualExpiry.tag="DelayedConditionalDurationExpiry" /\ actualExpiry.observationId \in Nat \ {0} /\ \A duration \in actualExpiry.expiredDurations : DelayedDurationValid96(duration) /\ duration # NoTimingRef9 /\ LET expired == {id \in DOMAIN before.effects : before.effects[id].policy="UntilDurationExpires" /\ before.effects[id].duration \in actualExpiry.expiredDurations} keys == {ConditionalKey96(before.effects[id].definition) : id \in expired} IN /\ after=[before EXCEPT !.effects=[id \in DOMAIN @ \ expired |-> @[id]],!.instances=LoseConditionalPendingKeys96(@,keys)] /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) ConditionalCreationInstruction96(plan,parent,ruleStep) == /\ plan.phase="Resolving" /\ IF plan.origin="Ability" THEN parent.phase="Resolving" /\ InstructionPlanMatches93(plan,parent,parent.cursor) ELSE RuleInstructionPlan93(plan,ruleStep) DelayedDefinition96(template,definitionId,effectId) == [template EXCEPT !.syntax.id=definitionId,!.activity.id=definitionId,!.activity.provider="Lingering",!.delayedEffect=effectId] CreateDelayedConditional96(before,after,effectId,definitionId,template,plan,parent,ruleStep,actualCreation,traversal,usedDefinitions) == /\ ConditionalCreationInstruction96(plan,parent,ruleStep) /\ actualCreation.tag="DelayedConditionalCreation" /\ actualCreation.instruction=InstructionWindowRef93(plan) /\ actualCreation.template=template /\ template.syntax.source=plan.source /\ ConditionalDefinitionValid96(template) /\ actualCreation.association \in {"Ordinary","IfSuccessfulInspection"} /\ IF template.thisTraversal /\ "TraversalEnds" \in ConditionalEventKinds96(template) /\ ~TraversalTimingPresent6(traversal) THEN after=before ELSE /\ effectId \in (Nat \ {0}) \ (DOMAIN before.effects \cup before.usedDelayedEffects) /\ definitionId \in (Nat \ {0}) \ (usedDefinitions \cup before.usedDelayedDefinitions) /\ definitionId \notin {before.effects[id].definition.syntax.id : id \in DOMAIN before.effects} /\ IF actualCreation.association="IfSuccessfulInspection" THEN "Inspection" \in ConditionalEventKinds96(template) /\ IfSuccessfulCondition6(actualCreation.ifSuccessfulOrigin,traversal,actualCreation.permittedTargetSites) ELSE TRUE /\ DelayedDurationValid96(actualCreation.duration) /\ LET definition == DelayedDefinition96(template,definitionId,effectId) duration == IF actualCreation.association="IfSuccessfulInspection" THEN TimingRef9("SchemaAtom138",traversal.id) ELSE actualCreation.duration trigger == IF template.thisTraversal THEN TimingRef9("SchemaAtom138",traversal.id) ELSE actualCreation.triggerStructure effect == [id |-> effectId,definition |-> definition,source |-> plan.source, policy |-> IF duration=NoTimingRef9 THEN "UntilResolution" ELSE "UntilDurationExpires", duration |-> duration,triggerStructure |-> trigger,association |-> actualCreation.association, traversalId |-> IF actualCreation.association="IfSuccessfulInspection" THEN traversal.id ELSE 0] IN after=[before EXCEPT !.effects=[id \in DOMAIN @ \cup {effectId} |-> IF id=effectId THEN effect ELSE @[id]], !.usedDelayedEffects=@ \cup {effectId},!.usedDelayedDefinitions=@ \cup {definitionId}] DelayedConditionalDefinitions96(effects) == [key \in {ConditionalKey96(effects[id].definition) : id \in DOMAIN effects} |-> effects[CHOOSE id \in DOMAIN effects : ConditionalKey96(effects[id].definition)=key].definition] DelayedConditionalAbilityIds96(effects) == {effects[id].definition.syntax.id : id \in DOMAIN effects} ExpireDelayedConditionalTimingCore96(before,after,beforeStack,afterStack,actualEnd) == /\ actualEnd.tag="TimingStructureEnded" /\ TimingRefValid9(actualEnd.structure) /\ LET expired == {id \in DOMAIN before.effects : before.effects[id].policy="UntilDurationExpires" /\ before.effects[id].duration=actualEnd.structure} keys == {ConditionalKey96(before.effects[id].definition) : id \in expired} IN /\ after=[before EXCEPT !.effects=[id \in DOMAIN @ \ expired |-> @[id]],!.instances=LoseConditionalPendingKeys96(@,keys)] /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) ExampleFamily092Occurrence96(d,requestedClass,plan,parent,ruleStep,actualEffect,snapshot,event) == /\ ConditionalDefinitionValid96(d) /\ ConditionalCreationInstruction96(plan,parent,ruleStep) /\ requestedClass \in {"WhenEncountered","WhenDeployed","WhenScored"} \cap ConditionalClasses96(d) /\ actualEffect.tag="ConditionalExampleFamily092" /\ actualEffect.class=requestedClass /\ actualEffect.ability=d.syntax.id /\ actualEffect.source=d.syntax.source /\ actualEffect.snapshotId=snapshot.id /\ actualEffect.instruction=InstructionWindowRef93(plan) /\ actualEffect.authorized /\ requestedClass="WhenScored" => d.syntax.cardKind="Objective" /\ event.id=actualEffect.occurrenceId /\ event.kind=CASE requestedClass="WhenScored" -> "ObjectivePlacementd" [] requestedClass="WhenDeployed" -> "Deployed" [] OTHER -> "EncounterBarrier" /\ event.object=d.syntax.source.object /\ event.scopeKind="Ability" /\ event.scopeDefinition=ConditionalKey96(d) /\ event.actor=IF requestedClass="WhenScored" THEN "SideA" ELSE IF requestedClass="WhenEncountered" THEN "SideB" ELSE actualEffect.deployActor /\ requestedClass="WhenDeployed" => actualEffect.deployActor \in SetupPlayers /\ event.side=d.syntax.side /\ event.snapshot=snapshot /\ event.effectId=plan.id CarryConditionalInstruction96(before,candidate,after,beforeStack,afterStack,beforeP,afterP,plan,afterPlan,actualStep,beforeSnapshot,afterSnapshot) == /\ CarryConditionalInstructionCore96(before,candidate,beforeStack, [i \in 1..Len(beforeStack) |-> LET lost == {id \in beforeStack[i].pending \cap DOMAIN before.instances : candidate.instances[id].status # "Pending"} IN [beforeStack[i] EXCEPT !.pending=@ \ lost,!.lostPending=@ \cup lost]],beforeP,afterP,plan,afterPlan,actualStep) /\ ObserveConditionalActivity96(before,candidate,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) PassConditionalPriority96(before,candidate,after,beforeStack,afterStack,player,currentEffect,beforeSnapshot,afterSnapshot) == /\ PassConditionalPriorityCore96(before,candidate,beforeStack, ReplaceWindowTop9(beforeStack,PassPriorityFrame9(WindowTop9(beforeStack))),player,currentEffect) /\ ObserveConditionalActivity96(before,candidate,after,ReplaceWindowTop9(beforeStack,PassPriorityFrame9(WindowTop9(beforeStack))),afterStack,beforeSnapshot,afterSnapshot) CancelConditionalBeginning96(before,candidate,after,beforeStack,candidateStack,afterStack,actualEnd,beforeSnapshot,afterSnapshot) == /\ CancelConditionalBeginningCore96(before,candidate,beforeStack,candidateStack,actualEnd) /\ ObserveConditionalActivity96(before,candidate,after,candidateStack,afterStack,beforeSnapshot,afterSnapshot) ExpireDelayedConditionalTiming96(before,candidate,after,beforeStack,afterStack,actualEnd,beforeSnapshot,afterSnapshot) == /\ ExpireDelayedConditionalTimingCore96(before,candidate,beforeStack, [i \in 1..Len(beforeStack) |-> LET lost == {id \in beforeStack[i].pending \cap DOMAIN before.instances : candidate.instances[id].status # "Pending"} IN [beforeStack[i] EXCEPT !.pending=@ \ lost,!.lostPending=@ \cup lost]],actualEnd) /\ ObserveConditionalActivity96(before,candidate,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) ExpireDelayedConditionalDuration96(before,candidate,after,beforeStack,afterStack,actualExpiry,beforeSnapshot,afterSnapshot) == /\ ExpireDelayedConditionalDurationCore96(before,candidate,beforeStack, [i \in 1..Len(beforeStack) |-> LET lost == {id \in beforeStack[i].pending \cap DOMAIN before.instances : candidate.instances[id].status # "Pending"} IN [beforeStack[i] EXCEPT !.pending=@ \ lost,!.lostPending=@ \cup lost]],actualExpiry) /\ ObserveConditionalActivity96(before,candidate,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) DeactivationConditionalCard96(before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot,object,actualEffectAuthorizes,events) == /\ Deactivation8(beforeSnapshot.objects,afterSnapshot.objects,object,actualEffectAuthorizes,events) /\ ObserveConditionalActivity96(before,before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) FinishActivationConditionalCard96(before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot,beforeActivation,afterActivation,actualLegal,events) == /\ FinishActivation8(beforeActivation,afterActivation,beforeSnapshot.objects,afterSnapshot.objects,actualLegal,events) /\ ObserveConditionalActivity96(before,before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) ApplyConditionalTraversalEndPolicy96(before,candidate,after,beforeStack,candidateStack,afterStack,cleanupId,actualCleanup,beforeSnapshot,afterSnapshot) == /\ ApplyTraversalEndWindowPolicy9(beforeStack,candidateStack,cleanupId,actualCleanup) /\ candidate=ConditionalPendingAfterWindows96(before,candidateStack) /\ ObserveConditionalActivity96(before,candidate,after,candidateStack,afterStack,beforeSnapshot,afterSnapshot) ConditionalPriorityCaller96(w) == [kind |-> "PriorityReception",windowId |-> w.id,reception |-> w.reception,player |-> w.priority] ConditionalInstructionCaller96(p) == [kind |-> "AbilityInstruction",abilityKind |-> p.ability.kind,abilityInstance |-> p.id,source |-> p.ability.source, instruction |-> p.ability.instructions[p.ability.cursor],index |-> p.ability.cursor,windowId |-> p.windowId,transactionId |-> p.transaction] PaidCheckpointCaller96(p) == IF p.phase="CostCheckpoint" THEN [kind |-> "PaidTriggerCost",abilityInstance |-> p.id,source |-> p.ability.source,windowId |-> p.windowId,transactionId |-> p.transaction] ELSE ConditionalInstructionCaller96(p) ConditionalCheckpointDrained96(ledger,stack,checkpointId) == /\ checkpointId \in DOMAIN ledger.checkpoints /\ LET ids == {id \in DOMAIN ledger.instances : ledger.instances[id].checkpointId=checkpointId /\ ~ledger.instances[id].member.interrupt} windows == {ledger.instances[id].member.windowId : id \in ids} IN /\ \A id \in ids : ledger.instances[id].status \in {"Complete","Lost"} /\ \A i \in 1..Len(stack) : stack[i].id \in windows => ~stack[i].open /\ stack[i].busy.id=0 CheckpointPriorityWithConditionals96(ledger,before,after,actualCheckpoint) == /\ Len(before)>0 /\ actualCheckpoint.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[actualCheckpoint.id].caller=ConditionalPriorityCaller96(WindowTop9(before)) /\ ConditionalCheckpointDrained96(ledger,before,actualCheckpoint.id) /\ CheckpointPriority9(before,after,actualCheckpoint) ConditionalInstructionCheckpoint96(ledger,stack,before,after,actualCheckpoint) == /\ actualCheckpoint.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[actualCheckpoint.id].caller=ConditionalInstructionCaller96(before) /\ ConditionalCheckpointDrained96(ledger,stack,actualCheckpoint.id) /\ ConditionalInstructionCheckpointCore96(stack,before,after,actualCheckpoint) PaidCheckpointWithConditionals96(ledger,stack,before,after,objects,transits,actualCheckpoint) == /\ actualCheckpoint.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[actualCheckpoint.id].caller=PaidCheckpointCaller96(before) /\ ConditionalCheckpointDrained96(ledger,stack,actualCheckpoint.id) /\ PaidCheckpoint95(stack,before,after,objects,transits,actualCheckpoint) EmptyPlay97 == [id \in {} |-> id] PlayDefinitionValid97(d) == /\ d.syntax.kind="Play" /\ d.activity.kind="Play" /\ d.activity.provider="Printed" /\ d.syntax.cardKind \in {"Action","Plan"} /\ AbilityTextValid93(d.syntax) /\ d.activity.id=d.syntax.id /\ d.activity.source=d.syntax.source /\ Len(d.instructions)>0 /\ DOMAIN d.partsByInstruction=SubIds6(d.instructions) /\ d.optionalParts \subseteq UNION {d.partsByInstruction[i] : i \in DOMAIN d.partsByInstruction} PrintedPlayOrder97(text) == SelectSeq(text.order,LAMBDA id : text.definitions[id].syntax.kind="Play") PlaySourceTextValid97(f,objects,text,cardFacts) == /\ f.object \in DOMAIN objects /\ PlayTypeAllowed8(objects[f.object],f.actor) /\ objects[f.object].zone="Play" /\ f.kind=objects[f.object].kind /\ f.activationReached /\ text.tag="NormalizedPrintedAbilities" /\ text.playId=f.id /\ text.object=f.object /\ text.card=objects[f.object].card /\ text.sourceSHA=cardFacts[text.card].sourceSHA /\ DeckSequenceValid4(text.order) /\ DOMAIN text.definitions=SubIds6(text.order) /\ \A id \in DOMAIN text.definitions : LET d == text.definitions[id] IN /\ d.syntax.id=id /\ d.syntax.source=ObjectAbilitySource9(f.object) /\ d.syntax.controller=f.actor /\ d.syntax.cardKind=f.kind /\ d.syntax.side=f.actor /\ d.activity.id=id /\ d.activity.source=d.syntax.source /\ d.activity.kind=d.syntax.kind /\ d.activity.provider="Printed" /\ AbilityTextValid93(d.syntax) /\ (d.syntax.kind="Play" => PlayDefinitionValid97(d)) PlayActivationCaller97(f) == [kind |-> "PlayActivation",playId |-> f.id,caller |-> f.caller,source |-> ObjectAbilitySource9(f.object),transactionId |-> f.transaction] PlayInvocationValid97(f,stack,invocation) == /\ invocation.tag="PlayInvocation" /\ invocation.playId=f.id /\ invocation.object=f.object /\ invocation.caller=f.caller /\ invocation.transactionId=f.transaction /\ invocation.owner.windowId \in Nat /\ invocation.origin \in {"NeutralValue00001","Instruction"} /\ IF invocation.origin="NeutralValue00001" THEN /\ invocation.owner.windowId # 0 /\ f.caller=invocation.owner.windowId /\ Len(stack)>0 /\ WindowTop9(stack).kind="NeutralValue00001" ELSE /\ f.caller=invocation.parentPlan.id /\ ConditionalCreationInstruction96(invocation.parentPlan,invocation.parentAbility,invocation.ruleStep) /\ invocation.instruction=InstructionWindowRef93(invocation.parentPlan) /\ IF invocation.owner.windowId=0 THEN Len(stack)=0 /\ invocation.owner.option=NoPriorityOption9 /\ invocation.owner.transaction=0 ELSE /\ Len(stack)>0 /\ WindowTop9(stack).id=invocation.owner.windowId /\ WindowTop9(stack).busy=invocation.owner.option /\ WindowTop9(stack).busy.id # 0 /\ WindowTop9(stack).busyTransaction=invocation.owner.transaction PlayIdleAbility97(source,caller) == OpenAbilityResolution9(0,"Play",source,"Play",<<>>,caller) NewPlayCohort97(f,text,invocation) == [playId |-> f.id,source |-> ObjectAbilitySource9(f.object),transaction |-> f.transaction,owner |-> invocation.owner, sourceText |-> text,order |-> PrintedPlayOrder97(text),cursor |-> 1,dispositions |-> EmptyPlay97, id |-> 0,ability |-> PlayIdleAbility97(ObjectAbilitySource9(f.object),f.id),checkpoint |-> 0,usedInstances |-> {}, phase |-> IF PrintedPlayOrder97(text)= <<>> THEN "Complete" ELSE "Ready"] EnterPlayCohort97(beforePlay,afterPlay,c,objects,text,invocation,ledger,stack,checkpointId,cardFacts) == /\ checkpointId \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[checkpointId].caller=PlayActivationCaller97(beforePlay) /\ ConditionalCheckpointDrained96(ledger,stack,checkpointId) /\ OpenPlayAbilities8(beforePlay,afterPlay,checkpointId,TRUE) /\ PlaySourceTextValid97(afterPlay,objects,text,cardFacts) /\ PlayInvocationValid97(afterPlay,stack,invocation) /\ c=NewPlayCohort97(afterPlay,text,invocation) PlayOwnerAtTop97(c,f,stack) == /\ f.stage="ProcedureCode3d7f756d78f7" /\ ~f.complete /\ ~f.returned /\ c.playId=f.id /\ c.source=ObjectAbilitySource9(f.object) /\ c.transaction=f.transaction /\ IF c.owner.windowId=0 THEN Len(stack)=0 ELSE /\ Len(stack)>0 /\ WindowTop9(stack).id=c.owner.windowId /\ WindowTop9(stack).busy=c.owner.option /\ WindowTop9(stack).busy.id # 0 /\ WindowTop9(stack).busyTransaction=c.owner.transaction CurrentPlayDefinition97(c) == c.sourceText.definitions[c.order[c.cursor]] PlayPresenceValid97(c,objects,present) == c.source.object \notin DOMAIN objects \/ SubIds6(c.order) \subseteq present PlayCurrentActive97(c,f,objects,present,activity,points) == LET d == CurrentPlayDefinition97(c) IN IF c.source.object \notin DOMAIN objects THEN FALSE ELSE FlagActivity93(d.syntax,present, AbilityActive9(d.activity,objects,present,PlayEffectiveCardActivity8(f,c.source.object,objects[c.source.object],FALSE),activity), activity.persistentAbilities,points) PlayAdvanceDisposition97(c,disposition,instance) == [c EXCEPT !.dispositions=[id \in DOMAIN @ \cup {c.order[c.cursor]} |-> IF id=c.order[c.cursor] THEN [disposition |-> disposition,instance |-> instance] ELSE @[id]], !.cursor=@+1,!.phase=IF c.cursor=Len(c.order) THEN "Complete" ELSE "Ready", !.id=0,!.ability=PlayIdleAbility97(c.source,c.playId),!.checkpoint=0] SkipInactivePlay97(before,after,f,stack,objects,present,activity,points) == /\ PlayOwnerAtTop97(before,f,stack) /\ before.phase="Ready" /\ before.cursor<=Len(before.order) /\ PlayPresenceValid97(before,objects,present) /\ ~PlayCurrentActive97(before,f,objects,present,activity,points) /\ after=PlayAdvanceDisposition97(before,"SkippedInactive",0) BeginPlayAbility97(before,after,f,stack,objects,present,activity,points,instance,usedInstances,plan,afterPlan,targets,entry,restrictions) == /\ PlayOwnerAtTop97(before,f,stack) /\ before.phase="Ready" /\ before.cursor<=Len(before.order) /\ PlayPresenceValid97(before,objects,present) /\ instance \in (Nat \ {0}) \ (usedInstances \cup before.usedInstances) /\ LET d == CurrentPlayDefinition97(before) a == OpenAbilityResolution9(instance,"Play",before.source,"Play",d.instructions,before.playId) announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [a EXCEPT !.phase="Imminent",!.firstImminent=TRUE] IN /\ PlayDefinitionValid97(d) /\ WholeAbilityRestrictionGate93(d.syntax,restrictions) /\ PlayCurrentActive97(before,f,objects,present,activity,points) /\ ~plan.announced /\ entry.sourceEligible=PlayCurrentActive97(before,f,objects,present,activity,points) /\ AnnounceInstructionTargets93(plan,announced,targets,a,"NoValue") /\ EnterFirstAbilityInstruction93(a,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.id=instance,!.ability=imminent,!.phase="Imminent",!.usedInstances=@ \cup {instance}] PlayAbilityBound97(c) == /\ c.cursor<=Len(c.order) /\ c.id \in Nat \ {0} /\ c.id \in c.usedInstances /\ c.ability.id=c.id /\ c.ability.kind="Play" /\ c.ability.source=c.source /\ c.ability.sourceZone="Play" /\ c.ability.caller=c.playId /\ c.ability.instructions=CurrentPlayDefinition97(c).instructions /\ ~c.ability.detached OpenPlayInstructionInterrupt97(c,f,beforeStack,afterStack,plan,id,site,instances,opening,usedWindows) == /\ PlayOwnerAtTop97(c,f,beforeStack) /\ PlayAbilityBound97(c) /\ c.phase="Imminent" /\ OpenInstructionInterrupt93(beforeStack,afterStack,id,site,instances,opening,usedWindows,plan,c.ability,"NoValue") ResolvePlayWithoutInterrupt97(before,after,f,stack,plan,afterPlan,noModifiers,clearance) == /\ PlayOwnerAtTop97(before,f,stack) /\ PlayAbilityBound97(before) /\ before.phase="Imminent" /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ NoInstructionInterrupt93(plan,before.ability,"NoValue",noModifiers,clearance) /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] ResolvePlayAfterInterrupt97(before,after,f,beforeStack,afterStack,plan,afterPlan,clearance) == /\ PlayAbilityBound97(before) /\ before.phase="Imminent" /\ ReturnInstructionInterrupt93(beforeStack,afterStack,plan,before.ability,"NoValue",clearance) /\ PlayOwnerAtTop97(before,f,afterStack) /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] CarryPlayInstruction97(before,after,f,stack,plan,afterPlan,step) == /\ PlayOwnerAtTop97(before,f,stack) /\ PlayAbilityBound97(before) /\ before.phase="Resolve" /\ CarryAbilityInstructionStep93(before.ability,after.ability,plan,afterPlan,step) /\ after=[before EXCEPT !.ability=after.ability,!.checkpoint=0,!.phase=IF afterPlan.phase="Complete" THEN "InstructionCheckpoint" ELSE "Resolve"] PlayInstructionCaller97(c) == [kind |-> "PlayInstruction",playId |-> c.playId,abilityInstance |-> c.id,source |-> c.source,transactionId |-> c.transaction, instruction |-> c.ability.instructions[c.ability.cursor],index |-> c.ability.cursor,windowId |-> c.owner.windowId] PlayInstructionCheckpoint97(before,after,f,stack,ledger,receipt) == /\ PlayOwnerAtTop97(before,f,stack) /\ PlayAbilityBound97(before) /\ before.phase="InstructionCheckpoint" /\ receipt.tag="PlayInstructionCheckpoint" /\ receipt.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[receipt.id].caller=PlayInstructionCaller97(before) /\ ConditionalCheckpointDrained96(ledger,stack,receipt.id) /\ receipt.playId=before.playId /\ receipt.abilityInstance=before.id /\ receipt.source=before.source /\ receipt.instruction=before.ability.instructions[before.ability.cursor] /\ receipt.index=before.ability.cursor /\ receipt.transactionId=before.transaction /\ receipt.complete /\ receipt.allNewerChainsComplete /\ after=[before EXCEPT !.checkpoint=receipt.id,!.phase=IF before.ability.lastFinished THEN "AbilityComplete" ELSE "Targets"] EnterNextPlayInstruction97(before,after,f,stack,plan,afterPlan,targets,entry) == /\ PlayOwnerAtTop97(before,f,stack) /\ PlayAbilityBound97(before) /\ before.phase="Targets" /\ before.checkpoint \in Nat \ {0} /\ entry.checkpointId=before.checkpoint /\ ~plan.announced /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [before.ability EXCEPT !.cursor=@+1,!.phase="Imminent"] IN /\ AnnounceInstructionTargets93(plan,announced,targets,before.ability,"NoValue") /\ EnterNextAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.phase="Imminent",!.checkpoint=0] FinishOnePlayAbility97(before,after,f,stack) == /\ PlayOwnerAtTop97(before,f,stack) /\ PlayAbilityBound97(before) /\ before.phase="AbilityComplete" /\ before.checkpoint \in Nat \ {0} /\ ReturnAbility9(before.ability,[before.ability EXCEPT !.returned=TRUE],TRUE,before.playId) /\ after=PlayAdvanceDisposition97(before,"Resolved",before.id) FinishPlayCohort97(c,beforePlay,afterPlay,stack,receipt) == /\ PlayOwnerAtTop97(c,beforePlay,stack) /\ c.phase="Complete" /\ c.cursor=Len(c.order)+1 /\ DOMAIN c.dispositions=SubIds6(c.order) /\ \A id \in DOMAIN c.dispositions : c.dispositions[id].disposition \in {"Resolved","SkippedInactive"} /\ receipt.tag="PlayCohortCompletion" /\ receipt.playId=c.playId /\ receipt.object=c.source.object /\ receipt.dispositions=c.dispositions /\ FinishPlayAbilities8(beforePlay,afterPlay, [playId |-> c.playId,object |-> c.source.object,allPlayAbilitiesResolved |-> TRUE, ownedTimingIds |-> receipt.ownedTimingIds,returnedTimingIds |-> receipt.returnedTimingIds,ownEndTriggersResolved |-> receipt.ownEndTriggersResolved]) RecordPlayOptionalChoice97(beforeUses,afterUses,beforeChoices,afterChoices,c,plan,choice,useId,events) == /\ PlayAbilityBound97(c) /\ c.phase="Resolve" /\ plan.phase="Resolving" /\ InstructionPlanMatches93(plan,c.ability,c.ability.cursor) /\ choice.tag="PlayOptionalChoice" /\ choice.instruction=InstructionWindowRef93(plan) /\ choice.abilityInstance=c.id /\ choice.source=c.source /\ choice.component \in CurrentPlayDefinition97(c).optionalParts /\ choice.component \in CurrentPlayDefinition97(c).partsByInstruction[plan.id] /\ choice.id \in Nat \ {0} /\ [instance |-> c.id,choice |-> choice.id] \notin beforeChoices /\ choice.complete /\ afterChoices=beforeChoices \cup {[instance |-> c.id,choice |-> choice.id]} /\ IF choice.carriedOut THEN /\ AbilityUseDue9("Play",FALSE,FALSE,FALSE,TRUE) /\ RecordAbilityUse9(beforeUses,afterUses,useId,c.id,c.source,CurrentPlayDefinition97(c).syntax.controller,TRUE,events) ELSE afterUses=beforeUses /\ events={} NormalPlayCleanup97(beforePlay,afterPlay,beforeObjects,afterObjects,successor,usedIds,cleanup) == /\ beforePlay.object \in DOMAIN beforeObjects /\ beforeObjects[beforePlay.object].form="Card" /\ beforeObjects[beforePlay.object].zone="Play" /\ beforeObjects[beforePlay.object].host=0 /\ FinishPlayCleanup8(beforePlay,afterPlay,beforeObjects,FALSE,FALSE,cleanup,EmptyPlay97,EmptyPlay97,EmptyPlay97) /\ CardBatchTransfer8(beforeObjects,afterObjects,{beforePlay.object},[id \in {beforePlay.object} |-> successor],usedIds, beforePlay.actor \o "Discard","Up",[id \in {beforePlay.object} |-> "Discard"]) NormalPlayResolvedOccurrence97(beforeCleanup,afterCleanup,afterResolved,beforeObjects,afterObjects,successor,usedIds,cleanup,rawEvents,originalDefinition,currentDefinition,snapshot,occurrenceId,event,cohort) == /\ NormalPlayCleanup97(beforeCleanup,afterCleanup,beforeObjects,afterObjects,successor,usedIds,cleanup) /\ MeetPlayResolvedConditions8(afterCleanup,afterResolved,rawEvents) /\ cohort.playId=beforeCleanup.id /\ cohort.source=ObjectAbilitySource9(beforeCleanup.object) /\ cohort.phase="Complete" /\ cohort.sourceText.object=beforeCleanup.object /\ cohort.sourceText.playId=beforeCleanup.id /\ cohort.sourceText.card=beforeObjects[beforeCleanup.object].card /\ originalDefinition.syntax.id \in DOMAIN cohort.sourceText.definitions /\ originalDefinition=cohort.sourceText.definitions[originalDefinition.syntax.id] /\ ConditionalDefinitionValid96(originalDefinition) /\ originalDefinition.syntax.source=ObjectAbilitySource9(beforeCleanup.object) /\ originalDefinition.activity.provider="Printed" /\ originalDefinition.trigger.subject="SchemaAtom149" /\ "PlayResolved" \in ConditionalEventKinds96(originalDefinition) /\ currentDefinition=ReboundConditionalDefinition96(originalDefinition,successor) /\ afterCleanup.actor \o "Discard" \in currentDefinition.activity.rulesOnlyZones /\ snapshot.objects=afterObjects /\ ConditionalKey96(currentDefinition) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(currentDefinition)]=currentDefinition /\ occurrenceId \in Nat \ {0} /\ LET raw == [tag |-> "PlayResolved",object |-> afterCleanup.object,kind |-> afterCleanup.kind,actor |-> afterCleanup.actor,playId |-> afterCleanup.id] IN /\ rawEvents={raw} /\ event.id=occurrenceId /\ event.kind="PlayResolved" /\ event.object=currentDefinition.syntax.source.object /\ event.actor=raw.actor /\ event.side=raw.actor /\ event.snapshot=snapshot /\ event.effectId=raw.playId /\ event.scopeKind="Global" /\ event.rawOrigin=raw PublishNormalPlayCleanup97(before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot,beforePlay,afterPlay,successor,usedIds,cleanup) == /\ NormalPlayCleanup97(beforePlay,afterPlay,beforeSnapshot.objects,afterSnapshot.objects,successor,usedIds,cleanup) /\ ObserveConditionalActivity96(before,before,after,beforeStack,afterStack,beforeSnapshot,afterSnapshot) RecognizeNormalPlayResolved97(before,after,beforeStack,afterStack,origin,definitions,cp,conditions,allocation,bindings,departures,holds,usedWindows) == /\ NormalPlayResolvedOccurrence97(origin.beforeCleanup,origin.afterCleanup,origin.afterResolved,origin.beforeObjects,origin.afterObjects, origin.successor,origin.usedIds,origin.cleanup,origin.rawEvents,origin.originalDefinition,origin.currentDefinition, origin.snapshot,origin.occurrenceId,origin.event,origin.cohort) /\ origin.occurrenceId \in DOMAIN cp.occurrences /\ cp.occurrences[origin.occurrenceId]=origin.event /\ ProcessConditionalCheckpoint96(before,after,beforeStack,afterStack,definitions,cp,conditions,allocation,bindings,departures,holds,usedWindows) EmptyOrder98 == [id \in {} |-> id] RuntimeSubIds98(state) == SubIds6(state.order) OrderPosition98(order,id) == CHOOSE i \in 1..Len(order) : order[i]=id OrderBefore98(order,a,b) == OrderPosition98(order,a)0 BarrierInstructionOrderValid98(state) == /\ state.barrierCard \in Nat \ {0} /\ DeckSequenceValid4(state.spine) /\ state.usedIds=SubIds6(state.spine) /\ state.present \subseteq state.usedIds /\ state.order=VisibleSubOrder98(state.spine,state.present) /\ DOMAIN state.definitions=state.usedIds /\ DOMAIN state.provenance=state.usedIds /\ \A id \in state.usedIds : BarrierInstructionDefinitionValid98(state.definitions[id],id,state.barrierCard) /\ state.activeApplications \subseteq DOMAIN state.applications /\ state.clock \in Nat NewBarrierInstructionOrder98(barrierCard,printedOrder,definitions,textKeys) == [barrierCard |-> barrierCard,order |-> printedOrder,present |-> SubIds6(printedOrder),spine |-> printedOrder,usedIds |-> SubIds6(printedOrder), definitions |-> definitions,provenance |-> [id \in SubIds6(printedOrder) |-> [kind |-> "Printed",effect |-> 0,parent |-> 0, printedSlot |-> OrderPosition98(printedOrder,id),born |-> 0,tie |-> OrderPosition98(printedOrder,id),textKey |-> textKeys[id]]], printedText |-> [slot \in 1..Len(printedOrder) |-> [definition |-> definitions[printedOrder[slot]],key |-> textKeys[printedOrder[slot]]]], applications |-> EmptyOrder98,activeApplications |-> {},clock |-> 0,history |-> <<>>,decisions |-> EmptyOrder98] InitializeBarrierInstructionOrder98(state,barrierCard,order,definitions,keys,objects,cardFacts,printedText) == /\ barrierCard \in DOMAIN objects /\ objects[barrierCard].kind="Barrier" /\ DOMAIN definitions=SubIds6(order) /\ DOMAIN keys=SubIds6(order) /\ printedText.tag="NormalizedPrintedBarrierInstructions" /\ printedText.barrierCard=barrierCard /\ printedText.card=objects[barrierCard].card /\ printedText.sourceSHA=cardFacts[objects[barrierCard].card].sourceSHA /\ printedText.order=order /\ printedText.definitions=definitions /\ printedText.textKeys=keys /\ \A id \in DOMAIN definitions : definitions[id].activity.provider="Printed" /\ state=NewBarrierInstructionOrder98(barrierCard,order,definitions,keys) /\ BarrierInstructionOrderValid98(state) SelfStaticGrant98(grant,barrierCard) == grant.ability.syntax.kind="Static" /\ grant.ability.syntax.source=ObjectAbilitySource9(barrierCard) GrantCategory98(grant,barrierCard) == IF SelfStaticGrant98(grant,barrierCard) THEN IF grant.placement="Before" THEN 2 ELSE 4 ELSE IF grant.placement="Before" THEN 1 ELSE 5 SubOriginCategory98(state,id) == CASE state.provenance[id].kind="Printed" -> 3 [] state.provenance[id].kind="Copy" -> 0 [] OTHER -> GrantCategory98(state.applications[state.provenance[id].effect].definition,state.barrierCard) SelfCategoryIdentical98(state) == \A a,b \in state.present : (SubOriginCategory98(state,a) \in {2,4} /\ SubOriginCategory98(state,a)=SubOriginCategory98(state,b)) => state.provenance[a].textKey=state.provenance[b].textKey /\ ReidentifyBarrierInstruction98(state.definitions[a],b)=state.definitions[b] BarrierInstructionGrantValid98(grant,barrierCard,objects,cardFacts) == /\ grant.tag="NormalizedBarrierInstructionGrant" /\ grant.id \in Nat \ {0} /\ grant.target=barrierCard /\ barrierCard \in DOMAIN objects /\ objects[barrierCard].kind="Barrier" /\ grant.ability.syntax.source.kind="Object" /\ grant.ability.syntax.source.object \in Nat \ {0} /\ grant.ability.syntax.id \in Nat \ {0} /\ grant.origin.tag="NormalizedBarrierInstructionGrantOrigin" /\ grant.origin.ability=grant.ability.syntax.id /\ grant.origin.source=grant.ability.syntax.source /\ grant.origin.card=grant.card /\ grant.origin.sourceSHA=grant.sourceSHA /\ grant.origin.kind \in {"Ability","MaintainedEffect"} /\ grant.ability.syntax.kind="Static" => grant.origin.kind="Ability" /\ grant.sourceSHA=cardFacts[grant.card].sourceSHA /\ grant.ability.syntax.cardKind=cardFacts[grant.card].kind /\ grant.ability.syntax.side=cardFacts[grant.card].side /\ AbilityTextValid93(grant.ability.syntax) /\ grant.ability.activity.id=grant.ability.syntax.id /\ grant.ability.activity.source=grant.ability.syntax.source /\ grant.ability.activity.kind=grant.ability.syntax.kind /\ grant.placement \in {"Before","After","Unspecified"} /\ grant.mode \in {"Default","SideAChoice","TLDR"} /\ grant.specified \in BOOLEAN /\ (grant.mode # "TLDR" => Len(grant.templates)>0) /\ \A i \in 1..Len(grant.templates) : BarrierInstructionDefinitionValid98(grant.templates[i].definition,grant.templates[i].definition.syntax.id,barrierCard) /\ SelfStaticGrant98(grant,barrierCard) => grant.mode="Default" /\ Len(grant.templates)=1 OrdinarySub98(state,id) == state.provenance[id].kind # "Copy" /\ (state.provenance[id].kind="Printed" \/ state.applications[state.provenance[id].effect].definition.mode="Default") OrdinaryPrecedes98(state,a,b) == LET ca == SubOriginCategory98(state,a) cb == SubOriginCategory98(state,b) pa == state.provenance[a] pb == state.provenance[b] IN IF ca # cb THEN ca pa.printedSlot IF pa.born # pb.born THEN pa.born LET ta == state.applications[pa.effect].clock tb == state.applications[pb.effect].clock IN IF ta # tb THEN IF ca=1 THEN ta>tb ELSE ta IF id \in gained THEN rows[id].definition ELSE @[id]], !.applications=[id \in DOMAIN @ \cup DOMAIN newApplications |-> IF id \in DOMAIN newApplications THEN [definition |-> newApplications[id],clock |-> before.clock+1] ELSE @[id]], !.activeApplications=@ \cup DOMAIN newApplications, !.provenance=[id \in DOMAIN @ \cup gained |-> IF id \in gained THEN [kind |-> originKind,effect |-> rows[id].effect,parent |-> rows[id].parent,printedSlot |-> rows[id].printedSlot, born |-> before.clock+1,tie |-> OrderPosition98(decision.gainOrder,id),textKey |-> rows[id].textKey] ELSE @[id]], !.history=Append(@,[kind |-> kind,clock |-> before.clock+1,gained |-> gained,lost |-> lost,decision |-> decision.id,applications |-> DOMAIN newApplications]), !.decisions=[id \in DOMAIN @ \cup {decision.id} |-> IF id=decision.id THEN decision ELSE @[id]]] FreshSubRows98(before,rows) == /\ DOMAIN rows \subseteq (Nat \ {0}) \ before.usedIds /\ \A id \in DOMAIN rows : BarrierInstructionDefinitionValid98(rows[id].definition,id,before.barrierCard) RowsMatchApplication98(rows,application,grant,gainOrder,barrierCard) == LET ids == {id \in DOMAIN rows : rows[id].effect=application} ordered == SelectSeq(gainOrder,LAMBDA id : id \in ids) IN /\ \A id \in ids : rows[id].template \in 1..Len(grant.templates) /\ rows[id].parent=0 /\ rows[id].printedSlot=0 /\ rows[id].textKey=grant.templates[rows[id].template].key /\ rows[id].definition=ReidentifyBarrierInstruction98(grant.templates[rows[id].template].definition,id) /\ IF SelfStaticGrant98(grant,barrierCard) THEN \A id \in ids : rows[id].template=1 ELSE /\ {rows[id].template : id \in ids}=1..Len(grant.templates) /\ Cardinality(ids)=Len(grant.templates) /\ (grant.specified => [i \in 1..Len(ordered) |-> rows[ordered[i]].template]=[i \in 1..Len(grant.templates) |-> i]) FreshOrderingConstraints98(after,gained) == \A a \in gained : \A b \in after.present \ {a} : (OrdinarySub98(after,a) /\ OrdinarySub98(after,b)) => (OrderBefore98(after.order,a,b)=OrdinaryPrecedes98(after,a,b)) GainOrderedBarrierInstructions98(before,after,grants,rows,spine,decision,objects,cardFacts) == LET gained == DOMAIN rows present == before.present \cup gained kind == IF \E g \in DOMAIN grants : grants[g].mode="SideAChoice" THEN "SideADeclaredGain" ELSE "OrdinaryGain" result == OrderChangedState98(before,rows,grants,present,spine,decision,kind,{},"Grant") IN /\ BarrierInstructionOrderValid98(before) /\ FreshSubRows98(before,rows) /\ DOMAIN grants # {} /\ DOMAIN grants \subseteq (Nat \ {0}) \ DOMAIN before.applications /\ \A g \in DOMAIN grants : grants[g].id=g /\ BarrierInstructionGrantValid98(grants[g],before.barrierCard,objects,cardFacts) /\ grants[g].mode # "TLDR" /\ \A g \in DOMAIN grants : grants[g].ability.syntax.kind="Static" => /\ ~\E old \in before.activeApplications : before.applications[old].definition.ability.syntax.id=grants[g].ability.syntax.id /\ before.applications[old].definition.ability.syntax.source=grants[g].ability.syntax.source /\ ~\E other \in DOMAIN grants \ {g} : grants[other].ability.syntax.id=grants[g].ability.syntax.id /\ grants[other].ability.syntax.source=grants[g].ability.syntax.source /\ \A id \in gained : rows[id].effect \in DOMAIN grants /\ \A g \in DOMAIN grants : RowsMatchApplication98(rows,g,grants[g],decision.gainOrder,before.barrierCard) /\ OrderingDecisionBound98(before,decision,kind,gained,{},spine,present) /\ FreshOrderingConstraints98(result,gained) /\ after=result /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) SubRowsFromEffect98(state,application) == SelectSeq(state.order,LAMBDA id : state.provenance[id].kind="Grant" /\ state.provenance[id].effect=application) NormalizedSubCount98(before,application,actualCount,tag) == /\ actualCount.tag=tag /\ actualCount.barrierCard=before.barrierCard /\ actualCount.count \in Nat /\ actualCount.application=application /\ actualCount.snapshotId \in Nat \ {0} /\ IF application=0 THEN TRUE ELSE actualCount.ability=before.applications[application].definition.ability.syntax.id /\ actualCount.source=before.applications[application].definition.ability.syntax.source ResizeSelfStaticSubs98(before,after,application,actualCount,rows,spine,decision) == LET grant == before.applications[application].definition old == SubRowsFromEffect98(before,application) count == actualCount.count keep == SubSeq(old,1,IF countLen(old) THEN count-Len(old) ELSE 0 /\ \A id \in gained : rows[id].effect=application /\ RowsMatchApplication98(rows,application,grant,decision.gainOrder,before.barrierCard) /\ OrderingDecisionBound98(before,decision,"SelfStaticResize",gained,lost,spine,present) /\ FreshOrderingConstraints98(result,gained) /\ after=result /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) SetPrintedSubCount98(before,after,actualCount,rows,spine,decision) == LET old == SelectSeq(before.order,LAMBDA id : before.provenance[id].kind="Printed") count == actualCount.count keep == SubSeq(old,1,IF countLen(old) THEN count-Len(old) ELSE 0 /\ {rows[id].printedSlot : id \in gained}=(IF count>Len(old) THEN (Len(old)+1)..count ELSE {}) /\ \A id \in gained : rows[id].effect=0 /\ rows[id].parent=0 /\ rows[id].definition=ReidentifyBarrierInstruction98(before.printedText[rows[id].printedSlot].definition,id) /\ rows[id].textKey=before.printedText[rows[id].printedSlot].key /\ OrderingDecisionBound98(before,decision,"PrintedResize",gained,lost,spine,present) /\ FreshOrderingConstraints98(result,gained) /\ after=result /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) RECURSIVE CopySubSpine98(_,_) CopySubSpine98(spine,copies) == IF Len(spine)=0 THEN <<>> ELSE (IF Head(spine) \in DOMAIN copies THEN <> ELSE <>) \o CopySubSpine98(Tail(spine),copies) CopyAllBarrierInstructions98(before,after,grant,copies,spine,decision,objects,cardFacts) == LET gained == {copies[id] : id \in DOMAIN copies} rows == [id \in gained |-> LET parent == CHOOSE p \in DOMAIN copies : copies[p]=id IN [definition |-> CopiedBarrierInstructionDefinition98(before.definitions[parent],id),textKey |-> before.provenance[parent].textKey, effect |-> grant.id,parent |-> parent,printedSlot |-> 0,template |-> 0]] applications == [id \in {grant.id} |-> grant] present == before.present \cup gained IN /\ BarrierInstructionOrderValid98(before) /\ BarrierInstructionGrantValid98(grant,before.barrierCard,objects,cardFacts) /\ grant.mode="TLDR" /\ grant.id \notin DOMAIN before.applications /\ DOMAIN copies=before.present /\ gained \subseteq (Nat \ {0}) \ before.usedIds /\ Cardinality(gained)=Cardinality(before.present) /\ spine=CopySubSpine98(before.spine,copies) /\ OrderingDecisionBound98(before,decision,"TLDRCopy",gained,{},spine,present) /\ after=OrderChangedState98(before,rows,applications,present,spine,decision,"TLDRCopy",{},"Copy") /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) RemoveOrderedBarrierInstructions98(before,after,loss) == /\ BarrierInstructionOrderValid98(before) /\ loss.tag="NormalizedBarrierInstructionPresenceLoss" /\ loss.barrierCard=before.barrierCard /\ loss.beforeOrder=before.order /\ loss.beforeHistory=before.history /\ loss.id \in (Nat \ {0}) \ DOMAIN before.decisions /\ loss.ids \subseteq before.present /\ loss.endedApplications \subseteq before.activeApplications /\ {id \in before.present : before.provenance[id].effect \in loss.endedApplications} \subseteq loss.ids /\ after=[before EXCEPT !.present=@ \ loss.ids,!.order=VisibleSubOrder98(before.spine,before.present \ loss.ids),!.clock=@+1, !.activeApplications=@ \ loss.endedApplications, !.history=Append(@,[kind |-> "Loss",clock |-> before.clock+1,gained |-> {},lost |-> loss.ids,decision |-> loss.id,applications |-> loss.endedApplications]), !.decisions=[id \in DOMAIN @ \cup {loss.id} |-> IF id=loss.id THEN loss ELSE @[id]]] /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) BarrierInstructionOwnerAtTop98(owner,stack) == IF owner.windowId=0 THEN Len(stack)=0 /\ owner.option=NoPriorityOption9 /\ owner.transaction=0 ELSE /\ Len(stack)>0 /\ WindowTop9(stack).id=owner.windowId /\ WindowTop9(stack).busy=owner.option /\ owner.option.id # 0 /\ WindowTop9(stack).busyTransaction=owner.transaction BarrierInstructionEncounterCurrent98(e,control) == /\ EncounterTimingLive95(e,control) /\ control.encounter=e.id BarrierInstructionStep98(e,control,step) == /\ BarrierInstructionEncounterCurrent98(e,control) /\ e.stage="BarrierInstructions" /\ step="ProcedureCodef1914978bb8e" /\ IF e.forced THEN TRUE ELSE control.traversal.phase="Encounter" /\ control.traversal.phaseId=e.id /\ control.traversal.step=step BarrierInstructionCurrentActive98(d,objects,present,activity,points) == /\ activity.tag="CurrentBarrierInstructionActivity" /\ activity.objects=objects /\ activity.present=present /\ d.syntax.id \in DOMAIN activity.ordinary /\ FlagActivity93(d.syntax,present,AbilityActive9(d.activity,objects,present,activity.ordinary[d.syntax.id],activity.context),activity.context.persistentAbilities,points) ExampleFamily062SourcesValid98(sources,objects,cardFacts) == \A key \in DOMAIN sources : LET d == sources[key] IN /\ d.syntax.id=key /\ d.syntax.kind="Static" /\ d.activity.kind="Static" /\ d.activity.id=key /\ d.activity.source=d.syntax.source /\ d.syntax.source.kind="Object" /\ d.syntax.source.object \in DOMAIN objects /\ objects[d.syntax.source.object].card="Specimen0226" /\ d.sourceSHA=cardFacts["Specimen0226"].sourceSHA /\ AbilityTextValid93(d.syntax) ActiveExampleFamily062Sources98(sources,objects,present,context,points) == {id \in DOMAIN sources : BarrierInstructionCurrentActive98(sources[id],objects,present,context,points)} NewBarrierInstructionLoop98(e,owner,declared,exampleFamily062) == [encounter |-> e.id,barrierCard |-> e.barrierCard,owner |-> owner,exampleFamily062 |-> exampleFamily062, initialOrder |-> declared,initialEligible |-> SubIds6(declared),handled |-> {},resolved |-> {},prevented |-> {}, current |-> 0,usedInstances |-> {},history |-> <<>>] EnterBarrierInstructionLoop98(before,after,e,control,step,orderState,sources,objects,present,context,points,owner,stack,declaration,cardFacts) == /\ e.id \notin DOMAIN before /\ BarrierInstructionStep98(e,control,step) /\ BarrierInstructionOwnerAtTop98(owner,stack) /\ e.resolved={} /\ BarrierInstructionOrderValid98(orderState) /\ orderState.barrierCard=e.barrierCard /\ orderState.order=e.order /\ ExampleFamily062SourcesValid98(sources,objects,cardFacts) /\ declaration.tag="EncounterBarrierInstructionResolutionOrder" /\ declaration.encounter=e.id /\ declaration.barrierCard=e.barrierCard /\ declaration.step=step /\ declaration.physicalOrder=e.order /\ declaration.barrierInstructionSuppressed=e.barrierInstructionSuppressed /\ DeckSequenceValid4(declaration.order) /\ SubIds6(declaration.order)=SubIds6(e.order) \ e.barrierInstructionSuppressed /\ LET active == ActiveExampleFamily062Sources98(sources,objects,present,context,points) IN /\ IF active={} THEN declaration.exampleFamily062=0 /\ declaration.order=SelectSeq(e.order,LAMBDA id : id \notin e.barrierInstructionSuppressed) ELSE declaration.exampleFamily062 \in active /\ declaration.controller="SideB" /\ declaration.source=sources[declaration.exampleFamily062].syntax.source /\ after=[id \in DOMAIN before \cup {e.id} |-> IF id=e.id THEN NewBarrierInstructionLoop98(e,owner,declaration.order,declaration.exampleFamily062) ELSE before[id]] BarrierInstructionLoopMatches98(loop,e) == /\ loop.encounter=e.id /\ loop.barrierCard=e.barrierCard /\ loop.resolved=e.resolved /\ loop.handled=loop.resolved \cup loop.prevented /\ loop.resolved \cap loop.prevented={} RemainingBarrierInstructions98(loop,e) == SubIds6(e.order) \ (e.barrierInstructionSuppressed \cup loop.handled) ResolutionOrderBound98(loop,e,actualOrder) == /\ actualOrder.tag="CurrentBarrierInstructionResolutionOrder" /\ actualOrder.encounter=e.id /\ actualOrder.barrierCard=e.barrierCard /\ actualOrder.physicalOrder=e.order /\ actualOrder.barrierInstructionSuppressed=e.barrierInstructionSuppressed /\ actualOrder.handled=loop.handled /\ actualOrder.initialOrder=loop.initialOrder /\ actualOrder.exampleFamily062=loop.exampleFamily062 /\ DeckSequenceValid4(actualOrder.order) /\ SubIds6(actualOrder.order)=RemainingBarrierInstructions98(loop,e) /\ IF loop.exampleFamily062=0 THEN actualOrder.order=SelectSeq(e.order,LAMBDA id : id \in RemainingBarrierInstructions98(loop,e)) ELSE /\ SelectSeq(actualOrder.order,LAMBDA id : id \in loop.initialEligible)=SelectSeq(loop.initialOrder,LAMBDA id : id \in RemainingBarrierInstructions98(loop,e)) /\ SelectSeq(actualOrder.order,LAMBDA id : id \notin loop.initialEligible)=SelectSeq(e.order,LAMBDA id : id \in RemainingBarrierInstructions98(loop,e) \ loop.initialEligible) NewBarrierInstructionBarrierInstruction98(id,sub,d,e,owner,zone) == [id |-> id,barrierInstruction |-> sub,encounter |-> e.id,barrierCard |-> e.barrierCard,definition |-> d,payload |-> d,owner |-> owner,origin |-> "Encounter",caller |-> e.id,structure |-> TimingRef9("TraversalPhase",e.id),invocation |-> EmptyOrder98, ability |-> OpenAbilityResolution9(id,"BarrierInstruction",ObjectAbilitySource9(e.barrierCard),zone,d.instructions,e.id), phase |-> "BarrierInstructionImminent",revision |-> 0,prevented |-> FALSE,checkpoint |-> 0,replacements |-> <<>>] SelectNextBarrierInstruction98(before,after,p,e,control,step,orderState,actualOrder,id,usedInstances,objects,present,context,points,stack) == /\ BarrierInstructionLoopMatches98(before,e) /\ before.current=0 /\ BarrierInstructionStep98(e,control,step) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ BarrierInstructionOrderValid98(orderState) /\ orderState.barrierCard=e.barrierCard /\ orderState.order=e.order /\ ResolutionOrderBound98(before,e,actualOrder) /\ Len(actualOrder.order)>0 /\ id \in (Nat \ {0}) \ (usedInstances \cup before.usedInstances) /\ e.barrierCard \in DOMAIN objects /\ LET sub == actualOrder.order[1] d == orderState.definitions[sub] IN /\ BarrierInstructionCurrentActive98(d,objects,present,context,points) /\ p=NewBarrierInstructionBarrierInstruction98(id,sub,d,e,before.owner,objects[e.barrierCard].zone) /\ after=[before EXCEPT !.current=id,!.usedInstances=@ \cup {id}] BarrierInstructionBarrierInstructionBound98(p) == /\ BarrierInstructionDefinitionValid98(p.definition,p.barrierInstruction,p.barrierCard) /\ BarrierInstructionDefinitionValid98(p.payload,p.barrierInstruction,p.barrierCard) /\ p.id \in Nat \ {0} /\ p.ability.id=p.id /\ p.ability.kind="BarrierInstruction" /\ p.ability.source=ObjectAbilitySource9(p.barrierCard) /\ p.ability.caller=p.caller /\ p.definition.syntax.id=p.barrierInstruction /\ p.definition.syntax.source=p.ability.source /\ p.payload.syntax.source=p.ability.source /\ p.payload.syntax.kind="BarrierInstruction" /\ p.ability.instructions=p.payload.instructions BarrierInstructionWindowRef98(p) == [origin |-> "BarrierInstruction",id |-> p.id,abilityInstance |-> p.id,index |-> 0,barrierInstruction |-> p.barrierInstruction,encounter |-> p.encounter, source |-> p.ability.source,sourceZone |-> p.ability.sourceZone,ruleStep |-> "NoValue",revision |-> p.revision] BarrierInstructionImminent98(p) == /\ BarrierInstructionBarrierInstructionBound98(p) /\ p.phase="BarrierInstructionImminent" /\ p.ability.phase="Ready" /\ ~p.ability.firstImminent /\ ~p.ability.detached OpenBarrierInstructionInterrupt98(p,before,after,id,site,instances,opening,usedWindows) == /\ BarrierInstructionImminent98(p) /\ BarrierInstructionOwnerAtTop98(p.owner,before) /\ id \in (Nat \ {0}) \ usedWindows /\ id \notin {before[i].id : i \in 1..Len(before)} /\ WindowSiteAllowed9("Interrupt",PriorityOpeningSite9(before,site)) /\ site.structure=p.structure /\ site.step="ProcedureCodef1914978bb8e" /\ opening.tag="PriorityWindowOpening" /\ opening.windowId=id /\ opening.kind="Interrupt" /\ opening.site=site /\ opening.members=DOMAIN instances /\ opening.instances=instances /\ ConditionalGroupValid9(instances,id,opening.group,TRUE) /\ opening.instruction=BarrierInstructionWindowRef98(p) /\ opening.effectRevision \in Nat \ {0} /\ opening.preparation= <<"ExpectedEffects","ReplacementEffects","ConditionalPending">> /\ opening.modifiersExist /\ opening.beginning=NoTimingRef9 /\ after=Append(before,NewPriorityWindow9(id,"Interrupt",PriorityOpeningSite9(before,site),instances,opening.group,NoTimingRef9,opening.instruction,opening.effectRevision)) OpenPreparedBarrierInstructionInterrupt98(p,before,after,id,site,ledger,opening,usedWindows) == OpenBarrierInstructionInterrupt98(p,before,after,id,site,ConditionalWindowMembers96(ledger.instances,id),opening,usedWindows) CreateBarrierInstructionConditionalInterrupt98(before,after,id,d,p,snapshot,prepared,windowId,group,usedWindows) == /\ BarrierInstructionImminent98(p) /\ ConditionalSnapshotBound96(snapshot,before) /\ ConditionalKey96(d) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(d)]=d /\ ConditionalDefinitionValid96(d) /\ ConditionalInterrupt96(d) /\ ConditionalActive96(d,snapshot) /\ id \in (Nat \ {0}) \ DOMAIN before.instances /\ windowId \in (Nat \ {0}) \ usedWindows /\ group \in Nat \ {0} /\ prepared.tag="ConditionalInterruptMatch" /\ prepared.instruction=BarrierInstructionWindowRef98(p) /\ prepared.ability=d.syntax.id /\ prepared.source=d.syntax.source /\ prepared.snapshotId=snapshot.id /\ prepared.matches /\ prepared.occurrence \in Nat \ {0} /\ [definition |-> ConditionalKey96(d),occurrence |-> prepared.occurrence] \notin before.interruptRecognitions /\ IF d.primaryKind="Static" THEN ~ConditionalSibling96(d,before.instances) /\ StaticRetryAllowed96(d,before) ELSE TRUE /\ LET instance == [member |-> ConditionalMember96(id,d,windowId,group),definition |-> ConditionalKey96(d),definitionCopy |-> d,status |-> "Pending", primaryKind |-> d.primaryKind,activationEpoch |-> snapshot.activationEpoch[ConditionalKey96(d)],checkpointId |-> before.lastCheckpoint, occurrence |-> prepared.occurrence,hadSnapshot |-> before.lastSnapshot,expected |-> EmptyOrder98,used |-> FALSE] IN after=[before EXCEPT !.activationEpoch=snapshot.activationEpoch, !.interruptRecognitions=@ \cup {[definition |-> ConditionalKey96(d),occurrence |-> prepared.occurrence]}, !.instances=[i \in DOMAIN @ \cup {id} |-> IF i=id THEN instance ELSE @[i]]] BarrierInstructionInterruptReturnBound98(p,r) == /\ r.tag="BarrierInstructionInterruptReturn" /\ r.barrierInstruction=BarrierInstructionWindowRef98(p) /\ r.complete /\ r.windowId \in Nat /\ r.openingRevision \in Nat /\ r.openingRevision<=p.revision ReturnBarrierInstructionInterrupt98(beforeP,afterP,before,after,r) == /\ BarrierInstructionImminent98(beforeP) /\ BarrierInstructionInterruptReturnBound98(beforeP,r) /\ Len(before)>0 /\ LET w == WindowTop9(before) IN /\ w.kind="Interrupt" /\ w.pending={} /\ r.windowId=w.id /\ w.instruction.origin="BarrierInstruction" /\ w.instruction.id=beforeP.id /\ w.instruction.barrierInstruction=beforeP.barrierInstruction /\ w.instruction.encounter=beforeP.encounter /\ w.instruction.source=beforeP.ability.source /\ w.instruction.sourceZone=beforeP.ability.sourceZone /\ w.instruction.abilityInstance=beforeP.id /\ w.instruction.index=0 /\ r.openingRevision=w.instruction.revision /\ PopClosedPriorityWindow9(before,after) /\ BarrierInstructionOwnerAtTop98(beforeP.owner,after) /\ afterP=[beforeP EXCEPT !.phase="FirstTargets"] NoBarrierInstructionInterrupt98(before,after,stack,noModifiers,r) == /\ BarrierInstructionImminent98(before) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ noModifiers.tag="NoBarrierInstructionInterruptModifiers" /\ noModifiers.barrierInstruction=BarrierInstructionWindowRef98(before) /\ noModifiers.conditionalInstances={} /\ noModifiers.paidInterruptAbilities={} /\ BarrierInstructionInterruptReturnBound98(before,r) /\ r.windowId=0 /\ r.openingRevision=before.revision /\ after=[before EXCEPT !.phase="FirstTargets"] ReplaceBarrierInstructionPayload98(before,after,exampleFamily006,actualReplacement,cardFacts) == /\ BarrierInstructionImminent98(before) /\ ~before.prevented /\ actualReplacement.tag="ExampleFamily006BarrierInstructionReplacement" /\ actualReplacement.barrierInstruction=BarrierInstructionWindowRef98(before) /\ actualReplacement.source=ObjectAbilitySource9(exampleFamily006) /\ actualReplacement.card="Specimen0252" /\ actualReplacement.sourceSHA=cardFacts["Specimen0252"].sourceSHA /\ actualReplacement.applies /\ actualReplacement.payload.kind="BarrierInstructionTemplate" /\ Len(actualReplacement.payload.instructions)>0 /\ LET payload == [before.definition EXCEPT !.instructions=actualReplacement.payload.instructions] IN after=[before EXCEPT !.payload=payload,!.ability.instructions=payload.instructions,!.revision=@+1, !.replacements=Append(@,[source |-> ObjectAbilitySource9(exampleFamily006),original |-> before.barrierInstruction,encounter |-> before.encounter,revision |-> before.revision])] BarrierInstructionModifierAtTop98(p,stack,plan,parent) == /\ Len(stack)>0 /\ BarrierInstructionImminent98(p) /\ LET w == WindowTop9(stack) IN /\ w.kind="Interrupt" /\ w.stage="Resolving" /\ w.busy.id # 0 /\ w.instruction.origin="BarrierInstruction" /\ w.instruction.id=p.id /\ w.instruction.encounter=p.encounter /\ w.instruction.barrierInstruction=p.barrierInstruction /\ w.instruction.source=p.ability.source /\ parent.caller=w.id /\ parent.source=w.busy.source /\ (w.busy.kind="ConditionalInterrupt" => parent.id=w.busy.instance) /\ ConditionalCreationInstruction96(plan,parent,"NoValue") PreventImminentBarrierInstruction98(before,after,stack,plan,parent,actualPrevention) == /\ BarrierInstructionImminent98(before) /\ ~before.prevented /\ BarrierInstructionModifierAtTop98(before,stack,plan,parent) /\ actualPrevention.instruction=InstructionWindowRef93(plan) /\ actualPrevention.tag="BarrierInstructionPrevention" /\ actualPrevention.barrierInstruction=BarrierInstructionWindowRef98(before) /\ actualPrevention.authorized /\ after=[before EXCEPT !.prevented=TRUE,!.revision=@+1] HandlePreventedBarrierInstruction98(beforeLoop,afterLoop,p,e,afterEncounter,stack) == /\ BarrierInstructionBarrierInstructionBound98(p) /\ p.phase="FirstTargets" /\ p.prevented /\ ~p.ability.firstImminent /\ BarrierInstructionLoopMatches98(beforeLoop,e) /\ beforeLoop.current=p.id /\ beforeLoop.encounter=p.encounter /\ e.id=p.encounter /\ BarrierInstructionOwnerAtTop98(p.owner,stack) /\ p.owner=beforeLoop.owner /\ afterEncounter=e /\ afterLoop=[beforeLoop EXCEPT !.current=0,!.handled=@ \cup {p.barrierInstruction},!.prevented=@ \cup {p.barrierInstruction}, !.history=Append(@,[barrierInstruction |-> p.barrierInstruction,instance |-> p.id,disposition |-> "Prevented",source |-> p.ability.source])] EnterFirstBarrierInstructionInstructionCore98(before,after,objects,present,context,points,stack,plan,afterPlan,targets,entry) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="FirstTargets" /\ ~before.prevented /\ BarrierInstructionCurrentActive98(before.definition,objects,present,context,points) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ ~plan.announced /\ entry.sourceEligible=BarrierInstructionCurrentActive98(before.definition,objects,present,context,points) /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [before.ability EXCEPT !.phase="Imminent",!.firstImminent=TRUE,!.detached=TRUE] IN /\ AnnounceInstructionTargets93(plan,announced,targets,before.ability,"NoValue") /\ EnterFirstAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.phase="Imminent"] EnterFirstBarrierInstructionInstruction98(before,after,e,control,orderState,objects,present,context,points,stack,plan,afterPlan,targets,entry) == /\ before.origin="Encounter" /\ before.caller=e.id /\ e.id=before.encounter /\ e.barrierCard=before.barrierCard /\ BarrierInstructionEncounterCurrent98(e,control) /\ orderState.barrierCard=e.barrierCard /\ orderState.order=e.order /\ before.barrierInstruction \in orderState.present /\ orderState.definitions[before.barrierInstruction]=before.definition /\ EnterFirstBarrierInstructionInstructionCore98(before,after,objects,present,context,points,stack,plan,afterPlan,targets,entry) OpenBarrierInstructionInstructionInterrupt98(p,before,after,plan,id,site,instances,opening,usedWindows) == /\ BarrierInstructionBarrierInstructionBound98(p) /\ p.phase="Imminent" /\ BarrierInstructionOwnerAtTop98(p.owner,before) /\ OpenInstructionInterrupt93(before,after,id,site,instances,opening,usedWindows,plan,p.ability,"NoValue") ResolveBarrierInstructionWithoutInterrupt98(before,after,stack,plan,afterPlan,noModifiers,clearance) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="Imminent" /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ NoInstructionInterrupt93(plan,before.ability,"NoValue",noModifiers,clearance) /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] ResolveBarrierInstructionAfterInterrupt98(before,after,beforeStack,afterStack,plan,afterPlan,clearance) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="Imminent" /\ ReturnInstructionInterrupt93(beforeStack,afterStack,plan,before.ability,"NoValue",clearance) /\ BarrierInstructionOwnerAtTop98(before.owner,afterStack) /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] CarryBarrierInstructionInstruction98(before,after,stack,plan,afterPlan,actualStep) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="Resolve" /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ CarryAbilityInstructionStep93(before.ability,after.ability,plan,afterPlan,actualStep) /\ after=[before EXCEPT !.ability=after.ability,!.checkpoint=0,!.phase=IF afterPlan.phase="Complete" THEN "InstructionCheckpoint" ELSE "Resolve"] BarrierInstructionInstructionCaller98(p) == [kind |-> "BarrierInstructionInstruction",encounter |-> p.encounter,barrierInstruction |-> p.barrierInstruction,abilityInstance |-> p.id, source |-> p.ability.source,instruction |-> p.ability.instructions[p.ability.cursor],index |-> p.ability.cursor,windowId |-> p.owner.windowId] BarrierInstructionInstructionCheckpoint98(before,after,stack,ledger,r) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="InstructionCheckpoint" /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ r.tag="BarrierInstructionInstructionCheckpoint" /\ r.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[r.id].caller=BarrierInstructionInstructionCaller98(before) /\ ConditionalCheckpointDrained96(ledger,stack,r.id) /\ r.caller=BarrierInstructionInstructionCaller98(before) /\ r.complete /\ r.allNewerChainsComplete /\ after=[before EXCEPT !.checkpoint=r.id,!.phase=IF before.ability.lastFinished THEN "AbilityComplete" ELSE "Targets"] EnterNextBarrierInstructionInstruction98(before,after,stack,plan,afterPlan,targets,entry) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="Targets" /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ before.checkpoint \in Nat \ {0} /\ entry.checkpointId=before.checkpoint /\ ~plan.announced /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [before.ability EXCEPT !.cursor=@+1,!.phase="Imminent"] IN /\ AnnounceInstructionTargets93(plan,announced,targets,before.ability,"NoValue") /\ EnterNextAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.checkpoint=0,!.phase="Imminent"] FinishBarrierInstruction98(beforeLoop,afterLoop,before,after,e,afterEncounter,stack) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ before.phase="AbilityComplete" /\ before.checkpoint \in Nat \ {0} /\ BarrierInstructionLoopMatches98(beforeLoop,e) /\ before.origin="Encounter" /\ beforeLoop.current=before.id /\ beforeLoop.encounter=before.encounter /\ e.id=before.encounter /\ e.barrierCard=before.barrierCard /\ beforeLoop.owner=before.owner /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ ReturnAbility9(before.ability,after.ability,TRUE,before.caller) /\ after=[before EXCEPT !.ability=after.ability,!.phase="Returned"] /\ afterEncounter=[e EXCEPT !.resolved=@ \cup {before.barrierInstruction}] /\ afterLoop=[beforeLoop EXCEPT !.current=0,!.handled=@ \cup {before.barrierInstruction},!.resolved=@ \cup {before.barrierInstruction}, !.history=Append(@,[barrierInstruction |-> before.barrierInstruction,instance |-> before.id,disposition |-> "Resolved",source |-> before.ability.source])] CompleteBarrierInstructionEncounter98(loop,e,after,control,step,stack,actualReturn) == /\ BarrierInstructionLoopMatches98(loop,e) /\ loop.current=0 /\ BarrierInstructionEncounterCurrent98(e,control) /\ e.stage="BarrierInstructions" /\ step="ProcedureCode687f72772ab1" /\ (e.forced \/ control.traversal.step=step) /\ RemainingBarrierInstructions98(loop,e)={} /\ BarrierInstructionOwnerAtTop98(loop.owner,stack) /\ actualReturn.tag="EncounterBarrierInstructionsReturn" /\ actualReturn.encounter=e.id /\ actualReturn.handled=loop.handled /\ actualReturn.complete /\ actualReturn.allNewerChainsComplete /\ after=[e EXCEPT !.stage="Complete"] AdvanceBarrierInstructionStep98(loop,before,after,e,forcedStep,afterForcedStep,actualReturn) == /\ BarrierInstructionLoopMatches98(loop,e) /\ loop.current=0 /\ BarrierInstructionStep98(e,before,forcedStep) /\ actualReturn.tag="BarrierInstructionLoopStepReturn" /\ actualReturn.encounter=e.id /\ actualReturn.complete /\ actualReturn.normalCheckpointAndReactionsDrained /\ actualReturn.history=loop.history /\ actualReturn.attempt \in Nat /\ IF actualReturn.attempt=0 THEN RemainingBarrierInstructions98(loop,e)={} ELSE Len(loop.history)>0 /\ loop.history[Len(loop.history)].instance=actualReturn.attempt /\ LET next == IF actualReturn.attempt=0 THEN "ProcedureCode687f72772ab1" ELSE "ProcedureCodeaa0828fbf852" IN /\ IF e.forced THEN after=before /\ afterForcedStep=next ELSE after=[before EXCEPT !.traversal.step=next] /\ afterForcedStep=next ResolvedBarrierInstructionCount98(loop,calls,barrierCard,encounter) == (IF loop.encounter=encounter THEN Cardinality({h \in 1..Len(loop.history) : loop.history[h].source=ObjectAbilitySource9(barrierCard) /\ loop.history[h].disposition="Resolved"}) ELSE 0) + Cardinality({call \in DOMAIN calls : calls[call].encounter=encounter /\ calls[call].source=ObjectAbilitySource9(barrierCard) /\ calls[call].status="Returned" /\ calls[call].disposition="Resolved"}) NestedBarrierInstructionInvocation98(p,parentPlan,parent,ruleStep,actualEffect) == /\ p.origin="Instruction" /\ ConditionalCreationInstruction96(parentPlan,parent,ruleStep) /\ p.invocation=actualEffect /\ actualEffect.tag="ExplicitResolveBarrierInstruction" /\ actualEffect.instruction=InstructionWindowRef93(parentPlan) /\ p.caller=parentPlan.id /\ actualEffect.barrierCard=p.barrierCard /\ actualEffect.barrierInstruction=p.barrierInstruction /\ actualEffect.structure=p.structure /\ actualEffect.encounter=p.encounter /\ actualEffect.authorized EnterInstructionBarrierInstruction98(beforeCalls,afterCalls,p,parentPlan,parent,ruleStep,actualEffect,orderState,id,usedInstances,owner,stack,objects,present,activity,points,cardFacts) == /\ ConditionalCreationInstruction96(parentPlan,parent,ruleStep) /\ BarrierInstructionOwnerAtTop98(owner,stack) /\ actualEffect.id \in (Nat \ {0}) \ DOMAIN beforeCalls /\ ~\E call \in DOMAIN beforeCalls : beforeCalls[call].instruction=InstructionWindowRef93(parentPlan) /\ beforeCalls[call].status="Active" /\ actualEffect.step=parentPlan.cursor /\ afterCalls=[call \in DOMAIN beforeCalls \cup {actualEffect.id} |-> IF call=actualEffect.id THEN [instruction |-> InstructionWindowRef93(parentPlan),instance |-> id,status |-> "Active",source |-> ObjectAbilitySource9(actualEffect.barrierCard),encounter |-> actualEffect.encounter,barrierInstruction |-> actualEffect.barrierInstruction,disposition |-> "NoValue"] ELSE beforeCalls[call]] /\ id \in (Nat \ {0}) \ usedInstances /\ BarrierInstructionOrderValid98(orderState) /\ actualEffect.barrierCard=orderState.barrierCard /\ actualEffect.barrierInstruction \in orderState.present /\ TimingRefValid9(actualEffect.structure) /\ actualEffect.encounter \in Nat /\ actualEffect.sourceCard \in DOMAIN cardFacts /\ actualEffect.sourceSHA=cardFacts[actualEffect.sourceCard].sourceSHA /\ actualEffect.origin.tag="FixedAbilitySourceObservation" /\ actualEffect.origin.source=parentPlan.source /\ actualEffect.origin.card=actualEffect.sourceCard /\ actualEffect.origin.sourceSHA=actualEffect.sourceSHA /\ actualEffect.selector \in {"AnotherItemActivatedBarrier","AnotherItemActivatedSubtypeClass024","NormalizedBarrierInstructionSelection"} /\ actualEffect.barrierCard \in DOMAIN objects /\ objects[actualEffect.barrierCard].kind="Barrier" /\ actualEffect.selector \in {"AnotherItemActivatedBarrier","AnotherItemActivatedSubtypeClass024"} => actualEffect.barrierCard # parentPlan.source.object /\ ActivationStatus8(objects[actualEffect.barrierCard])="ItemActivated" /\ actualEffect.selector="AnotherItemActivatedSubtypeClass024" => "SchemaAtom024" \in actualEffect.currentSubtypes /\ LET d == orderState.definitions[actualEffect.barrierInstruction] base == NewBarrierInstructionBarrierInstruction98(id,actualEffect.barrierInstruction,d, [id |-> actualEffect.encounter,barrierCard |-> actualEffect.barrierCard],owner,objects[actualEffect.barrierCard].zone) IN /\ BarrierInstructionCurrentActive98(d,objects,present,activity,points) /\ p=[base EXCEPT !.origin="Instruction",!.caller=parentPlan.id,!.ability.caller=parentPlan.id, !.structure=actualEffect.structure,!.invocation=actualEffect] /\ NestedBarrierInstructionInvocation98(p,parentPlan,parent,ruleStep,actualEffect) EnterFirstInstructionBarrierInstruction98(before,after,parentPlan,parent,ruleStep,orderState,objects,present,activity,points,stack,plan,afterPlan,targets,entry) == /\ NestedBarrierInstructionInvocation98(before,parentPlan,parent,ruleStep,before.invocation) /\ orderState.barrierCard=before.barrierCard /\ before.barrierInstruction \in orderState.present /\ orderState.definitions[before.barrierInstruction]=before.definition /\ EnterFirstBarrierInstructionInstructionCore98(before,after,objects,present,activity,points,stack,plan,afterPlan,targets,entry) ReturnInstructionBarrierInstruction98(beforeCalls,afterCalls,before,after,parentPlan,parent,ruleStep,stack,actualReturn) == /\ BarrierInstructionBarrierInstructionBound98(before) /\ NestedBarrierInstructionInvocation98(before,parentPlan,parent,ruleStep,before.invocation) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ before.invocation.id \in DOMAIN beforeCalls /\ beforeCalls[before.invocation.id]=[instruction |-> InstructionWindowRef93(parentPlan),instance |-> before.id,status |-> "Active",source |-> before.ability.source,encounter |-> before.encounter,barrierInstruction |-> before.barrierInstruction,disposition |-> "NoValue"] /\ actualReturn.tag="NestedBarrierInstructionReturn" /\ actualReturn.instruction=InstructionWindowRef93(parentPlan) /\ actualReturn.invocation=before.invocation.id /\ actualReturn.instance=before.id /\ actualReturn.source=before.ability.source /\ actualReturn.barrierInstruction=before.barrierInstruction /\ actualReturn.complete /\ IF before.prevented THEN /\ before.phase="FirstTargets" /\ ~before.ability.firstImminent /\ actualReturn.disposition="Prevented" /\ actualReturn.finalCheckpoint=0 /\ after=[before EXCEPT !.phase="PreventedReturn"] ELSE /\ before.phase="AbilityComplete" /\ before.checkpoint \in Nat \ {0} /\ actualReturn.disposition="Resolved" /\ actualReturn.finalCheckpoint=before.checkpoint /\ ReturnAbility9(before.ability,after.ability,TRUE,before.caller) /\ after=[before EXCEPT !.ability=after.ability,!.phase="Returned"] /\ afterCalls=[beforeCalls EXCEPT ![before.invocation.id].status="Returned",![before.invocation.id].disposition=actualReturn.disposition] CarryBarrierInstructionChildReturn98(beforeCalls,afterCalls,before,after,stack,plan,afterPlan,step,beforeChild,afterChild,childReturn) == /\ ReturnInstructionBarrierInstruction98(beforeCalls,afterCalls,beforeChild,afterChild,plan,before.ability,"NoValue",stack,childReturn) /\ step.childReturn=childReturn /\ CarryBarrierInstructionInstruction98(before,after,stack,plan,afterPlan,step) EncounterSuppressInstructionRef98(e) == [kind |-> "Encounter",id |-> e.id,barrierCard |-> e.barrierCard,traversalId |-> e.traversalId] CurrentUnsuppressedBarrierInstructions98(e) == SubIds6(e.order) \ e.barrierInstructionSuppressed EncounterSubStatus98(e,sub) == IF sub \notin e.usedSubIds THEN "Absent" ELSE IF sub \in e.barrierInstructionSuppressed THEN "BarrierInstructionSuppressed" ELSE "UnsuppressedBarrierInstructions" SuppressInstructionEncounterEnded98(e,control) == e.stage="Complete" \/ e.aborted \/ e.id \in control.phaseEndedIds \/ (e.traversalId # 0 /\ (e.traversalId # control.traversal.id \/ ~TraversalTimingPresent6(control.traversal))) SuppressInstructionEncounterCurrent98(e,control) == EncounterTimingLive95(e,control) /\ control.encounter=e.id NormalizedSuppressInstructionClassification98(d,objects,cardFacts,classification) == /\ d.syntax.kind="Paid" /\ d.canSuppressBarrierInstructions /\ d.syntax.source.kind="Object" /\ d.syntax.source.object \in DOMAIN objects /\ classification.tag="NormalizedSuppressInstructionInstruction" /\ classification.ability=d.syntax.id /\ classification.source=d.syntax.source /\ classification.card=objects[d.syntax.source.object].card /\ classification.sourceSHA=cardFacts[classification.card].sourceSHA /\ classification.instruction \in SubIds6(d.instructions) /\ classification.mode \in {"Ordinary","All","Hook"} /\ classification.selector \in {"SchemaAtom016","Last"} /\ classification.minimumTargets \in Nat /\ classification.maximumTargets \in Nat /\ classification.minimumTargets<=classification.maximumTargets /\ IF classification.mode="Ordinary" THEN classification.maximumTargets>0 ELSE IF classification.mode="Hook" THEN classification.minimumTargets=1 /\ classification.maximumTargets=1 /\ classification.selector="SchemaAtom016" ELSE classification.minimumTargets=0 /\ classification.maximumTargets=0 /\ classification.selector="SchemaAtom016" NewSuppressInstructionIntent98(p,e,classification) == [tag |-> "SuppressInstructionActivation",definition |-> p.definition,abilityInstance |-> p.id,ability |-> p.definition.syntax.id,source |-> p.ability.source, windowId |-> p.windowId,transactionId |-> p.transaction,encounter |-> EncounterSuppressInstructionRef98(e),classification |-> classification] SuppressInstructionIntentMatches98(intent,p) == /\ intent.tag="SuppressInstructionActivation" /\ intent.definition=p.definition /\ intent.abilityInstance=p.id /\ intent.ability=p.definition.syntax.id /\ intent.source=p.ability.source /\ intent.source=p.definition.syntax.source /\ intent.source.kind="Object" /\ intent.windowId=p.windowId /\ intent.transactionId=p.transaction /\ intent.classification.ability=intent.ability /\ intent.classification.source=intent.source ReserveSuppressInstructionAbility98(beforeStack,afterStack,p,id,d,c,option,legality,usedInstances,classification,intent,cardFacts) == /\ NormalizedSuppressInstructionClassification98(d,c.objects,cardFacts,classification) /\ SuppressInstructionEncounterCurrent98(c.encounter,c.traversalControl) /\ classification.mode="All" => CurrentUnsuppressedBarrierInstructions98(c.encounter) # {} /\ classification.mode="Hook" => SubIds6(c.encounter.order) # {} /\ ReservePaidAbility95(beforeStack,afterStack,p,id,d,c,option,legality,usedInstances) /\ intent=NewSuppressInstructionIntent98(p,c.encounter,classification) SuppressInstructionOrdinaryCandidates98(e,classification) == CurrentUnsuppressedBarrierInstructions98(e) \cap (IF classification.selector="Last" THEN IF Len(e.order)=0 THEN {} ELSE {e.order[Len(e.order)]} ELSE SubIds6(e.order)) SuppressInstructionTargetsValid98(intent,e,control,targets) == /\ EncounterSuppressInstructionRef98(e)=intent.encounter /\ IF SuppressInstructionEncounterEnded98(e,control) THEN targets={} ELSE /\ SuppressInstructionEncounterCurrent98(e,control) /\ CASE intent.classification.mode="All" -> targets={} [] intent.classification.mode="Hook" -> targets \subseteq SubIds6(e.order) /\ Cardinality(targets)=IF Len(e.order)=0 THEN 0 ELSE 1 [] OTHER -> LET available == SuppressInstructionOrdinaryCandidates98(e,intent.classification) minimum == IF Cardinality(available)=minimum /\ Cardinality(targets)<=intent.classification.maximumTargets NewSuppressInstructionSelection98(intent,imminentPlan,targets) == [tag |-> "SuppressInstructionTargets",NeutralValue00003 |-> intent,instruction |-> InstructionWindowRef93(imminentPlan),targets |-> targets] EnterSuppressInstructionInstruction98(stack,before,after,plan,afterPlan,targets,entry,intent,e,control,selection) == /\ SuppressInstructionIntentMatches98(intent,before) /\ plan.id=intent.classification.instruction /\ SuppressInstructionTargetsValid98(intent,e,control,targets.targets) /\ EnterPaidInstruction95(stack,before,after,plan,afterPlan,targets,entry) /\ selection=NewSuppressInstructionSelection98(intent,afterPlan,targets.targets) SuppressInstructionSelectionMatches98(intent,selection,plan) == /\ selection.tag="SuppressInstructionTargets" /\ selection.NeutralValue00003=intent /\ InstructionProfileMatches93(selection.instruction,plan) /\ selection.instruction.revision<=plan.revision /\ selection.targets=plan.targets ResolvePaidSuppressInstructionInstruction98(before,after,control,stack,p,plan,intent,selection,actualEffect,events) == /\ SuppressInstructionIntentMatches98(intent,p) /\ EncounterSuppressInstructionRef98(before)=intent.encounter /\ PaidProcedureAtTop95(stack,p) /\ p.phase="Resolve" /\ p.costPaid /\ p.ability.phase="Resolving" /\ plan.phase="Resolving" /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ plan.id=intent.classification.instruction /\ SuppressInstructionSelectionMatches98(intent,selection,plan) /\ actualEffect.tag="NormalizedSuppressInstructionResolution" /\ actualEffect.instruction=InstructionWindowRef93(plan) /\ actualEffect.abilityInstance=p.id /\ actualEffect.source=intent.source /\ actualEffect.encounter=intent.encounter /\ actualEffect.classification=intent.classification /\ actualEffect.operation \in {"SuppressInstruction","NoEffects"} /\ IF SuppressInstructionEncounterEnded98(before,control) THEN after=before /\ events={} ELSE /\ SuppressInstructionEncounterCurrent98(before,control) /\ LET subs == IF actualEffect.operation="NoEffects" THEN {} ELSE CASE intent.classification.mode="All" -> CurrentUnsuppressedBarrierInstructions98(before) [] intent.classification.mode="Hook" -> CurrentUnsuppressedBarrierInstructions98(before) \ selection.targets [] OTHER -> SuppressInstructionOrdinaryCandidates98(before,intent.classification) \cap selection.targets IN IF subs={} THEN after=before /\ events={} ELSE SuppressInstructionEncounterSubs6(before,after,subs,intent.source.object,TRUE,p.costPaid,events) InstructionSuppressInstructionClassification98(plan,classification) == /\ classification.tag="NormalizedInstructionSuppressInstruction" /\ classification.instruction=InstructionWindowRef93(plan) /\ classification.mode \in {"Ordinary","All","Hook"} /\ classification.selector \in {"SchemaAtom016","Last"} /\ classification.minimumTargets \in Nat /\ classification.maximumTargets \in Nat /\ classification.minimumTargets<=classification.maximumTargets /\ IF classification.mode="Ordinary" THEN classification.maximumTargets>0 ELSE IF classification.mode="Hook" THEN classification.minimumTargets=1 /\ classification.maximumTargets=1 /\ classification.selector="SchemaAtom016" ELSE classification.minimumTargets=0 /\ classification.maximumTargets=0 /\ classification.selector="SchemaAtom016" NewInstructionSuppressInstructionIntent98(plan,e,classification) == [tag |-> "InstructionSuppressInstructionTargetContext",instruction |-> InstructionWindowRef93(plan),encounter |-> EncounterSuppressInstructionRef98(e),classification |-> classification] AnnounceSuppressInstructionInstructionTargets98(before,announced,parent,ruleStep,classification,intent,e,control,targets,selection) == /\ InstructionSuppressInstructionClassification98(before,classification) /\ intent=NewInstructionSuppressInstructionIntent98(before,e,classification) /\ SuppressInstructionTargetsValid98(intent,e,control,targets.targets) /\ AnnounceInstructionTargets93(before,announced,targets,parent,ruleStep) /\ selection=NewSuppressInstructionSelection98(intent,announced,targets.targets) EnterFirstSuppressInstructionInstruction98(beforeAbility,afterAbility,before,after,e,control,classification,intent,targets,entry,selection) == /\ beforeAbility.kind \in {"Conditional","BarrierInstruction","Play"} /\ LET announced == [before EXCEPT !.announced=TRUE,!.targets=targets.targets] IN /\ AnnounceSuppressInstructionInstructionTargets98(before,announced,beforeAbility,"NoValue",classification,intent,e,control,targets,selection) /\ EnterFirstAbilityInstruction93(beforeAbility,afterAbility,announced,after,entry) EnterNextSuppressInstructionInstruction98(beforeAbility,afterAbility,before,after,e,control,classification,intent,targets,entry,selection) == /\ beforeAbility.kind \in {"Conditional","BarrierInstruction","Play"} /\ LET announced == [before EXCEPT !.announced=TRUE,!.targets=targets.targets] IN /\ AnnounceSuppressInstructionInstructionTargets98(before,announced,beforeAbility,"NoValue",classification,intent,e,control,targets,selection) /\ EnterNextAbilityInstruction93(beforeAbility,afterAbility,announced,after,entry) EnterRuleSuppressInstructionInstruction98(before,after,ruleStep,e,control,classification,intent,targets,selection) == /\ LET announced == [before EXCEPT !.announced=TRUE,!.targets=targets.targets] IN /\ AnnounceSuppressInstructionInstructionTargets98(before,announced,[id \in {} |-> id],ruleStep,classification,intent,e,control,targets,selection) /\ EnterRuleInstruction93(announced,after,ruleStep) BarrierInstructionOrderPublicationStep98(before,after) == /\ BarrierInstructionOrderValid98(before) /\ BarrierInstructionOrderValid98(after) /\ SelfCategoryIdentical98(after) /\ after.barrierCard=before.barrierCard /\ after.clock=before.clock+1 /\ Len(after.history)=Len(before.history)+1 /\ SubSeq(after.history,1,Len(before.history))=before.history /\ before.usedIds \subseteq after.usedIds /\ OrderPreserves98(after.spine,before.spine) /\ after.printedText=before.printedText /\ \A id \in before.usedIds : after.definitions[id]=before.definitions[id] /\ after.provenance[id]=before.provenance[id] /\ \A id \in DOMAIN before.applications : id \in DOMAIN after.applications /\ after.applications[id]=before.applications[id] /\ LET step == after.history[Len(after.history)] gained == after.present \ before.present lost == before.present \ after.present IN /\ step.kind \in {"OrdinaryGain","SideADeclaredGain","SelfStaticResize","PrintedResize","TLDRCopy","Loss"} /\ step.clock=after.clock /\ step.gained=gained /\ step.lost=lost /\ after.usedIds=before.usedIds \cup gained /\ gained \cap before.usedIds={} /\ step.decision \notin DOMAIN before.decisions /\ DOMAIN after.decisions=DOMAIN before.decisions \cup {step.decision} /\ \A id \in DOMAIN before.decisions : after.decisions[id]=before.decisions[id] /\ IF step.kind="Loss" THEN /\ DOMAIN after.applications=DOMAIN before.applications /\ step.applications \subseteq before.activeApplications /\ after.activeApplications=before.activeApplications \ step.applications ELSE /\ DOMAIN after.applications=DOMAIN before.applications \cup step.applications /\ DOMAIN before.applications \cap step.applications={} /\ after.activeApplications=before.activeApplications \cup step.applications /\ \A id \in step.applications : after.applications[id].clock=after.clock NewEncounterBarrierInstructionOrderPublication98(encounter,before,after) == LET step == after.history[Len(after.history)] IN [tag |-> "AppliedEncounterBarrierInstructionOrder",encounterBefore |-> encounter,beforeOrderState |-> before,afterOrderState |-> after, appliedStep |-> step,appliedOrderingDecision |-> after.decisions[step.decision]] PublishEncounterBarrierInstructionOrder98(beforeE,afterE,beforeOrder,afterOrder,boundPublication,events) == /\ BarrierInstructionOrderPublicationStep98(beforeOrder,afterOrder) /\ beforeE.barrierCard=beforeOrder.barrierCard /\ beforeE.order=beforeOrder.order /\ beforeE.usedSubIds \subseteq beforeOrder.usedIds /\ beforeOrder.present \subseteq beforeE.usedSubIds /\ DOMAIN beforeE.barrierInstructionSuppressedBy=beforeE.usedSubIds /\ beforeE.barrierInstructionSuppressed \cup beforeE.resolved \subseteq beforeE.usedSubIds /\ boundPublication=NewEncounterBarrierInstructionOrderPublication98(beforeE,beforeOrder,afterOrder) /\ UpdateEncounterSubs6(beforeE,afterE,afterOrder.order,TRUE,events) /\ LET gained == afterOrder.present \ beforeOrder.present IN /\ afterE.usedSubIds=beforeE.usedSubIds \cup gained /\ afterE.usedSubIds \subseteq afterOrder.usedIds /\ gained \cap afterE.barrierInstructionSuppressed={} /\ gained \cap afterE.resolved={} /\ \A id \in gained : afterE.barrierInstructionSuppressedBy[id]=0 /\ afterE.barrierInstructionSuppressed=beforeE.barrierInstructionSuppressed /\ afterE.resolved=beforeE.resolved /\ \A id \in beforeE.usedSubIds : afterE.barrierInstructionSuppressedBy[id]=beforeE.barrierInstructionSuppressedBy[id] ExpectedValueKinds99 == {"Damage","ExposureMarkers","Cost","EscalatingResourceContest"} ExpectedEffectValid99(id,effect) == /\ id \in Nat \ {0} /\ effect.id=id /\ effect.kind \in STRING /\ (effect.kind \in ExpectedValueKinds99 => effect.value \in Int) /\ (effect.kind="Damage" => effect.damageType \in {"HarmClassA","HarmClassB","PersistentCapacityHarm"}) ExpectedEffectsValid99(effects) == \A id \in DOMAIN effects : ExpectedEffectValid99(id,effects[id]) ExpectedValuePresent99(effects,id) == id \in DOMAIN effects /\ effects[id].kind \in ExpectedValueKinds99 SetExpectedEffectValue99(before,after,id,value) == /\ ExpectedEffectsValid99(before) /\ ExpectedValuePresent99(before,id) /\ value \in Int /\ after=[before EXCEPT ![id].value=value] ModifyExpectedEffectValue99(before,after,id,delta) == /\ ExpectedValuePresent99(before,id) /\ delta \in Int /\ SetExpectedEffectValue99(before,after,id,before[id].value+delta) ExpectedEffectPreventable99(effects,id) == id \in DOMAIN effects /\ "preventable" \in DOMAIN effects[id] /\ effects[id].preventable PreventExpectedAmount99(before,after,id,amount) == /\ ExpectedEffectsValid99(before) /\ id \in DOMAIN before /\ before[id].kind \in {"Damage","ExposureMarkers"} /\ amount \in Nat /\ ExpectedEffectPreventable99(before,id) /\ SetExpectedEffectValue99(before,after,id,before[id].value-amount) PreventExpectedWhole99(before,after,id) == /\ ExpectedEffectsValid99(before) /\ ExpectedEffectPreventable99(before,id) /\ after=[effect \in DOMAIN before \ {id} |-> before[effect]] PreventExpectedAllDamageOrExposureMarkers99(before,after,id) == /\ id \in DOMAIN before /\ before[id].kind \in {"Damage","ExposureMarkers"} /\ PreventExpectedWhole99(before,after,id) ExampleFamily091Relevant99(effects,id) == /\ ExpectedValuePresent99(effects,id) /\ effects[id].kind="Damage" /\ effects[id].damageType="HarmClassA" /\ effects[id].value>=2 /\ ExpectedEffectPreventable99(effects,id) ExampleFamily091HarmClassAToOne99(before,after,id) == /\ ExampleFamily091Relevant99(before,id) /\ SetExpectedEffectValue99(before,after,id,1) ActualExpectedEffects99(effects) == [id \in {effect \in DOMAIN effects : effects[effect].kind \notin {"Damage","ExposureMarkers"} \/ effects[effect].value>0} |-> IF effects[id].kind="Cost" THEN [effects[id] EXCEPT !.value=ModifiedCost(@,<<>>,<<>>)] ELSE effects[id]] ExpectedValueOperationReceipt99(id,operation,source,effect,before,after) == [tag |-> "ExpectedValueOperation",id |-> id,operation |-> operation,source |-> source,effectId |-> effect, beforeEffects |-> before,afterEffects |-> after] ResolvedExpectedInterrupt99(before,after,actualResolved) == /\ ExpectedEffectsValid99(before) /\ ExpectedEffectsValid99(after) /\ actualResolved.tag="ResolvedInterruptEffectModification" /\ actualResolved.status="Resolved" /\ actualResolved.classification="Interrupt" /\ actualResolved.abilityKind \in {"Paid","Conditional"} /\ actualResolved.id \in Nat \ {0} /\ actualResolved.abilityInstance \in Nat \ {0} /\ actualResolved.source.kind \in {"Object","Rule"} /\ IF actualResolved.source.kind="Object" THEN actualResolved.source.object \in Nat \ {0} ELSE actualResolved.source.rule # "NoValue" /\ actualResolved.beforeEffects=before /\ actualResolved.afterEffects=after /\ actualResolved.revisionBefore \in Nat /\ actualResolved.revisionAfter=actualResolved.revisionBefore+1 PositiveBeforeEffect99(before,id) == id \in DOMAIN before /\ before[id].kind \in {"Damage","ExposureMarkers"} /\ before[id].value>0 PreventedPositiveAmount99(before,after,id) == IF ~PositiveBeforeEffect99(before,id) THEN 0 ELSE LET remaining == IF id \notin DOMAIN after THEN 0 ELSE IF after[id].kind # before[id].kind THEN 0 ELSE MaxOf(0,after[id].value) IN MaxOf(0,before[id].value-remaining) PositivePreventionObserved99(before,after,id,actualResolved) == /\ ResolvedExpectedInterrupt99(before,after,actualResolved) /\ actualResolved.operation \in {"PreventAmount","PreventWhole","ExampleFamily091HarmClassAToOne"} /\ PreventedPositiveAmount99(before,after,id)>0 PositivePreventionObservations99(before,after,actualResolved) == {[tag |-> "ExpectedPreventionObservation",kind |-> IF before[id].kind="ExposureMarkers" THEN "AvoidExposureMarker" ELSE "PreventDamage", effectId |-> id,amount |-> PreventedPositiveAmount99(before,after,id),source |-> actualResolved.source, interruptInstance |-> actualResolved.abilityInstance,operationId |-> actualResolved.id,instruction |-> actualResolved.instruction] : id \in {effect \in DOMAIN before : PositivePreventionObserved99(before,after,effect,actualResolved)}} ExampleFamily025PreventionObserved99(before,after,conditionalSource,actualResolved) == /\ ResolvedExpectedInterrupt99(before,after,actualResolved) /\ conditionalSource.kind="Object" /\ conditionalSource.object \in Nat \ {0} /\ actualResolved.source=conditionalSource /\ \E id \in DOMAIN before : before[id].kind="Damage" /\ before[id].value>0 /\ (IF id \notin DOMAIN after THEN TRUE ELSE IF after[id].kind # "Damage" THEN TRUE ELSE after[id].value IF field \in DOMAIN patch THEN patch[field] ELSE base[field]] ReplacementTechniqueValid99(technique) == /\ technique.tag="CompositeEffectTechnique" /\ Len(technique.steps)>0 /\ \A index \in 1..Len(technique.steps) : /\ technique.steps[index].tag="EffectTechniqueStep" /\ technique.steps[index].operation \in STRING /\ \A prior \in technique.steps[index].reads : prior \in 1..(index-1) ReplacementEffectValid99(id,effect) == /\ ExpectedEffectValid99(id,effect) /\ effect.lineage \in Nat \ {0} /\ effect.baseController \in SetupPlayers /\ effect.targeted \in BOOLEAN /\ effect.targetCard \in Nat /\ (effect.targeted => effect.targetCard>0) /\ effect.baseOrigin.kind \in {"Object","Rule"} /\ (effect.kind="CompositeTechnique" => ReplacementTechniqueValid99(effect.technique)) ReplacementEffectsValid99(effects) == \A id \in DOMAIN effects : ReplacementEffectValid99(id,effects[id]) ReplacementStateValid99(state) == /\ ReplacementEffectsValid99(state.effects) /\ DOMAIN state.effects \subseteq state.usedEffectIds /\ DOMAIN state.ancestry=DOMAIN state.effects /\ \A id \in DOMAIN state.ancestry : state.ancestry[id] \subseteq Nat \ {0} /\ state.usedEffectIds \subseteq Nat \ {0} /\ \A pair \in state.appliedPairs : /\ Len(pair)=2 /\ pair[1] \in Nat \ {0} /\ pair[2] \in Nat \ {0} ReplacementPatternValid99(pattern) == /\ "kind" \in DOMAIN pattern /\ pattern.kind \in STRING /\ DOMAIN pattern \subseteq {"kind","damageType","targetCard","affectedCard","targetSite","actor","minValue"} /\ ("minValue" \in DOMAIN pattern => pattern.minValue \in Int) ReplacementPatternMatches99(pattern,effect) == /\ effect.kind=pattern.kind /\ \A field \in DOMAIN pattern \ {"kind","minValue"} : IF field \in DOMAIN effect THEN effect[field]=pattern[field] ELSE FALSE /\ IF "minValue" \in DOMAIN pattern THEN IF "value" \in DOMAIN effect THEN effect.value>=pattern.minValue ELSE FALSE ELSE TRUE ReplacementBodyValid99(body) == /\ DOMAIN body \cap ReplacementReserved99={} /\ body.kind \in STRING /\ body.targeted \in BOOLEAN /\ body.targetCard \in Nat /\ (body.targeted => body.targetCard>0) /\ (body.kind="CompositeTechnique" => ReplacementTechniqueValid99(body.technique)) ReplacementBlueprintValid99(id,replacement) == /\ id \in Nat \ {0} /\ replacement.id=id /\ replacement.source.kind \in {"Object","Rule"} /\ replacement.sourceSHA \in STRING /\ IF replacement.source.kind="Object" THEN replacement.source.object \in Nat \ {0} ELSE replacement.source.rule # "NoValue" /\ ReplacementPatternValid99(replacement.pattern) /\ replacement.behavior.mode \in {"Patch","Replace"} /\ IF replacement.behavior.mode="Patch" THEN DOMAIN replacement.behavior.fields \cap ReplacementReserved99={} ELSE \A index \in 1..Len(replacement.behavior.results) : ReplacementBodyValid99(replacement.behavior.results[index]) ReplacementBlueprintsValid99(replacements) == \A id \in DOMAIN replacements : ReplacementBlueprintValid99(id,replacements[id]) ReplacementPair99(replacement,effect) == <> EligibleReplacements99(state,effectId,replacements) == IF effectId \notin DOMAIN state.effects THEN {} ELSE {id \in DOMAIN replacements : id \notin state.ancestry[effectId] /\ ReplacementPatternMatches99(replacements[id].pattern,state.effects[effectId])} ReplacementController99(effect,world) == IF effect.targeted THEN world.controllers[effect.targetCard] ELSE effect.baseController NewReplacementState99(effects) == [effects |-> effects,ancestry |-> [id \in DOMAIN effects |-> {}],appliedPairs |-> {},usedEffectIds |-> DOMAIN effects,transformations |-> <<>>] ReplacementResult99(effect,body,id) == ReplacementOverlay99(body,[id |-> id,lineage |-> effect.lineage,baseController |-> effect.baseController,baseOrigin |-> effect.baseOrigin]) ReplacementOutputs99(effect,replacement,resultIds) == IF replacement.behavior.mode="Patch" THEN [id \in {effect.id} |-> ReplacementOverlay99(effect,replacement.behavior.fields)] ELSE [id \in SubIds6(resultIds) |-> ReplacementResult99(effect,replacement.behavior.results[CHOOSE index \in 1..Len(resultIds) : resultIds[index]=id],id)] ReplacementOutputIdsValid99(state,effect,replacement,resultIds) == IF replacement.behavior.mode="Patch" THEN resultIds= <> ELSE /\ Len(resultIds)=Len(replacement.behavior.results) /\ DeckSequenceValid4(resultIds) /\ SubIds6(resultIds) \subseteq Nat \ {0} /\ SubIds6(resultIds) \cap state.usedEffectIds={} ReplacementDecision99(state,effectId,replacements,world,chosen,resultIds) == [tag |-> "ReplacementOrderDecision",inputEffect |-> state.effects[effectId],eligible |-> EligibleReplacements99(state,effectId,replacements), replacements |-> replacements,worldSnapshotId |-> world.id,controller |-> ReplacementController99(state.effects[effectId],world), chosen |-> chosen,resultIds |-> resultIds] ReplacementNextState99(state,effectId,replacements,chosen,resultIds,decision) == LET effect == state.effects[effectId] outputs == ReplacementOutputs99(effect,replacements[chosen],resultIds) effects == ReplacementOverlay99([id \in DOMAIN state.effects \ {effectId} |-> state.effects[id]],outputs) ancestry == ReplacementOverlay99([id \in DOMAIN state.ancestry \ {effectId} |-> state.ancestry[id]], [id \in DOMAIN outputs |-> state.ancestry[effectId] \cup {chosen}]) IN [effects |-> effects,ancestry |-> ancestry,appliedPairs |-> state.appliedPairs \cup {ReplacementPair99(chosen,effect)}, usedEffectIds |-> state.usedEffectIds \cup DOMAIN outputs,transformations |-> Append(state.transformations,decision)] ApplyReplacementStep99(before,after,effectId,replacements,world,decision) == /\ ReplacementStateValid99(before) /\ ReplacementBlueprintsValid99(replacements) /\ world.id \in Nat \ {0} /\ (\A card \in DOMAIN world.controllers : world.controllers[card] \in SetupPlayers) /\ effectId \in DOMAIN before.effects /\ (before.effects[effectId].targeted => before.effects[effectId].targetCard \in DOMAIN world.controllers) /\ decision.chosen \in EligibleReplacements99(before,effectId,replacements) /\ decision=ReplacementDecision99(before,effectId,replacements,world,decision.chosen,decision.resultIds) /\ ReplacementOutputIdsValid99(before,before.effects[effectId],replacements[decision.chosen],decision.resultIds) /\ after=ReplacementNextState99(before,effectId,replacements,decision.chosen,decision.resultIds,decision) /\ ReplacementStateValid99(after) ReplacementPreparationComplete99(state,replacements) == \A id \in DOMAIN state.effects : EligibleReplacements99(state,id,replacements)={} PrepareReplacementEffects99(before,after,replacements,world,states,steps) == /\ Len(states)=Len(steps)+1 /\ states[1]=before /\ states[Len(states)]=after /\ ReplacementStateValid99(before) /\ ReplacementBlueprintsValid99(replacements) /\ \A index \in 1..Len(steps) : ApplyReplacementStep99(states[index],states[index+1],steps[index].effectId,replacements,world,steps[index].decision) /\ ReplacementPreparationComplete99(after,replacements) ApplyCreatedReplacementImmediately99(before,after,replacements,newId,world,states,steps) == /\ newId \in DOMAIN replacements /\ PrepareReplacementEffects99(before,after,replacements,world,states,steps) ContinuousStaticKey99(d,syntax) == [ability |-> syntax.id,source |-> d.source] ContinuousStaticActive99(definition,syntax,current) == StaticAbilityActive94(definition,syntax,current.objects,current.present, current.ordinaryActivity[ContinuousStaticKey99(definition,syntax)],current.activity,current.points) ContinuousOriginalPresent99(original,current) == original.id \in DOMAIN current.maintainedEffects /\ current.maintainedEffects[original.id]=original ContinuousOriginalActive99(original,current) == ContinuousOriginalPresent99(original,current) /\ original.id \in current.activeOriginals Specimen0100Record99(replacement,current,cardFacts) == /\ replacement.kind="Specimen0100Duration" /\ replacement.definition.source.kind="Object" /\ replacement.definition.source=replacement.syntax.source /\ replacement.syntax.kind="Static" /\ replacement.sourceSHA=cardFacts["Specimen0100"].sourceSHA /\ IF replacement.definition.source.object \in DOMAIN current.objects THEN current.objects[replacement.definition.source.object].card="Specimen0100" ELSE TRUE Specimen0100DurationComparison99(original,current,comparison) == /\ comparison.tag="CurrentBoostDurationComparison" /\ comparison.original=original /\ comparison.snapshotId=current.id /\ comparison.turn=TimingRef9("Turn",current.turnId) /\ comparison.shorterThanTurn \in BOOLEAN EffectiveSpecimen0100Boost99(original,replacement,current,comparison) == IF ~ContinuousOriginalActive99(original,current) THEN original.base ELSE Specimen0100CurrentPaidDuration94(replacement.definition,replacement.syntax,current.objects,current.present, current.ordinaryActivity[ContinuousStaticKey99(replacement.definition,replacement.syntax)],current.activity,current.points, original.base,current.turnId,comparison.shorterThanTurn) CurrentBoostAlive99(effect,current) == IF effect.mode="Continuous" THEN TRUE ELSE BarrierResponseCardBoostUnexpired(effect.boost,current.liveEncounters,LAMBDA ref : ref \in current.liveDurations) ObserveSpecimen0100Duration99(original,replacement,current,comparison,projection,cardFacts) == /\ original.id \in Nat \ {0} /\ current.id \in Nat \ {0} /\ current.turnId \in Nat \ {0} /\ current.activeOriginals \subseteq DOMAIN current.maintainedEffects /\ original.id \in DOMAIN current.maintainedEffects => current.maintainedEffects[original.id]=original /\ Specimen0100Record99(replacement,current,cardFacts) /\ Specimen0100DurationComparison99(original,current,comparison) /\ LET effective == EffectiveSpecimen0100Boost99(original,replacement,current,comparison) due == ContinuousOriginalPresent99(original,current) /\ ~CurrentBoostAlive99(effective,current) IN projection=[tag |-> "ContinuousDurationProjection",originalId |-> original.id,replacementId |-> replacement.id, snapshotId |-> current.id,base |-> original.base,effective |-> effective, replacementApplies |-> ContinuousOriginalActive99(original,current) /\ effective # original.base, cleanupDue |-> due,cleanupAt |-> IF due THEN "NextCheckpoint" ELSE "NoValue"] ObserveContinuousStaticReplacement99(original,replacement,current,actualReplacement,projection) == /\ current.id \in Nat \ {0} /\ actualReplacement.tag="CurrentStaticReplacement" /\ actualReplacement.original=original /\ actualReplacement.replacement=replacement /\ actualReplacement.snapshotId=current.id /\ LET base == [id \in DOMAIN actualReplacement.base |-> actualReplacement.base[id]] originalActive == ContinuousStaticActive99(original.definition,original.syntax,current) replacementActive == ContinuousStaticActive99(replacement.definition,replacement.syntax,current) IN /\ ObserveCurrentStaticDeclarations94(original.definition,original.syntax,current.objects,current.present, current.ordinaryActivity[ContinuousStaticKey99(original.definition,original.syntax)],current.activity,current.points, original.parts,original.conditions,original.values,base) /\ DOMAIN actualReplacement.values \subseteq DOMAIN base /\ projection=[id \in DOMAIN base |-> IF originalActive /\ replacementActive /\ id \in DOMAIN actualReplacement.values THEN [base[id] EXCEPT !.value=actualReplacement.values[id]] ELSE base[id]] EmptyWould99 == [id \in {} |-> id] WouldContextKey99(ref) == [field \in DOMAIN ref \ {"revision"} |-> ref[field]] WouldContextValid99(ref) == /\ ref.origin \in {"Ability","Rule","BarrierInstruction"} /\ ref.id \in Nat \ {0} /\ ref.revision \in Nat /\ ref.source.kind \in {"Object","Rule"} /\ IF ref.origin="Rule" THEN ref.abilityInstance=0 /\ ref.index=0 /\ ref.source=RuleAbilitySource9(ref.ruleStep) /\ ref.ruleStep # "NoValue" ELSE ref.abilityInstance \in Nat \ {0} /\ (IF ref.origin="BarrierInstruction" THEN ref.index=0 ELSE ref.index \in Nat \ {0}) WouldPeriodValid99(ref) == TimingRefValid9(ref) \/ (ref.kind \in {"Game","StatedPeriod"} /\ ref.id \in Nat \ {0}) WouldPeriodMembership99(opening,period,membership) == /\ WouldPeriodValid99(period) /\ membership.tag="WouldPeriodMembership" /\ membership.openingId=opening.id /\ membership.context=WouldContextKey99(opening.context) /\ membership.period=period /\ membership.procedureId \in Nat \ {0} /\ CASE period.kind="Turn" -> TurnFrameValid5(membership.frame) /\ membership.frame.id=period.id [] period.kind="SchemaAtom138" -> TraversalFrameValid6(membership.frame) /\ membership.frame.id=period.id [] OTHER -> membership.frame.tag="TimingPeriodInstance" /\ membership.frame.period=period /\ membership.frame.procedureId=membership.procedureId NewWouldHistory99 == [openings |-> EmptyWould99,occurrences |-> EmptyWould99,usedOccurrenceIds |-> {},usedOpeningIds |-> {},usedImminenceIds |-> {},serial |-> 0] WouldRootKey99(context,root) == [context |-> WouldContextKey99(context),root |-> root] NewWouldOccurrence99(row,opening,periods,serial) == [id |-> row.id,root |-> row.root,imminenceId |-> opening.imminenceId,context |-> WouldContextKey99(opening.context),openingId |-> opening.id, snapshotId |-> opening.snapshotId,effect |-> row.effect,periods |-> DOMAIN periods,serial |-> serial] OrderPosition99(order,id) == CHOOSE i \in 1..Len(order) : order[i]=id ObserveWouldImminence99(before,after,opening,periods,rows) == /\ opening.tag="WouldEffectOpening" /\ opening.point="BecameImminent" /\ WouldContextValid99(opening.context) /\ opening.id \in (Nat \ {0}) \ before.usedOpeningIds /\ opening.snapshotId \in Nat \ {0} /\ opening.imminenceId \in (Nat \ {0}) \ before.usedImminenceIds /\ opening.imminence.tag="ActualInstructionImminence" /\ opening.imminence.id=opening.imminenceId /\ opening.imminence.context=WouldContextKey99(opening.context) /\ opening.imminence.snapshotId=opening.snapshotId /\ DeckSequenceValid4(opening.order) /\ SubIds6(opening.order)=DOMAIN rows /\ DOMAIN periods # {} /\ \A period \in DOMAIN periods : WouldPeriodMembership99(opening,period,periods[period]) /\ DOMAIN rows \subseteq (Nat \ {0}) \ before.usedOccurrenceIds /\ Cardinality({rows[id].root : id \in DOMAIN rows})=Cardinality(DOMAIN rows) /\ \A id \in DOMAIN rows : rows[id].tag="EffectWouldImminence" /\ rows[id].id=id /\ rows[id].root \in Nat \ {0} /\ rows[id].context=WouldContextKey99(opening.context) /\ rows[id].snapshotId=opening.snapshotId /\ rows[id].effect.amount \in Int /\ LET key == opening.imminenceId record == [id |-> opening.id,imminenceId |-> key,context |-> opening.context,snapshotId |-> opening.snapshotId,periods |-> periods,roots |-> {rows[id].root : id \in DOMAIN rows}] IN after=[before EXCEPT !.openings=[k \in DOMAIN @ \cup {key} |-> IF k=key THEN record ELSE @[k]], !.occurrences=[id \in DOMAIN @ \cup DOMAIN rows |-> IF id \in DOMAIN rows THEN NewWouldOccurrence99(rows[id],opening,periods,before.serial+OrderPosition99(opening.order,id)) ELSE @[id]], !.usedOccurrenceIds=@ \cup DOMAIN rows,!.usedOpeningIds=@ \cup {opening.id},!.usedImminenceIds=@ \cup {opening.imminenceId},!.serial=@+Len(opening.order)] ObserveWouldRevision99(before,after,revision) == /\ revision.tag="WouldExpectedEffectsRevision" /\ WouldContextValid99(revision.context) /\ revision.imminenceId \in DOMAIN before.openings /\ LET original == before.openings[revision.imminenceId] IN /\ revision.openingId=original.id /\ revision.openingSnapshotId=original.snapshotId /\ WouldContextKey99(revision.context)=WouldContextKey99(original.context) /\ revision.context.revision>=original.context.revision /\ after=before ObserveWouldOutcome99(before,after,outcome) == /\ outcome.tag="WouldEffectOutcome" /\ WouldContextValid99(outcome.context) /\ outcome.imminenceId \in DOMAIN before.openings /\ LET original == before.openings[outcome.imminenceId] IN /\ outcome.openingId=original.id /\ outcome.roots \subseteq original.roots /\ WouldContextKey99(outcome.context)=WouldContextKey99(original.context) /\ outcome.context.revision>=original.context.revision /\ outcome.disposition \in {"Resolved","Prevented","Replaced"} /\ after=before WouldCriterionMatches99(effect,criterion) == /\ effect.kind=criterion.kind /\ effect.subtype=criterion.subtype /\ effect.actor=criterion.actor /\ ~criterion.minimumPresent \/ effect.amount>=criterion.minimum /\ ~criterion.targetSitePresent \/ effect.targetSite=criterion.targetSite WouldOrdinalCount99(history,period,criterion) == Cardinality({id \in DOMAIN history.occurrences : period \in history.occurrences[id].periods /\ WouldCriterionMatches99(history.occurrences[id].effect,criterion)}) WouldOrdinalAt99(history,id,period,criterion) == Cardinality({other \in DOMAIN history.occurrences : history.occurrences[other].serial<=history.occurrences[id].serial /\ period \in history.occurrences[other].periods /\ WouldCriterionMatches99(history.occurrences[other].effect,criterion)}) AbilityKey99(d) == [ability |-> d.syntax.id,source |-> d.syntax.source] AbilityOwnWords99(d,lex) == {lex.mentions[id].word : id \in {t \in DOMAIN lex.mentions : lex.mentions[t].owner=AbilityKey99(d)}} OperativeInterruptWords99(d,lex) == {lex.mentions[id].word : id \in {t \in DOMAIN lex.mentions : lex.mentions[t].owner=AbilityKey99(d) /\ (lex.mentions[t].role="EffectOperator" \/ lex.mentions[t].role="ImminentTrigger")}} AbilityMentionValid99(d,mention) == /\ mention.unit \in 1..Len(d.syntax.units) /\ mention.role \in {"EffectOperator","ImminentTrigger","ActualOccurrenceTrigger","OtherOwnText","OtherAbility","StaticDeclaration"} /\ (mention.owner=AbilityKey99(d))=(mention.role # "OtherAbility") /\ mention.role="EffectOperator" => d.syntax.units[mention.unit].category="Instruction" /\ mention.role \in {"ImminentTrigger","ActualOccurrenceTrigger"} => d.syntax.units[mention.unit].category="SchemaAtom043" /\ d.syntax.units[mention.unit].primary /\ mention.role="ImminentTrigger" => mention.word="would" /\ mention.role="StaticDeclaration" => d.syntax.units[mention.unit].category="Declaration" AbilityLexemesValid99(d,lex,objects,cardFacts) == /\ lex.tag="NormalizedAbilityLexemes" /\ lex.definition=d /\ lex.source=d.syntax.source /\ lex.origin.tag="AbilityTextOrigin" /\ lex.origin.recipientSource=d.syntax.source /\ lex.origin.provider=d.activity.provider /\ \A id \in DOMAIN lex.mentions : id \in Nat \ {0} /\ AbilityMentionValid99(d,lex.mentions[id]) /\ (IF "instructionHasWould" \in DOMAIN d THEN d.instructionHasWould => "would" \in OperativeInterruptWords99(d,lex) ELSE TRUE) /\ IF d.syntax.source.kind="Rule" THEN /\ lex.card="NoValue" /\ lex.origin.rule=d.syntax.source.rule /\ lex.sourceSHA="0186148ecd6da8170b6555aa90d3f0115a8d5150d807078b75ac2339a2a1421e" ELSE /\ lex.card \in DOMAIN cardFacts /\ lex.sourceSHA=cardFacts[lex.card].sourceSHA /\ lex.origin.card=lex.card /\ lex.origin.sourceSHA=lex.sourceSHA /\ IF d.activity.provider="Printed" /\ d.syntax.source.object \in DOMAIN objects THEN objects[d.syntax.source.object].card=lex.card ELSE TRUE AbilityInterrupt99(d,lex) == d.syntax.kind \in {"Paid","Conditional"} /\ (FlagPresent93(d.syntax.units,"Interrupt") \/ {"prevent","avoid","would"} \cap OperativeInterruptWords99(d,lex) # {}) ReplacementText99(d,lex) == \E id \in DOMAIN lex.mentions : lex.mentions[id].owner=AbilityKey99(d) /\ lex.mentions[id].word="instead" /\ lex.mentions[id].role \in {"EffectOperator","StaticDeclaration"} PaidRequiredWindows99(d,lex) == (IF IsAction5(TRUE,d.triggerCost) THEN {"NeutralValue00001"} ELSE {}) \cup (IF AbilityInterrupt99(d,lex) THEN {"Interrupt"} ELSE {}) \cup (IF FlagPresent93(d.syntax.units,"ItemInspection") \/ d.ruleTiming="BasicRetire" THEN {"MidItemInspection"} ELSE {}) PaidWindowKinds99(d,lex) == LET required == PaidRequiredWindows99(d,lex) IN IF required={} THEN {"Paid"} ELSE IF Cardinality(required)=1 THEN required ELSE {} PaidBaseEligibility99(d,lex,c,w) == /\ PaidTraversalContextBound95(c) /\ PaidWindowContext95(c,w) /\ d.syntax.kind="Paid" /\ d.activity.kind="Paid" /\ d.activity.id=d.syntax.id /\ d.activity.source=d.syntax.source /\ AbilityTextValid93(d.syntax) /\ Len(d.triggerCost)>0 /\ Len(d.instructions)>0 /\ d.ruleTiming \in {"NoValue","BasicRetire"} /\ d.ruleTiming="BasicRetire" => d.syntax.source=RuleAbilitySource9("BasicRetire") /\ WindowSiteAllowed9(w.kind,w.site) /\ w.kind \in PaidWindowKinds99(d,lex) /\ w.priority=d.syntax.controller /\ w.active=c.turn.owner /\ w.site.turnId=c.turn.id /\ FlagActivity93(d.syntax,c.present,AbilityActive9(d.activity,c.objects,c.present,c.defaultActive, c.activity),c.activity.persistentAbilities,c.points) /\ WholeAbilityRestrictionGate93(d.syntax,c.ownRestrictions) /\ PaidOtherRestrictions95(d,c) /\ OncePerTurnAllowed93(d.syntax,c.turn.id,c.uses) /\ PaidSourceUseAllowed95(d,c) /\ PaidEffectTiming95(d,c) /\ PaidInterfaceTiming95(d,c,w.site) PaidEligibilityCore99(d,lex,c,w) == /\ PaidBaseEligibility99(d,lex,c,w) /\ IF AbilityInterrupt99(d,lex) THEN /\ InterruptEffectMatches9(w,c.currentEffect) /\ d.syntax.id \in c.currentEffect.paidInterruptAbilities /\ c.paidRelevance.tag="PaidInterruptRelevance" /\ c.paidRelevance.windowId=w.id /\ c.paidRelevance.instruction=w.instruction /\ c.paidRelevance.revision=c.currentEffect.revision /\ [ability |-> d.syntax.id,source |-> d.syntax.source] \in c.paidRelevance.eligible ELSE TRUE PaidEligibility99(d,lex,c,w,cardFacts) == /\ AbilityLexemesValid99(d,lex,c.objects,cardFacts) /\ PaidEligibilityCore99(d,lex,c,w) ReservePaidAbility99(before,after,p,id,d,lex,c,option,legality,usedInstances,cardFacts) == /\ Len(before)>0 /\ id \in (Nat \ {0}) \ usedInstances /\ PaidEligibility99(d,lex,c,WindowTop9(before),cardFacts) /\ PaidOptionMatches95(d,option,WindowTop9(before)) /\ BeginPriorityOption9(before,after,option,c.objects,legality,c.currentEffect) /\ p=OpenPaidProcedure95(id,d,option,WindowTop9(before),legality.transactionId, IF d.syntax.source.kind="Object" THEN c.objects[d.syntax.source.object].zone ELSE "Rule") ConditionalLexemesBound99(definitions,lexemes,snapshot,cardFacts) == /\ DOMAIN lexemes=DOMAIN definitions /\ \A key \in DOMAIN definitions : AbilityLexemesValid99(definitions[key],lexemes[key],snapshot.objects,cardFacts) CheckpointCandidates99(definitions,lexemes,ledger,cp,conditions) == {candidate \in CheckpointCandidates96(definitions,ledger,cp,conditions) : ~AbilityInterrupt99(definitions[candidate.definition],lexemes[candidate.definition])} DepartureCandidates99(definitions,lexemes,cp,conditions,departures) == {candidate \in DepartureCandidates96(definitions,cp,conditions,departures) : ~AbilityInterrupt99(definitions[candidate.definition],lexemes[candidate.definition])} ProcessConditionalCheckpointCore99(before,after,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,cardFacts) == LET stable == ConditionalActivityLedger96(before,definitions,cp.processingSnapshot) candidates == CheckpointCandidates99(definitions,lexemes,stable,cp,conditions) \cup DepartureCandidates99(definitions,lexemes,cp,conditions,departures) departureKeys == {key.definition : key \in DepartureCandidates99(definitions,lexemes,cp,conditions,departures)} ids == {allocation[key] : key \in candidates} IN /\ ConditionalLexemesBound99(definitions,lexemes,cp.processingSnapshot,cardFacts) /\ definitions=cp.processingSnapshot.definitions /\ ConditionalDefinitionsStable96(before.lastSnapshot,cp.processingSnapshot) /\ \A key \in DOMAIN definitions : key=ConditionalKey96(definitions[key]) /\ ConditionalDefinitionValid96(definitions[key]) /\ ConditionalSnapshotBound96(cp.processingSnapshot,before) /\ CheckpointBatchValid96(before,cp,candidates,allocation,bindings) /\ DOMAIN holds=departureKeys /\ \A key \in departureKeys : DepartureAuthority96(definitions[key],cp,conditions[key],allocation,departures[key],holds[key]) /\ after=[stable EXCEPT !.activationEpoch=cp.processingSnapshot.activationEpoch,!.holds=[key \in DOMAIN @ \cup departureKeys |-> IF key \in departureKeys THEN holds[key] ELSE @[key]],!.lastCheckpoint=cp.id,!.checkpointIds=@ \cup {cp.id}, !.checkpoints=[id \in DOMAIN @ \cup {cp.id} |-> IF id=cp.id THEN [caller |-> cp.caller] ELSE @[id]],!.serial=cp.serial,!.lastSnapshot=cp.processingSnapshot, !.processed=@ \cup DOMAIN cp.occurrences, !.instances=[id \in DOMAIN @ \cup ids |-> IF id \in ids THEN LET key == CHOOSE k \in candidates : allocation[k]=id d == definitions[key.definition] IN NewConditionalInstance96(id,d,cp,key.occurrence,bindings[key].windowId,bindings[key].group) ELSE @[id]]] /\ \A key \in departureKeys : ConditionalActive96(definitions[key],SnapshotWithConditionalRegistry96(cp.processingSnapshot,after)) ProcessConditionalCheckpoint99(before,after,beforeStack,afterStack,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,usedWindowIds,cardFacts) == /\ ProcessConditionalCheckpointCore99(before,after,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,cardFacts) /\ \A key \in DOMAIN bindings : bindings[key].windowId \notin usedWindowIds \cup {beforeStack[i].id : i \in 1..Len(beforeStack)} /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) BeginConditionalResolutionCore99(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,d,lex,snapshot,id,option,legality,currentEffect,plan,afterPlan,targets,entry,turnUses,restrictions,cardFacts) == /\ AbilityLexemesValid99(d,lex,snapshot.objects,cardFacts) /\ ConditionalSnapshotBound96(snapshot,beforeLedger) /\ ConditionalDefinitionValid96(d) /\ id \in DOMAIN beforeLedger.instances /\ beforeLedger.instances[id].status="Pending" /\ beforeLedger.instances[id].definition=ConditionalKey96(d) /\ ConditionalKey96(d) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(d)]=d /\ beforeLedger.instances[id].definitionCopy=d /\ ConditionalInstanceCurrent96(beforeLedger.instances[id],[key \in {ConditionalKey96(d)} |-> d],snapshot) /\ Len(beforeStack)>0 /\ WindowTop9(beforeStack).kind=(IF AbilityInterrupt99(d,lex) THEN "Interrupt" ELSE "Reaction") /\ id \in DOMAIN WindowTop9(beforeStack).members /\ WindowTop9(beforeStack).members[id]=beforeLedger.instances[id].member /\ option.instance=id /\ option.ability=d.syntax.id /\ option.source=d.syntax.source /\ option.kind=IF AbilityInterrupt99(d,lex) THEN "ConditionalInterrupt" ELSE "Conditional" /\ WholeAbilityRestrictionGate93(d.syntax,restrictions) /\ OncePerTurnAllowed93(d.syntax,WindowTop9(beforeStack).site.turnId,turnUses) /\ BeginPriorityOption9(beforeStack,afterStack,option,snapshot.objects,legality,currentEffect) /\ p=OpenConditionalProcedure96(id,d,WindowTop9(beforeStack),option,legality.transactionId, IF d.syntax.source.kind="Rule" THEN "Rule" ELSE IF d.syntax.source.object \in DOMAIN snapshot.objects THEN snapshot.objects[d.syntax.source.object].zone ELSE "NoValue") /\ ~plan.announced /\ entry.sourceEligible=ConditionalActive96(d,snapshot) /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [p.ability EXCEPT !.phase="Imminent",!.firstImminent=TRUE,!.detached=TRUE] IN /\ AnnounceInstructionTargets93(plan,announced,targets,p.ability,"NoValue") /\ EnterFirstAbilityInstruction93(p.ability,imminent,announced,afterPlan,entry) /\ afterP=[p EXCEPT !.ability=imminent,!.phase="Imminent"] /\ afterLedger=[beforeLedger EXCEPT !.instances[id].status="Imminent"] /\ ConditionalProcedureBound96(afterLedger,afterP) NewWouldAccounting99 == [groups |-> [key \in {} |-> key],evidence |-> <<>>,serial |-> 0,observationIds |-> {},observations |-> [key \in {} |-> key],latest |-> [key \in {} |-> key]] WouldDescriptor99(effect) == [kind |-> effect.kind,subtype |-> IF effect.kind="Damage" THEN effect.damageType ELSE "NoValue", actor |-> IF "actor" \in DOMAIN effect THEN effect.actor ELSE effect.baseController, amount |-> IF "value" \in DOMAIN effect THEN effect.value ELSE 0, targetSite |-> IF "targetSite" \in DOMAIN effect THEN effect.targetSite ELSE "NoValue"] ExpectedWouldAtomicCriterion99(effect,criterion) == /\ effect.kind=criterion.kind /\ effect.subtype=criterion.subtype /\ (criterion.actor="SchemaAtom016" \/ effect.actor=criterion.actor) /\ (~criterion.minimumPresent \/ effect.amount>=criterion.minimum) /\ (~criterion.targetSitePresent \/ effect.targetSite=criterion.targetSite) ExpectedWouldCriterionMatches99(effect,criterion) == IF "alternatives" \in DOMAIN criterion THEN \E alternative \in criterion.alternatives : ExpectedWouldAtomicCriterion99(effect,alternative) ELSE ExpectedWouldAtomicCriterion99(effect,criterion) InitialWouldGroups99(imminence,effects) == [id \in DOMAIN effects |-> <>] WouldMatchingGroups99(history,period,criterion) == {key \in DOMAIN history.groups : \E i \in 1..Len(history.evidence) : history.evidence[i].group=key /\ period \in history.evidence[i].periods /\ ExpectedWouldCriterionMatches99(history.evidence[i].descriptor,criterion)} FirstWouldMatchSerial99(history,key,period,criterion) == LET positions == {i \in 1..Len(history.evidence) : history.evidence[i].group=key /\ period \in history.evidence[i].periods /\ ExpectedWouldCriterionMatches99(history.evidence[i].descriptor,criterion)} IN IF positions={} THEN 0 ELSE CHOOSE i \in positions : \A other \in positions : i<=other WouldOrdinalCountCurrent99(history,period,criterion) == Cardinality(WouldMatchingGroups99(history,period,criterion)) WouldOrdinalAtCurrent99(history,key,period,criterion) == IF key \notin WouldMatchingGroups99(history,period,criterion) THEN 0 ELSE Cardinality({other \in WouldMatchingGroups99(history,period,criterion) : FirstWouldMatchSerial99(history,other,period,criterion)<=FirstWouldMatchSerial99(history,key,period,criterion)}) RecordWouldDescriptors99(before,after,contextId,imminence,ref,worldId,effects,groups,periods,order,receipt) == /\ receipt.tag="CurrentExpectedWouldObservation" /\ receipt.id \in (Nat \ {0}) \ before.observationIds /\ receipt.contextId=contextId /\ receipt.imminenceId=imminence /\ receipt.reference=ref /\ receipt.snapshotId=worldId /\ receipt.effects=effects /\ receipt.groups=groups /\ receipt.periods=periods /\ receipt.order=order /\ DOMAIN groups=DOMAIN effects /\ DeckSequenceValid4(order) /\ SubIds6(order)=DOMAIN effects /\ \A id \in DOMAIN groups : Len(groups[id])>=2 /\ groups[id][1]=imminence /\ LET keys == {groups[id] : id \in DOMAIN groups} owner == [imminenceId |-> imminence,context |-> WouldContextKey99(ref)] observed == [i \in 1..Len(order) |-> [group |-> groups[order[i]],descriptor |-> WouldDescriptor99(effects[order[i]]), periods |-> periods,serial |-> before.serial+i,reference |-> ref,snapshotId |-> worldId]] IN /\ \A key \in keys \cap DOMAIN before.groups : before.groups[key]=owner /\ after=[before EXCEPT !.groups=ReplacementOverlay99(@,[key \in keys |-> owner]), !.evidence=@ \o observed,!.serial=@+Len(order),!.observationIds=@ \cup {receipt.id}, !.latest=ReplacementOverlay99(@,[key \in {contextId} |-> receipt]), !.observations=ReplacementOverlay99(@,[key \in {receipt.id} |-> receipt])] WouldViewCurrent99(history,context,world) == /\ context.id \in DOMAIN history.latest /\ history.latest[context.id].imminenceId=context.imminenceId /\ history.latest[context.id].reference=context.currentRef /\ history.latest[context.id].snapshotId=world.id /\ history.latest[context.id].effects=context.state.effects /\ history.latest[context.id].groups=[id \in DOMAIN context.state.effects |-> context.wouldGroups[id]] RECURSIVE ReplacementWouldGroups99(_,_,_,_) ReplacementWouldGroups99(groups,states,steps,replacements) == IF Len(steps)=0 THEN groups ELSE LET step == Head(steps).decision input == Head(steps).effectId ids == SubIds6(step.resultIds) policy == replacements[step.chosen].wouldGrouping additions == [id \in ids |-> IF policy="Preserve" THEN groups[input] ELSE Append(groups[input],id)] next == ReplacementOverlay99([id \in DOMAIN groups \ {input} |-> groups[id]],additions) IN ReplacementWouldGroups99(next,Tail(states),Tail(steps),replacements) ImminentOrigin99(origin) == IF origin.kind="BarrierInstruction" THEN BarrierInstructionImminent98(origin.procedure) ELSE origin.kind="Instruction" /\ InstructionImminentAtOrigin93(origin.plan,origin.parent,origin.ruleStep) OriginReference99(origin) == IF origin.kind="BarrierInstruction" THEN BarrierInstructionWindowRef98(origin.procedure) ELSE InstructionWindowRef93(origin.plan) OriginRevision99(origin) == OriginReference99(origin).revision ExpectedWorldValid99(world) == /\ world.tag="CurrentInterruptWorld" /\ world.id \in Nat \ {0} /\ TurnFrameValid5(world.turn) /\ TraversalFrameValid6(world.traversalControl.traversal) /\ DOMAIN world.controllers=DOMAIN world.objects /\ \A id \in DOMAIN world.controllers : world.controllers[id] \in SetupPlayers /\ \A ref \in DOMAIN world.activePeriods : ref.kind \notin {"Turn","SchemaAtom138"} /\ WouldPeriodValid99(ref) /\ world.activePeriods[ref].period=ref ActualWouldPeriods99(world) == {TimingRef9("Turn",world.turn.id)} \cup (IF DuringTraversal6(world.traversalControl.traversal) THEN {TimingRef9("SchemaAtom138",world.traversalControl.traversal.id)} ELSE {}) \cup DOMAIN world.activePeriods ActualWouldMembership99(opening,world,periods) == /\ ExpectedWorldValid99(world) /\ DOMAIN periods=ActualWouldPeriods99(world) /\ \A ref \in DOMAIN periods : /\ WouldPeriodMembership99(opening,ref,periods[ref]) /\ CASE ref.kind="Turn" -> periods[ref].frame=world.turn [] ref.kind="SchemaAtom138" -> periods[ref].frame=world.traversalControl.traversal [] OTHER -> periods[ref].frame=world.activePeriods[ref] ExpectedAtomDescriptor99(effect) == WouldDescriptor99(effect) ExpectedAtomMapBound99(effects,ref) == /\ ReplacementEffectsValid99(effects) /\ \A id \in DOMAIN effects : effects[id].value \in Int /\ effects[id].actor \in SetupPlayers /\ effects[id].targetSite \in STRING /\ effects[id].baseOrigin=ref.source InitialExpectedProjection99(origin,world,description,projection,effects) == /\ ImminentOrigin99(origin) /\ ExpectedWorldValid99(world) /\ description.tag="NormalizedInstructionEffectDescription" /\ description.context=OriginReference99(origin) /\ description.source=OriginReference99(origin).source /\ description.snapshotId=world.id /\ IF "occurrenceGroups" \in DOMAIN description THEN /\ DOMAIN description.occurrenceGroups=DOMAIN description.effects /\ \A id \in DOMAIN description.occurrenceGroups : description.occurrenceGroups[id] \in Nat \ {0} ELSE TRUE /\ ExpectedAtomMapBound99(description.effects,OriginReference99(origin)) /\ DeckSequenceValid4(description.order) /\ SubIds6(description.order)=DOMAIN description.effects /\ {description.effects[id].lineage : id \in DOMAIN description.effects}=DOMAIN description.effects /\ \A id \in DOMAIN description.effects : description.effects[id].lineage=id /\ projection.tag="CurrentStaticExpectedProjection" /\ projection.description=description /\ projection.snapshotId=world.id /\ projection.forbiddenIds \subseteq DOMAIN description.effects /\ DOMAIN projection.values \subseteq DOMAIN description.effects /\ \A id \in DOMAIN projection.values : description.effects[id].kind \in ExpectedValueKinds99 /\ projection.values[id] \in Int /\ effects=[id \in DOMAIN description.effects \ projection.forbiddenIds |-> IF id \in DOMAIN projection.values THEN [description.effects[id] EXCEPT !.value=projection.values[id]] ELSE description.effects[id]] ExpectedObservationSet99(effects) == {effects[id] : id \in DOMAIN effects} DescriptionWouldGroups99(entryId,description) == IF "occurrenceGroups" \in DOMAIN description THEN [effect \in DOMAIN description.effects |-> <>] ELSE InitialWouldGroups99(entryId,description.effects) NewExpectedContext99(id,entryId,origin,world,description,initial,owner) == [id |-> id,imminenceId |-> entryId,initialRef |-> OriginReference99(origin),currentRef |-> OriginReference99(origin), openingRef |-> OriginReference99(origin),initialWorld |-> world.id,currentWorld |-> world.id,initialPeriods |-> ActualWouldPeriods99(world), initialWouldGroups |-> [effect \in DOMAIN initial |-> DescriptionWouldGroups99(entryId,description)[effect]], entry |-> world.entries[entryId],clearance |-> [field \in {} |-> field],site |-> [field \in {} |-> field],actualEffects |-> [effect \in {} |-> effect], description |-> description,initialEffects |-> initial,preparedEffects |-> initial, state |-> [NewReplacementState99(description.effects) EXCEPT !.effects=initial,!.ancestry=[effect \in DOMAIN initial |-> {}]],owner |-> owner, ancestryArchive |-> [effect \in DOMAIN description.effects |-> {}], templates |-> description.effects,removedEffects |-> {},retiredEffects |-> {}, phase |-> "Replacing",conditionalIds |-> {},conditionalDefinitions |-> [key \in {} |-> key],openingMembers |-> [effect \in {} |-> effect], wouldRows |-> [root \in {} |-> root],wouldGroups |-> DescriptionWouldGroups99(entryId,description),windowId |-> 0,group |-> 0,modifications |-> <<>>,modificationIds |-> {},temporaryReplacements |-> [effect \in {} |-> effect]] InitialWouldOrder99(context) == SelectSeq(context.description.order,LAMBDA effect : effect \in DOMAIN context.initialEffects) InitialWouldObservation99(context,id) == [tag |-> "CurrentExpectedWouldObservation",id |-> id,contextId |-> context.id,imminenceId |-> context.imminenceId, reference |-> context.initialRef,snapshotId |-> context.initialWorld,effects |-> context.initialEffects, groups |-> context.initialWouldGroups,periods |-> context.initialPeriods,order |-> InitialWouldOrder99(context)] InitialWouldCaptured99(context,history) == \E id \in DOMAIN history.observations \cap history.observationIds : /\ history.observations[id]=InitialWouldObservation99(context,id) /\ \A effect \in DOMAIN context.initialEffects : \E index \in 1..Len(history.evidence) : /\ history.evidence[index].group=context.initialWouldGroups[effect] /\ history.evidence[index].descriptor=WouldDescriptor99(context.initialEffects[effect]) /\ history.evidence[index].reference=context.initialRef /\ history.evidence[index].snapshotId=context.initialWorld /\ history.evidence[index].periods=context.initialPeriods ExpectedContextOrigin99(context,origin) == /\ ImminentOrigin99(origin) /\ context.currentRef=OriginReference99(origin) /\ WouldContextKey99(context.initialRef)=WouldContextKey99(context.currentRef) ExpectedContextWorld99(context,world) == ExpectedWorldValid99(world) /\ context.currentWorld=world.id InitialExpectedReceipt99(context) == [tag |-> "ConditionalExpectedEffects",point |-> "ExpectedEffectsBeforeInterrupt",instruction |-> context.initialRef,effects |-> ExpectedObservationSet99(context.initialEffects)] ObserveInitialConditionalExpected99(before,after,p,plan,context) == /\ context.initialRef=InstructionWindowRef93(plan) /\ context.phase="Replacing" /\ context.currentRef=context.initialRef /\ ObserveConditionalExpected96(before,after,p,plan,InitialExpectedReceipt99(context)) ContextInitialObservationBound99(ledger,p,context) == /\ ConditionalProcedureBound96(ledger,p) /\ context.initialRef.abilityInstance=p.id /\ context.initialRef.index \in DOMAIN ledger.instances[p.id].expected /\ ledger.instances[p.id].expected[context.initialRef.index]=[instruction |-> context.initialRef,effects |-> ExpectedObservationSet99(context.initialEffects)] AdvanceImminentOrigin99(before,after) == /\ ImminentOrigin99(before) /\ IF before.kind="BarrierInstruction" THEN after=[before EXCEPT !.procedure.revision=@+1] ELSE after=[before EXCEPT !.plan.revision=@+1] RefreshExpectedWorld99(before,after,beforeOrigin,afterOrigin,world,projection,history) == /\ InitialWouldCaptured99(before,history) /\ ExpectedContextOrigin99(before,beforeOrigin) /\ before.phase \in {"Replacing","Prepared","WindowOpen"} /\ ExpectedWorldValid99(world) /\ projection.tag="ContinuousExpectedEffectsUpdate" /\ projection.context=before.currentRef /\ projection.snapshotId=world.id /\ projection.description=before.description /\ projection.beforeEffects=before.state.effects /\ projection.instructionReplacements=before.state.transformations /\ projection.resolvedModifications=before.modifications /\ DOMAIN projection.effects \subseteq before.state.usedEffectIds \ (before.removedEffects \cup before.retiredEffects) /\ ReplacementEffectsValid99(projection.effects) /\ \A id \in DOMAIN projection.effects : /\ id \in DOMAIN before.templates /\ DOMAIN projection.effects[id]=DOMAIN before.templates[id] /\ \A field \in DOMAIN before.templates[id] \ {"value","preventable","specifications","restrictions"} : projection.effects[id][field]=before.templates[id][field] /\ AdvanceImminentOrigin99(beforeOrigin,afterOrigin) /\ after=[before EXCEPT !.currentRef=OriginReference99(afterOrigin),!.currentWorld=world.id,!.state.effects=projection.effects, !.state.ancestry=[id \in DOMAIN projection.effects |-> IF id \in DOMAIN before.state.ancestry THEN before.state.ancestry[id] ELSE before.ancestryArchive[id]], !.ancestryArchive=ReplacementOverlay99(@,before.state.ancestry), !.modifications=Append(@,[kind |-> "ContinuousProjection",snapshotId |-> world.id,from |-> before.currentRef,to |-> OriginReference99(afterOrigin),effects |-> projection.effects])] InterruptPatternValid99(pattern) == /\ "kind" \in DOMAIN pattern /\ pattern.kind \in STRING /\ ("minValue" \in DOMAIN pattern => pattern.minValue \in Int) InterruptCapabilitiesValid99(d,lex,capabilities) == /\ capabilities.tag="NormalizedInterruptCapabilities" /\ capabilities.definition=d /\ capabilities.origin=lex.origin /\ \A id \in DOMAIN capabilities.clauses : LET c == capabilities.clauses[id] IN /\ c.mode \in {"PreventAmount","PreventWhole","AddValue","SetValue","CreateReplacement","WouldTrigger"} /\ InterruptPatternValid99(c.pattern) /\ c.mode \in {"PreventAmount","AddValue","SetValue"} => c.value \in Int /\ c.mode="CreateReplacement" => InterruptPatternValid99(c.replacementPattern) /\ c.mode="WouldTrigger" => c.ordinal \in Nat /\ WouldPeriodValid99(c.period) CapabilityRelevant99(clause,effect,context,world,history) == /\ ReplacementPatternMatches99(clause.pattern,effect) /\ CASE clause.mode="PreventAmount" -> effect.kind \in {"Damage","ExposureMarkers"} /\ "preventable" \in DOMAIN effect /\ effect.preventable /\ clause.value>0 [] clause.mode="PreventWhole" -> "preventable" \in DOMAIN effect /\ effect.preventable [] clause.mode="AddValue" -> effect.kind \in ExpectedValueKinds99 /\ clause.value # 0 [] clause.mode="SetValue" -> effect.kind \in ExpectedValueKinds99 /\ clause.value # effect.value [] clause.mode="CreateReplacement" -> ReplacementPatternMatches99(clause.replacementPattern,effect) [] clause.mode="WouldTrigger" -> /\ clause.period \in ActualWouldPeriods99(world) /\ IF clause.ordinal=0 THEN TRUE ELSE /\ effect.id \in DOMAIN context.wouldGroups /\ ExpectedWouldCriterionMatches99(ExpectedAtomDescriptor99(effect),clause.criterion) /\ WouldOrdinalAtCurrent99(history,context.wouldGroups[effect.id],clause.period,clause.criterion)=clause.ordinal [] OTHER -> FALSE InterruptRelevant99(d,lex,capabilities,context,world,history) == /\ AbilityInterrupt99(d,lex) /\ InterruptCapabilitiesValid99(d,lex,capabilities) /\ \E c \in DOMAIN capabilities.clauses : \E effect \in DOMAIN context.state.effects : CapabilityRelevant99(capabilities.clauses[c],context.state.effects[effect],context,world,history) ConditionalInterruptPrimary99(d,capabilities,context,world,history) == IF d.primaryKind="Static" THEN TRUE ELSE /\ "primaryGroups" \in DOMAIN capabilities /\ \E group \in DOMAIN capabilities.primaryGroups : \A id \in capabilities.primaryGroups[group] : \E effect \in DOMAIN context.state.effects : CapabilityRelevant99(capabilities.clauses[id],context.state.effects[effect],context,world,history) CurrentInterruptDefinitions99(world) == ReplacementOverlay99(world.conditional.definitions,world.paidDefinitions) CurrentInterruptWorld99(world,ledger,cardFacts) == /\ ExpectedWorldValid99(world) /\ ConditionalSnapshotBound96(world.conditional,ledger) /\ world.conditional.id=world.id /\ world.objects=world.conditional.objects /\ DOMAIN world.conditional.definitions \cap DOMAIN world.paidDefinitions={} /\ DOMAIN world.lexemes=DOMAIN CurrentInterruptDefinitions99(world) /\ DOMAIN world.capabilities=DOMAIN CurrentInterruptDefinitions99(world) /\ DOMAIN world.paidContexts=DOMAIN world.paidDefinitions /\ \A key \in DOMAIN CurrentInterruptDefinitions99(world) : LET d == CurrentInterruptDefinitions99(world)[key] IN /\ key=AbilityKey99(d) /\ (d.syntax.kind="Conditional" => ConditionalDefinitionValid96(d)) /\ AbilityLexemesValid99(d,world.lexemes[key],world.objects,cardFacts) /\ InterruptCapabilitiesValid99(d,world.lexemes[key],world.capabilities[key]) /\ IF d.syntax.kind="Conditional" /\ AbilityInterrupt99(d,world.lexemes[key]) /\ d.primaryKind="Trigger" THEN /\ "primaryGroups" \in DOMAIN world.capabilities[key] /\ \A group \in DOMAIN world.capabilities[key].primaryGroups : /\ world.capabilities[key].primaryGroups[group] # {} /\ world.capabilities[key].primaryGroups[group] \subseteq DOMAIN world.capabilities[key].clauses /\ \A id \in world.capabilities[key].primaryGroups[group] : world.capabilities[key].clauses[id].mode="WouldTrigger" ELSE TRUE /\ \A key \in DOMAIN world.paidContexts : LET c == world.paidContexts[key] IN /\ c.objects=world.objects /\ c.turn=world.turn /\ c.traversalControl=world.traversalControl /\ c.traversal=world.traversalControl.traversal /\ c.present=world.conditional.present /\ c.activity=world.conditional.activity /\ c.points=world.conditional.points /\ c.uses=world.turnUses CurrentPendingRelevant99(context,world,history,ledger) == {id \in context.conditionalIds \cap DOMAIN ledger.instances : LET instance == ledger.instances[id] key == instance.definition IN IF key \notin DOMAIN world.conditional.definitions THEN FALSE ELSE /\ instance.status="Pending" /\ ConditionalInstanceCurrent96(instance,world.conditional.definitions,world.conditional) /\ InterruptRelevant99(world.conditional.definitions[key],world.lexemes[key],world.capabilities[key],context,world,history) /\ ConditionalInterruptPrimary99(world.conditional.definitions[key],world.capabilities[key],context,world,history)} CurrentPaidRelevant99(context,world,history,w) == {key \in DOMAIN world.paidDefinitions : PaidBaseEligibility99(world.paidDefinitions[key],world.lexemes[key],world.paidContexts[key],w) /\ InterruptRelevant99(world.paidDefinitions[key],world.lexemes[key],world.capabilities[key],context,world,history)} OpeningPaidRelevant99(context,world,history,w) == {key \in DOMAIN world.paidDefinitions : LET d == world.paidDefinitions[key] IN PaidBaseEligibility99(d,world.lexemes[key],world.paidContexts[key],[w EXCEPT !.priority=d.syntax.controller]) /\ InterruptRelevant99(d,world.lexemes[key],world.capabilities[key],context,world,history)} CurrentEffectReceipt99(context,world,history,ledger,w) == [tag |-> "CurrentImminentEffect",windowId |-> w.id,instruction |-> w.instruction,revision |-> context.currentRef.revision+1, relevantConditional |-> CurrentPendingRelevant99(context,world,history,ledger), paidInterruptAbilities |-> {key.ability : key \in CurrentPaidRelevant99(context,world,history,w)}] CurrentPaidRelevanceReceipt99(context,world,history,w) == [tag |-> "PaidInterruptRelevance",windowId |-> w.id,instruction |-> w.instruction,revision |-> context.currentRef.revision+1, eligible |-> CurrentPaidRelevant99(context,world,history,w)] CurrentInterruptWindow99(context,stack) == /\ context.phase="WindowOpen" /\ Len(stack)>0 /\ LET w == WindowTop9(stack) IN /\ w.id=context.windowId /\ w.kind="Interrupt" /\ w.instruction=context.openingRef /\ w.members=context.openingMembers /\ w.group=context.group ReserveCurrentPaidInterrupt99(beforeStack,afterStack,p,id,d,c,context,origin,world,history,ledger,option,legality,usedInstances,cardFacts) == /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ ExpectedContextWorld99(context,world) /\ ExpectedContextOrigin99(context,origin) /\ WouldViewCurrent99(history,context,world) /\ CurrentInterruptWindow99(context,beforeStack) /\ LET key == AbilityKey99(d) w == WindowTop9(beforeStack) IN /\ key \in DOMAIN world.paidDefinitions /\ world.paidDefinitions[key]=d /\ c=world.paidContexts[key] /\ c.currentEffect=CurrentEffectReceipt99(context,world,history,ledger,w) /\ c.paidRelevance=CurrentPaidRelevanceReceipt99(context,world,history,w) /\ key \in CurrentPaidRelevant99(context,world,history,w) /\ ReservePaidAbility99(beforeStack,afterStack,p,id,d,world.lexemes[key],c,option,legality,usedInstances,cardFacts) BeginCurrentConditionalInterrupt99(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,d,snapshot,id,option,legality, plan,afterPlan,targets,entry,turnUses,restrictions,context,origin,world,history,cardFacts) == /\ CurrentInterruptWorld99(world,beforeLedger,cardFacts) /\ ExpectedContextWorld99(context,world) /\ ExpectedContextOrigin99(context,origin) /\ WouldViewCurrent99(history,context,world) /\ CurrentInterruptWindow99(context,beforeStack) /\ snapshot=world.conditional /\ turnUses=world.turnUses /\ id \in context.conditionalIds /\ id \in CurrentPendingRelevant99(context,world,history,beforeLedger) /\ BeginConditionalResolutionCore99(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,d,world.lexemes[AbilityKey99(d)],snapshot,id, option,legality,CurrentEffectReceipt99(context,world,history,beforeLedger,WindowTop9(beforeStack)), plan,afterPlan,targets,entry,turnUses,restrictions,cardFacts) InstructionCallerEntry99(entry,world,cardFacts) == /\ entry.tag="ActualInstructionEntry" /\ entry.id \in Nat \ {0} /\ entry.snapshotId=world.id /\ entry.beforePlan.phase="Planning" /\ ~entry.beforePlan.announced /\ entry.afterPlan.phase="Imminent" /\ (entry.kind # "ConditionalFirst" => entry.stackAfter=entry.stackBefore) /\ CASE entry.kind="Paid" -> /\ EnterPaidInstruction95(entry.stackBefore,entry.before,entry.after,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) /\ IF WindowTop9(entry.stackBefore).kind="Interrupt" THEN /\ entry.before.id \in DOMAIN world.interruptSelections /\ world.interruptSelections[entry.before.id]=entry.selection /\ entry.selection.instance=entry.before.id /\ entry.selection.definition=entry.before.definition /\ entry.selection.windowId=entry.before.windowId /\ entry.selection.option=entry.before.option /\ entry.selection.transactionId=entry.before.transaction /\ entry.selection.source=entry.before.ability.source ELSE TRUE [] entry.kind="ConditionalFirst" -> IF WindowTop9(entry.stackBefore).kind="Interrupt" THEN /\ entry.parentWorld.id=world.id /\ entry.parentWorld.objects=world.objects /\ entry.parentWorld.turn=world.turn /\ entry.parentWorld.traversalControl=world.traversalControl /\ entry.parentWorld.conditional.definitions=world.conditional.definitions /\ entry.parentWorld.conditional.activationEpoch=world.conditional.activationEpoch /\ BeginCurrentConditionalInterrupt99(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.stackAfter, entry.before,entry.after,entry.definition,entry.snapshot,entry.instance,entry.option,entry.legality, entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt,entry.turnUses,entry.restrictions, entry.parentContext,entry.parentOrigin,entry.parentWorld,entry.parentHistory,cardFacts) ELSE BeginConditionalResolutionCore99(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.stackAfter, entry.before,entry.after,entry.definition,entry.lexemes,entry.snapshot,entry.instance,entry.option,entry.legality,entry.currentEffect, entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt,entry.turnUses,entry.restrictions,cardFacts) [] entry.kind="ConditionalNext" -> EnterNextConditionalInstruction96(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.before,entry.after, entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) [] entry.kind="PlayFirst" -> BeginPlayAbility97(entry.before,entry.after,entry.play,entry.stackBefore,world.objects,entry.present,entry.activity,entry.points, entry.instance,entry.usedInstances,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt,entry.restrictions) [] entry.kind="PlayNext" -> EnterNextPlayInstruction97(entry.before,entry.after,entry.play,entry.stackBefore,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) [] entry.kind="BarrierInstructionFirst" -> EnterFirstBarrierInstructionInstruction98(entry.before,entry.after,entry.encounter,world.traversalControl,entry.orderState,world.objects, entry.present,entry.activity,entry.points,entry.stackBefore,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) [] entry.kind="NestedBarrierInstructionFirst" -> EnterFirstInstructionBarrierInstruction98(entry.before,entry.after,entry.parentPlan,entry.parentAbility,entry.parentRuleStep,entry.orderState, world.objects,entry.present,entry.activity,entry.points,entry.stackBefore,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) [] entry.kind="BarrierInstructionNext" -> EnterNextBarrierInstructionInstruction98(entry.before,entry.after,entry.stackBefore,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt) [] entry.kind="Rule" -> /\ entry.ruleInvocation \in DOMAIN world.ruleInvocations /\ world.ruleInvocations[entry.ruleInvocation].tag="ActualRuleInvocation" /\ world.ruleInvocations[entry.ruleInvocation].step=entry.ruleStep /\ ~world.ruleInvocations[entry.ruleInvocation].returned /\ entry.sourceProcedure=world.ruleInvocations[entry.ruleInvocation].structure /\ entry.owner=world.ruleInvocations[entry.ruleInvocation].owner /\ LET announced == [entry.beforePlan EXCEPT !.announced=TRUE,!.targets=entry.targets.targets] IN /\ AnnounceInstructionTargets93(entry.beforePlan,announced,entry.targets,[id \in {} |-> id],entry.ruleStep) /\ EnterRuleInstruction93(announced,entry.afterPlan,entry.ruleStep) [] OTHER -> FALSE InstructionEntryOrigin99(entry,origin) == /\ origin.kind="Instruction" /\ origin.plan=entry.afterPlan /\ IF entry.kind="Rule" THEN origin.ruleStep=entry.ruleStep /\ RuleInstructionPlan93(origin.plan,origin.ruleStep) ELSE origin.ruleStep="NoValue" /\ origin.parent=entry.after.ability BarrierInstructionCallerEntry99(entry,world,cardFacts) == /\ entry.tag="ActualBarrierInstructionEntry" /\ entry.id \in Nat \ {0} /\ entry.snapshotId=world.id /\ entry.stackAfter=entry.stackBefore /\ entry.owner=entry.procedure.owner /\ CASE entry.kind="EncounterSelection" -> SelectNextBarrierInstruction98(entry.beforeLoop,entry.afterLoop,entry.procedure,entry.encounter,world.traversalControl,entry.step,entry.orderState, entry.currentOrder,entry.instance,entry.usedInstances,world.objects,entry.present,entry.activity,entry.points,entry.stackBefore) [] entry.kind="InstructionInvocation" -> EnterInstructionBarrierInstruction98(entry.beforeCalls,entry.afterCalls,entry.procedure,entry.parentPlan,entry.parentAbility,entry.ruleStep, entry.effect,entry.orderState,entry.instance,entry.usedInstances,entry.owner,entry.stackBefore,world.objects,entry.present,entry.activity,entry.points,cardFacts) [] OTHER -> FALSE ActualImminenceEntry99(entry,origin,world,cardFacts) == /\ ExpectedWorldValid99(world) /\ entry.id \in DOMAIN world.entries /\ world.entries[entry.id]=entry /\ IF origin.kind="BarrierInstruction" THEN BarrierInstructionCallerEntry99(entry,world,cardFacts) /\ origin.procedure=entry.procedure ELSE InstructionCallerEntry99(entry,world,cardFacts) /\ InstructionEntryOrigin99(entry,origin) NewExpectedRegistry99 == [contexts |-> [id \in {} |-> id],entryIds |-> {},usedContextIds |-> {}] BeginExpectedContext99(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts,beforeWould,afterWould,initialObservation) == /\ \A prior \in DOMAIN before.contexts : InitialWouldCaptured99(before.contexts[prior],beforeWould) /\ ActualImminenceEntry99(entry,origin,world,cardFacts) /\ entry.id \notin before.entryIds /\ id \in (Nat \ {0}) \ before.usedContextIds /\ ~\E other \in DOMAIN before.contexts : before.contexts[other].phase # "Returned" /\ WouldContextKey99(before.contexts[other].currentRef)=WouldContextKey99(OriginReference99(origin)) /\ owner=entry.owner /\ BarrierInstructionOwnerAtTop98(owner,entry.stackAfter) /\ InitialExpectedProjection99(origin,world,description,projection,initial) /\ LET context == NewExpectedContext99(id,entry.id,origin,world,description,initial,owner) IN /\ initialObservation=InitialWouldObservation99(context,initialObservation.id) /\ RecordWouldDescriptors99(beforeWould,afterWould,id,entry.id,context.initialRef,world.id,initial,context.initialWouldGroups, context.initialPeriods,InitialWouldOrder99(context),initialObservation) /\ after=[before EXCEPT !.entryIds=@ \cup {entry.id},!.usedContextIds=@ \cup {id}, !.contexts=[key \in DOMAIN @ \cup {id} |-> IF key=id THEN context ELSE @[key]]] ReplacementScopeCurrent99(record,context,world) == CASE record.scope.kind="Instruction" -> record.scope.context=WouldContextKey99(context.initialRef) [] record.scope.kind="SchemaAtom138" -> TraversalTimingPresent6(world.traversalControl.traversal) /\ record.scope.id=world.traversalControl.traversal.id [] record.scope.kind="Turn" -> record.scope.id=world.turn.id /\ ~world.turn.formalEnded [] record.scope.kind="WhileStaticActive" -> record.provider="Static" [] OTHER -> record.scope.period \in DOMAIN world.activePeriods ReplacementRecordActive99(record,context,world) == /\ ReplacementScopeCurrent99(record,context,world) /\ CASE record.provider="Static" -> /\ record.definition.syntax.kind="Static" /\ record.definition.activity.source.kind="Object" /\ record.definition.activity.source.object \in DOMAIN world.objects /\ StaticPartApplies94(record.definition.syntax,record.part, StaticAbilityActive94(record.definition.activity,record.definition.syntax,world.objects,world.conditional.present, world.conditional.cardActivity[record.definition.activity.source.object],world.conditional.activity,world.conditional.points),record.conditions) [] record.provider="Maintained" -> record.id \in world.liveReplacementIds [] record.provider="ImminentInterrupt" -> record.id \in DOMAIN context.temporaryReplacements /\ context.temporaryReplacements[record.id]=record [] OTHER -> FALSE ReplacementRecords99(context,world) == ReplacementOverlay99(world.replacementDefinitions,context.temporaryReplacements) ActiveReplacementBlueprints99(context,world) == [id \in {r \in DOMAIN ReplacementRecords99(context,world) : ReplacementRecordActive99(ReplacementRecords99(context,world)[r],context,world)} |-> ReplacementRecords99(context,world)[id].blueprint] ReplacementSourcesBound99(context,world,cardFacts) == /\ DOMAIN world.replacementDefinitions \cap DOMAIN context.temporaryReplacements={} /\ world.liveReplacementIds \subseteq DOMAIN world.replacementDefinitions /\ \A id \in DOMAIN ReplacementRecords99(context,world) : LET r == ReplacementRecords99(context,world)[id] IN /\ r.id=id /\ ReplacementBlueprintValid99(id,r.blueprint) /\ AbilityLexemesValid99(r.definition,r.lexemes,world.objects,cardFacts) /\ ReplacementText99(r.definition,r.lexemes) /\ r.blueprint.source=r.definition.syntax.source /\ r.blueprint.sourceSHA=r.lexemes.sourceSHA /\ r.blueprint.wouldGrouping \in {"Preserve","SeparateResults"} /\ r.bindingSnapshotId=world.id /\ r.provider \in {"Static","Maintained","ImminentInterrupt"} /\ IF r.provider="Static" THEN r.definition.syntax.kind="Static" ELSE /\ r.creation.tag="ResolvedReplacementCreation" /\ r.creation.replacement=id /\ r.creation.instruction.source=r.blueprint.source /\ r.creation.abilityInstance \in Nat /\ WouldContextValid99(r.creation.instruction) OpeningConditionalKeys99(context,world,history,ledger) == {key \in DOMAIN world.conditional.definitions : LET d == world.conditional.definitions[key] IN /\ ConditionalActive96(d,world.conditional) /\ InterruptRelevant99(d,world.lexemes[key],world.capabilities[key],context,world,history) /\ ConditionalInterruptPrimary99(d,world.capabilities[key],context,world,history) /\ IF d.primaryKind="Static" THEN ~ConditionalSibling96(d,ledger.instances) /\ StaticRetryAllowed96(d,ledger) ELSE TRUE} NewOpeningInterruptInstance99(id,d,snapshot,ledger,context,windowId,group) == [member |-> [ConditionalMember96(id,d,windowId,group) EXCEPT !.interrupt=TRUE],definition |-> ConditionalKey96(d),definitionCopy |-> d, status |-> "Pending",primaryKind |-> d.primaryKind,activationEpoch |-> snapshot.activationEpoch[ConditionalKey96(d)], checkpointId |-> ledger.lastCheckpoint,occurrence |-> context.imminenceId,hadSnapshot |-> ledger.lastSnapshot,expected |-> [i \in {} |-> i],used |-> FALSE] PrepareOpeningInterrupts99(beforeContext,afterContext,beforeLedger,afterLedger,origin,world,history,windowId,group,allocation,usedWindows,cardFacts) == /\ InitialWouldCaptured99(beforeContext,history) /\ beforeContext.phase="Replacing" /\ ExpectedContextOrigin99(beforeContext,origin) /\ ExpectedContextWorld99(beforeContext,world) /\ WouldViewCurrent99(history,beforeContext,world) /\ CurrentInterruptWorld99(world,beforeLedger,cardFacts) /\ ReplacementSourcesBound99(beforeContext,world,cardFacts) /\ ReplacementPreparationComplete99(beforeContext.state,ActiveReplacementBlueprints99(beforeContext,world)) /\ windowId \in (Nat \ {0}) \ usedWindows /\ group \in Nat \ {0} /\ LET candidates == OpeningConditionalKeys99(beforeContext,world,history,beforeLedger) ids == {allocation[key] : key \in candidates} recognitions == {[definition |-> key,occurrence |-> beforeContext.imminenceId] : key \in candidates} additions == [id \in ids |-> LET key == CHOOSE k \in candidates : allocation[k]=id IN NewOpeningInterruptInstance99(id,world.conditional.definitions[key],world.conditional,beforeLedger,beforeContext,windowId,group)] IN /\ DOMAIN allocation=candidates /\ Cardinality(ids)=Cardinality(candidates) /\ ids \subseteq (Nat \ {0}) \ DOMAIN beforeLedger.instances /\ recognitions \cap beforeLedger.interruptRecognitions={} /\ afterLedger=[beforeLedger EXCEPT !.instances=ReplacementOverlay99(@,additions),!.interruptRecognitions=@ \cup recognitions] /\ afterContext=[beforeContext EXCEPT !.phase="Prepared",!.preparedEffects=beforeContext.state.effects,!.openingRef=beforeContext.currentRef, !.conditionalIds=ids,!.conditionalDefinitions=[key \in candidates |-> world.conditional.definitions[key]], !.windowId=windowId,!.group=group,!.openingMembers=[id \in ids |-> additions[id].member]] PreparedOriginOpening99(context,site) == [tag |-> "PriorityWindowOpening",windowId |-> context.windowId,kind |-> "Interrupt",site |-> site, members |-> context.conditionalIds,instances |-> context.openingMembers,group |-> context.group,beginning |-> NoTimingRef9, instruction |-> context.openingRef,effectRevision |-> context.openingRef.revision+1, modifiersExist |-> TRUE,preparation |-> <<"ExpectedEffects","ReplacementEffects","ConditionalPending">>] OpenPreparedInterrupt99(beforeContext,afterContext,beforeStack,afterStack,origin,world,history,ledger,site,opening,usedWindows,cardFacts) == /\ beforeContext.phase="Prepared" /\ ExpectedContextOrigin99(beforeContext,origin) /\ ExpectedContextWorld99(beforeContext,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ BarrierInstructionOwnerAtTop98(beforeContext.owner,beforeStack) /\ WouldViewCurrent99(history,beforeContext,world) /\ site.turnId=world.turn.id /\ site.active=world.turn.owner /\ opening=PreparedOriginOpening99(beforeContext,site) /\ LET proposed == NewPriorityWindow9(beforeContext.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,site),beforeContext.openingMembers, beforeContext.group,NoTimingRef9,beforeContext.openingRef,beforeContext.openingRef.revision+1) IN /\ beforeContext.conditionalIds # {} \/ OpeningPaidRelevant99(beforeContext,world,history,proposed) # {} /\ IF origin.kind="BarrierInstruction" THEN OpenBarrierInstructionInterrupt98(origin.procedure,beforeStack,afterStack,beforeContext.windowId,site,beforeContext.openingMembers,opening,usedWindows) ELSE OpenInstructionInterrupt93(beforeStack,afterStack,beforeContext.windowId,site,beforeContext.openingMembers,opening,usedWindows, origin.plan,origin.parent,origin.ruleStep) /\ afterContext=[beforeContext EXCEPT !.phase="WindowOpen",!.site=site] NoPreparedInterrupt99(before,after,origin,world,history,ledger,stack,site,cardFacts) == /\ before.phase="Prepared" /\ ExpectedContextOrigin99(before,origin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ WouldViewCurrent99(history,before,world) /\ site.turnId=world.turn.id /\ site.active=world.turn.owner /\ before.conditionalIds={} /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(stack,site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN /\ OpeningPaidRelevant99(before,world,history,proposed)={} /\ after=[before EXCEPT !.phase="Cleared",!.site=site] OriginAfterRevisions99(before,after,count) == /\ ImminentOrigin99(before) /\ count \in Nat /\ IF before.kind="BarrierInstruction" THEN after=[before EXCEPT !.procedure.revision=@+count] ELSE after=[before EXCEPT !.plan.revision=@+count] AppliedReplacementContext99(before,after,beforeOrigin,afterOrigin,world,nextState,count) == /\ OriginAfterRevisions99(beforeOrigin,afterOrigin,count) /\ LET oldIds == DOMAIN before.state.effects newIds == DOMAIN nextState.effects archive == ReplacementOverlay99(before.ancestryArchive,ReplacementOverlay99(before.state.ancestry,nextState.ancestry)) IN after=[before EXCEPT !.state=nextState,!.currentRef=OriginReference99(afterOrigin),!.currentWorld=world.id, !.templates=ReplacementOverlay99(@,nextState.effects),!.ancestryArchive=archive, !.retiredEffects=@ \cup (oldIds \ newIds),!.wouldGroups=after.wouldGroups] ApplyAutomaticReplacements99(before,after,beforeOrigin,afterOrigin,world,states,steps,cardFacts,history) == /\ InitialWouldCaptured99(before,history) /\ before.phase="Replacing" /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ ReplacementSourcesBound99(before,world,cardFacts) /\ PrepareReplacementEffects99(before.state,states[Len(states)],ActiveReplacementBlueprints99(before,world), [id |-> world.id,controllers |-> world.controllers],states,steps) /\ AppliedReplacementContext99(before,after,beforeOrigin,afterOrigin,world,states[Len(states)],Len(steps)) /\ after.wouldGroups=ReplacementWouldGroups99(before.wouldGroups,states,steps,ActiveReplacementBlueprints99(before,world)) ObserveCurrentExpectedWould99(before,after,context,origin,world,order,receipt) == /\ ExpectedContextOrigin99(context,origin) /\ ExpectedContextWorld99(context,world) /\ RecordWouldDescriptors99(before,after,context.id,context.imminenceId,context.currentRef,world.id,context.state.effects, [id \in DOMAIN context.state.effects |-> context.wouldGroups[id]],ActualWouldPeriods99(world),order,receipt) ContextInstructionClearance99(context,windowId) == [tag |-> "InstructionInterruptReturn",instruction |-> context.currentRef.id,origin |-> context.currentRef.origin, abilityInstance |-> context.currentRef.abilityInstance,index |-> context.currentRef.index,source |-> context.currentRef.source, sourceZone |-> context.currentRef.sourceZone,revision |-> context.currentRef.revision,windowId |-> windowId, openingRevision |-> context.openingRef.revision,complete |-> TRUE] ContextNoModifiers99(context) == [tag |-> "NoInstructionInterruptModifiers",instruction |-> context.currentRef,conditionalInstances |-> {},paidInterruptAbilities |-> {}] ClearPreparedInstruction99(before,after,origin,world,history,ledger,beforeStack,afterStack,route,clearance,cardFacts) == /\ origin.kind="Instruction" /\ ExpectedContextOrigin99(before,origin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ WouldViewCurrent99(history,before,world) /\ route \in {"Window","NoModifiers"} /\ IF route="Window" THEN /\ CurrentInterruptWindow99(before,beforeStack) /\ clearance=ContextInstructionClearance99(before,before.windowId) /\ ReturnInstructionInterrupt93(beforeStack,afterStack,origin.plan,origin.parent,origin.ruleStep,clearance) /\ \A id \in before.conditionalIds : ledger.instances[id].status \in {"Complete","Lost"} ELSE /\ before.phase="Cleared" /\ before.conditionalIds={} /\ beforeStack=afterStack /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,before.site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN OpeningPaidRelevant99(before,world,history,proposed)={} /\ clearance=ContextInstructionClearance99(before,0) /\ NoInstructionInterrupt93(origin.plan,origin.parent,origin.ruleStep,ContextNoModifiers99(before),clearance) /\ BarrierInstructionOwnerAtTop98(before.owner,afterStack) /\ after=[before EXCEPT !.phase="InstructionCleared",!.clearance=clearance] AtomicAbilityCaller99(context,origin,world,ledger,stack,call) == /\ origin.kind="Instruction" /\ origin.plan.origin="Ability" /\ call.before.phase="Imminent" /\ call.before=context.entry.after /\ call.kind=call.before.ability.kind /\ call.before.ability=origin.parent /\ call.before.ability.phase="Imminent" /\ CASE call.kind="Paid" -> PaidProcedureAtTop95(stack,call.before) /\ call.before.costPaid [] call.kind="Conditional" -> /\ ConditionalAtTop96(stack,call.before) /\ ConditionalProcedureBound96(ledger,call.before) /\ ledger.instances[call.before.id].status="Imminent" /\ ContextInitialObservationBound99(ledger,call.before,context) [] call.kind="Play" -> PlayOwnerAtTop97(call.before,call.play,stack) /\ PlayAbilityBound97(call.before) [] call.kind="BarrierInstruction" -> BarrierInstructionOwnerAtTop98(call.before.owner,stack) /\ BarrierInstructionBarrierInstructionBound98(call.before) [] OTHER -> FALSE BeginClearedAbilityInstruction99(before,after,beforeOrigin,afterOrigin,world,beforeLedger,afterLedger,stack,call,clearance,afterPlan) == /\ before.phase="InstructionCleared" /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ AtomicAbilityCaller99(before,beforeOrigin,world,beforeLedger,stack,call) /\ clearance=before.clearance /\ LET ability == [call.before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(call.before.ability,ability,beforeOrigin.plan,afterPlan,clearance) /\ call.after=[call.before EXCEPT !.ability=ability,!.phase="Resolve"] /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan,!.parent=ability] /\ IF call.kind="Conditional" THEN afterLedger=[beforeLedger EXCEPT !.instances[call.before.id].status="Resolving"] ELSE afterLedger=beforeLedger /\ after=[before EXCEPT !.phase="Resolving",!.actualEffects=ActualExpectedEffects99(before.state.effects)] BeginClearedRuleInstruction99(before,after,beforeOrigin,afterOrigin,world,stack,clearance,afterPlan) == /\ before.phase="InstructionCleared" /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.plan.origin="Rule" /\ before.entry.ruleInvocation \in DOMAIN world.ruleInvocations /\ ~world.ruleInvocations[before.entry.ruleInvocation].returned /\ world.ruleInvocations[before.entry.ruleInvocation].step=beforeOrigin.ruleStep /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ clearance=before.clearance /\ BeginRuleInstructionAtomic93(beforeOrigin.plan,afterPlan,beforeOrigin.ruleStep,clearance) /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan] /\ after=[before EXCEPT !.phase="Resolving",!.actualEffects=ActualExpectedEffects99(before.state.effects)] FinishExpectedRuleInstruction99(before,after,beforeOrigin,afterOrigin,world,actualEffects,actualReturn,step,afterPlan) == /\ before.phase="Resolving" /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.plan.origin="Rule" /\ before.currentRef=InstructionWindowRef93(beforeOrigin.plan) /\ beforeOrigin.plan.phase="Resolving" /\ actualEffects=before.actualEffects /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=before.id /\ actualReturn.instruction=before.currentRef /\ actualReturn.snapshotId=world.id /\ actualReturn.effects=actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ step.expectedReturn=actualReturn /\ CarryInstructionStep93(beforeOrigin.plan,afterPlan,step) /\ afterPlan.phase="Complete" /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan] /\ after=[before EXCEPT !.phase="Returned"] SelectedInterrupt99(p,d,lex,capabilities,context,world) == [tag |-> "SelectedInterrupt",instance |-> p.id,definition |-> d,lexemes |-> lex,capabilities |-> capabilities, source |-> p.ability.source,windowId |-> p.windowId,option |-> p.option,transactionId |-> p.transaction, contextId |-> context.id,imminenceId |-> context.imminenceId,selectedReference |-> context.currentRef,snapshotId |-> world.id] ReserveCurrentPaidWithSelection99(beforeStack,afterStack,p,selection,id,d,c,context,origin,world,history,ledger,option,legality,usedInstances,cardFacts) == /\ ReserveCurrentPaidInterrupt99(beforeStack,afterStack,p,id,d,c,context,origin,world,history,ledger,option,legality,usedInstances,cardFacts) /\ selection=SelectedInterrupt99(p,d,world.lexemes[AbilityKey99(d)],world.capabilities[AbilityKey99(d)],context,world) SelectedInterruptAtTop99(selection,p,context,stack,plan,world,cardFacts) == /\ selection.tag="SelectedInterrupt" /\ selection.contextId=context.id /\ selection.imminenceId=context.imminenceId /\ WouldContextKey99(selection.selectedReference)=WouldContextKey99(context.initialRef) /\ selection.instance=p.id /\ selection.definition=p.definition /\ selection.source=p.ability.source /\ selection.windowId=p.windowId /\ selection.option=p.option /\ selection.transactionId=p.transaction /\ AbilityLexemesValid99(p.definition,selection.lexemes,world.objects,cardFacts) /\ AbilityInterrupt99(p.definition,selection.lexemes) /\ p.ability.kind \in {"Paid","Conditional"} /\ p.ability.kind=p.definition.syntax.kind /\ p.phase="Resolve" /\ p.ability.phase="Resolving" /\ plan.phase="Resolving" /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ CurrentInterruptWindow99(context,stack) /\ LET w == WindowTop9(stack) IN /\ w.id=p.windowId /\ w.busy=p.option /\ w.busyTransaction=p.transaction /\ w.busy.id # 0 /\ w.stage \in {"Resolving","Closed"} /\ (p.ability.kind="Conditional" => w.busy.instance=p.id) /\ (p.ability.kind="Paid" => p.costPaid) ExpectedControlBound99(parent,modifier,plan,operation) == /\ modifier.phase="Resolving" /\ modifier.currentRef=InstructionWindowRef93(plan) /\ plan.phase="Resolving" /\ operation.id \in DOMAIN modifier.actualEffects /\ modifier.actualEffects[operation.id]=operation /\ operation.parentContextId=parent.id /\ operation.parentImminenceId=parent.imminenceId /\ operation.parentReference=WouldContextKey99(parent.initialRef) /\ operation.kind \in {"PreventAmount","PreventWhole","AddExpectedValue","SetExpectedValue","ExampleFamily091HarmClassAToOne","NoExpectedEffects"} /\ operation.effectId \in Nat \ {0} /\ InterruptPatternValid99(operation.pattern) /\ (operation.kind="PreventAmount" => operation.value \in Nat) /\ (operation.kind \in {"AddExpectedValue","SetExpectedValue"} => operation.value \in Int) ExpectedControlStep99(beforeEffects,afterEffects,operation) == CASE operation.kind="PreventAmount" -> PreventExpectedAmount99(beforeEffects,afterEffects,operation.effectId,operation.value) [] operation.kind="PreventWhole" -> PreventExpectedWhole99(beforeEffects,afterEffects,operation.effectId) [] operation.kind="AddExpectedValue" -> ModifyExpectedEffectValue99(beforeEffects,afterEffects,operation.effectId,operation.value) [] operation.kind="SetExpectedValue" -> SetExpectedEffectValue99(beforeEffects,afterEffects,operation.effectId,operation.value) [] operation.kind="ExampleFamily091HarmClassAToOne" -> ExampleFamily091HarmClassAToOne99(beforeEffects,afterEffects,operation.effectId) [] operation.kind="NoExpectedEffects" -> afterEffects=beforeEffects [] OTHER -> FALSE ExpectedControlApplies99(effects,operation) == /\ operation.effectId \in DOMAIN effects /\ ReplacementPatternMatches99(operation.pattern,effects[operation.effectId]) /\ CASE operation.kind="PreventAmount" -> effects[operation.effectId].kind \in {"Damage","ExposureMarkers"} /\ ExpectedEffectPreventable99(effects,operation.effectId) [] operation.kind="PreventWhole" -> ExpectedEffectPreventable99(effects,operation.effectId) [] operation.kind="ExampleFamily091HarmClassAToOne" -> ExampleFamily091Relevant99(effects,operation.effectId) [] operation.kind \in {"AddExpectedValue","SetExpectedValue"} -> ExpectedValuePresent99(effects,operation.effectId) [] operation.kind="NoExpectedEffects" -> TRUE [] OTHER -> FALSE ApplyExpectedControlCore99(before,after,beforeOrigin,afterOrigin,modifier,plan,operation,world,afterEffects) == /\ ExpectedContextOrigin99(before,beforeOrigin) /\ before.phase="WindowOpen" /\ ExpectedContextWorld99(before,world) /\ ExpectedControlBound99(before,modifier,plan,operation) /\ operation.operationId \in (Nat \ {0}) \ before.modificationIds /\ IF ExpectedControlApplies99(before.state.effects,operation) THEN ExpectedControlStep99(before.state.effects,afterEffects,operation) ELSE afterEffects=before.state.effects /\ AdvanceImminentOrigin99(beforeOrigin,afterOrigin) /\ after=[before EXCEPT !.currentRef=OriginReference99(afterOrigin),!.state.effects=afterEffects, !.state.ancestry=[id \in DOMAIN afterEffects |-> before.state.ancestry[id]], !.ancestryArchive=ReplacementOverlay99(@,before.state.ancestry), !.removedEffects=@ \cup (DOMAIN before.state.effects \ DOMAIN afterEffects),!.modificationIds=@ \cup {operation.operationId}, !.modifications=Append(@,[kind |-> operation.kind,operation |-> operation,modifier |-> modifier.currentRef, beforeEffects |-> before.state.effects,afterEffects |-> afterEffects,from |-> before.currentRef,to |-> OriginReference99(afterOrigin)])] ResolvedControlReceipt99(before,after,modifier,p,operation) == [tag |-> "ResolvedInterruptEffectModification",status |-> "Resolved",classification |-> "Interrupt",abilityKind |-> p.ability.kind, id |-> operation.operationId,abilityInstance |-> p.id,source |-> p.ability.source, beforeEffects |-> before.state.effects,afterEffects |-> after.state.effects, revisionBefore |-> before.currentRef.revision,revisionAfter |-> after.currentRef.revision, instruction |-> modifier.currentRef,operation |-> operation.kind] ResolvePaidInterruptControl99(before,after,beforeOrigin,afterOrigin,modifier,world,selection,call,operation,afterEffects,resolved,cardFacts) == /\ SelectedInterruptAtTop99(selection,call.before,before,call.stack,call.beforePlan,world,cardFacts) /\ call.before.ability.kind="Paid" /\ ApplyExpectedControlCore99(before,after,beforeOrigin,afterOrigin,modifier,call.beforePlan,operation,world,afterEffects) /\ CarryPaidInstruction95(call.stack,call.before,call.after,call.beforePlan,call.afterPlan,call.step) /\ call.step.expectedControl=operation /\ resolved=ResolvedControlReceipt99(before,after,modifier,call.before,operation) ResolveConditionalInterruptControl99(before,after,beforeOrigin,afterOrigin,modifier,world,selection,call,operation,afterEffects,resolved,cardFacts) == /\ SelectedInterruptAtTop99(selection,call.before,before,call.beforeStack,call.beforePlan,world,cardFacts) /\ call.before.ability.kind="Conditional" /\ ApplyExpectedControlCore99(before,after,beforeOrigin,afterOrigin,modifier,call.beforePlan,operation,world,afterEffects) /\ CarryConditionalInstruction96(call.beforeLedger,call.candidateLedger,call.afterLedger,call.beforeStack,call.afterStack, call.before,call.after,call.beforePlan,call.afterPlan,call.step,call.beforeSnapshot,call.afterSnapshot) /\ call.step.expectedControl=operation /\ resolved=ResolvedControlReceipt99(before,after,modifier,call.before,operation) CompleteModifierExpectedContext99(before,after,call,world,actualReturn) == /\ before.phase="Resolving" /\ before.currentRef=InstructionWindowRef93(call.beforePlan) /\ call.afterPlan.phase="Complete" /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=before.id /\ actualReturn.instruction=before.currentRef /\ actualReturn.snapshotId=world.id /\ actualReturn.effects=before.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ call.step.expectedReturn=actualReturn /\ after=[before EXCEPT !.phase="Returned"] ResolvePaidInterruptAndReturn99(before,after,beforeOrigin,afterOrigin,beforeModifier,afterModifier,world,selection,call,operation, afterEffects,resolved,actualReturn,cardFacts) == /\ ResolvePaidInterruptControl99(before,after,beforeOrigin,afterOrigin,beforeModifier,world,selection,call,operation,afterEffects,resolved,cardFacts) /\ CompleteModifierExpectedContext99(beforeModifier,afterModifier,call,world,actualReturn) ResolveConditionalInterruptAndReturn99(before,after,beforeOrigin,afterOrigin,beforeModifier,afterModifier,world,selection,call,operation, afterEffects,resolved,actualReturn,cardFacts) == /\ ResolveConditionalInterruptControl99(before,after,beforeOrigin,afterOrigin,beforeModifier,world,selection,call,operation,afterEffects,resolved,cardFacts) /\ CompleteModifierExpectedContext99(beforeModifier,afterModifier,call,world,actualReturn) ExpectedReplacementCreationBound99(context,modifier,plan,operation,record) == /\ modifier.phase="Resolving" /\ modifier.currentRef=InstructionWindowRef93(plan) /\ plan.phase="Resolving" /\ operation.id \in DOMAIN modifier.actualEffects /\ modifier.actualEffects[operation.id]=operation /\ operation.kind="CreateReplacement" /\ operation.parentContextId=context.id /\ operation.parentImminenceId=context.imminenceId /\ operation.parentReference=WouldContextKey99(context.initialRef) /\ record.id=operation.replacementId /\ record.blueprint=operation.blueprint /\ record.provider="ImminentInterrupt" /\ record.scope=[kind |-> "Instruction",context |-> WouldContextKey99(context.initialRef)] /\ record.creation=[tag |-> "ResolvedReplacementCreation",replacement |-> record.id,instruction |-> modifier.currentRef,abilityInstance |-> plan.abilityInstance] CreateImmediateReplacementCore99(before,after,beforeOrigin,afterOrigin,modifier,world,selection,p,plan,operation,record, afterUsedIds,states,steps,cardFacts) == /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ before.phase="WindowOpen" /\ ExpectedReplacementCreationBound99(before,modifier,plan,operation,record) /\ record.definition=p.definition /\ record.lexemes=selection.lexemes /\ record.bindingSnapshotId=world.id /\ record.id \in (Nat \ {0}) \ (world.usedReplacementIds \cup DOMAIN before.temporaryReplacements) /\ afterUsedIds=world.usedReplacementIds \cup {record.id} /\ LET created == [before EXCEPT !.temporaryReplacements=ReplacementOverlay99(@,[id \in {record.id} |-> record])] replacements == ActiveReplacementBlueprints99(created,world) IN /\ ReplacementSourcesBound99(created,world,cardFacts) /\ ApplyCreatedReplacementImmediately99(before.state,states[Len(states)],replacements,record.id, [id |-> world.id,controllers |-> world.controllers],states,steps) /\ AppliedReplacementContext99(created,after,beforeOrigin,afterOrigin,world,states[Len(states)],Len(steps)+1) /\ after.wouldGroups=ReplacementWouldGroups99(before.wouldGroups,states,steps,replacements) ResolvePaidReplacementAndReturn99(before,after,beforeOrigin,afterOrigin,beforeModifier,afterModifier,world,selection,call, operation,record,afterUsedIds,states,steps,actualReturn,cardFacts) == /\ SelectedInterruptAtTop99(selection,call.before,before,call.stack,call.beforePlan,world,cardFacts) /\ call.before.ability.kind="Paid" /\ CreateImmediateReplacementCore99(before,after,beforeOrigin,afterOrigin,beforeModifier,world,selection,call.before,call.beforePlan,operation,record, afterUsedIds,states,steps,cardFacts) /\ CarryPaidInstruction95(call.stack,call.before,call.after,call.beforePlan,call.afterPlan,call.step) /\ call.step.expectedReplacement=operation /\ CompleteModifierExpectedContext99(beforeModifier,afterModifier,call,world,actualReturn) ResolveConditionalReplacementAndReturn99(before,after,beforeOrigin,afterOrigin,beforeModifier,afterModifier,world,selection,call, operation,record,afterUsedIds,states,steps,actualReturn,cardFacts) == /\ SelectedInterruptAtTop99(selection,call.before,before,call.beforeStack,call.beforePlan,world,cardFacts) /\ call.before.ability.kind="Conditional" /\ CreateImmediateReplacementCore99(before,after,beforeOrigin,afterOrigin,beforeModifier,world,selection,call.before,call.beforePlan,operation,record, afterUsedIds,states,steps,cardFacts) /\ CarryConditionalInstruction96(call.beforeLedger,call.candidateLedger,call.afterLedger,call.beforeStack,call.afterStack, call.before,call.after,call.beforePlan,call.afterPlan,call.step,call.beforeSnapshot,call.afterSnapshot) /\ call.step.expectedReplacement=operation /\ CompleteModifierExpectedContext99(beforeModifier,afterModifier,call,world,actualReturn) ReserveNormalPaid99(before,after,p,id,d,lex,c,option,legality,usedInstances,cardFacts) == /\ ~AbilityInterrupt99(d,lex) /\ ReservePaidAbility99(before,after,p,id,d,lex,c,option,legality,usedInstances,cardFacts) ReserveCurrentMidItemInspection99(before,after,p,id,d,lex,c,option,legality,usedInstances,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034,cardFacts) == /\ Len(before)>0 /\ id \in (Nat \ {0}) \ usedInstances /\ ~AbilityInterrupt99(d,lex) /\ PaidEligibility99(d,lex,c,WindowTop9(before),cardFacts) /\ PaidOptionMatches95(d,option,WindowTop9(before)) /\ BeginMidItemInspectionOption9(before,after,option,c.objects,legality,a,afterItemInspection,midOption,options,mustRetire,exampleFamily034) /\ p=OpenPaidProcedure95(id,d,option,WindowTop9(before),legality.transactionId, IF d.syntax.source.kind="Object" THEN c.objects[d.syntax.source.object].zone ELSE "Rule") PublishSelectedPaidInterrupt99(beforeWorld,afterWorld,beforeStack,afterStack,p,selection,id,d,c,context,origin,history,ledger, option,legality,usedInstances,cardFacts) == /\ ReserveCurrentPaidWithSelection99(beforeStack,afterStack,p,selection,id,d,c,context,origin,beforeWorld,history,ledger, option,legality,usedInstances,cardFacts) /\ LET selections == IF "interruptSelections" \in DOMAIN beforeWorld THEN beforeWorld.interruptSelections ELSE [key \in {} |-> key] IN /\ id \notin DOMAIN selections /\ afterWorld=ReplacementOverlay99(beforeWorld,[interruptSelections |-> ReplacementOverlay99(selections,[key \in {id} |-> selection])]) SelectCurrentConditionalInterrupt99(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,selection,d,snapshot,id,option,legality, plan,afterPlan,targets,entry,turnUses,restrictions,context,origin,world,history,cardFacts) == /\ BeginCurrentConditionalInterrupt99(beforeLedger,afterLedger,beforeStack,afterStack,p,afterP,d,snapshot,id,option,legality, plan,afterPlan,targets,entry,turnUses,restrictions,context,origin,world,history,cardFacts) /\ selection=SelectedInterrupt99(afterP,d,world.lexemes[AbilityKey99(d)],world.capabilities[AbilityKey99(d)],context,world) PassCurrentInterrupt99(beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack,player,context,origin,world,history, beforeSnapshot,afterSnapshot,cardFacts) == /\ CurrentInterruptWorld99(world,beforeLedger,cardFacts) /\ ExpectedContextOrigin99(context,origin) /\ ExpectedContextWorld99(context,world) /\ WouldViewCurrent99(history,context,world) /\ CurrentInterruptWindow99(context,beforeStack) /\ beforeSnapshot=world.conditional /\ PassConditionalPriority96(beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack,player, CurrentEffectReceipt99(context,world,history,beforeLedger,WindowTop9(beforeStack)),beforeSnapshot,afterSnapshot) FinishExpectedAbilityInstruction99(before,after,beforeOrigin,afterOrigin,world,call,actualReturn) == /\ before.phase="Resolving" /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.plan.origin="Ability" /\ before.currentRef=InstructionWindowRef93(beforeOrigin.plan) /\ call.beforePlan=beforeOrigin.plan /\ call.before.ability=beforeOrigin.parent /\ call.kind=call.before.ability.kind /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=before.id /\ actualReturn.instruction=before.currentRef /\ actualReturn.snapshotId=world.id /\ actualReturn.effects=before.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ call.step.expectedReturn=actualReturn /\ CASE call.kind="Paid" -> CarryPaidInstruction95(call.stack,call.before,call.after,call.beforePlan,call.afterPlan,call.step) [] call.kind="Conditional" -> CarryConditionalInstruction96(call.beforeLedger,call.candidateLedger,call.afterLedger, call.beforeStack,call.afterStack,call.before,call.after,call.beforePlan,call.afterPlan,call.step,call.beforeSnapshot,call.afterSnapshot) [] call.kind="Play" -> CarryPlayInstruction97(call.before,call.after,call.play,call.stack,call.beforePlan,call.afterPlan,call.step) [] call.kind="BarrierInstruction" -> CarryBarrierInstructionInstruction98(call.before,call.after,call.stack,call.beforePlan,call.afterPlan,call.step) [] OTHER -> FALSE /\ call.afterPlan.phase="Complete" /\ afterOrigin=[beforeOrigin EXCEPT !.plan=call.afterPlan,!.parent=call.after.ability] /\ after=[before EXCEPT !.phase="Returned"] BarrierInstructionWasPrevented99(context,p) == \E index \in 1..Len(context.modifications) : LET modification == context.modifications[index] IN IF modification.kind # "PreventWhole" THEN FALSE ELSE LET operation == modification.operation id == operation.effectId IN /\ operation.kind="PreventWhole" /\ operation.parentContextId=context.id /\ operation.parentImminenceId=context.imminenceId /\ operation.parentReference=WouldContextKey99(context.initialRef) /\ id \in DOMAIN modification.beforeEffects /\ id \notin DOMAIN modification.afterEffects /\ modification.beforeEffects[id].kind="BarrierInstruction" /\ modification.beforeEffects[id].barrierInstruction=p.barrierInstruction /\ modification.beforeEffects[id].baseOrigin=p.ability.source /\ WouldContextValid99(modification.modifier) /\ modification.modifier.origin="Ability" ExpectedBarrierInstructionProjection99(context,p,payload,prevented) == /\ context.currentRef=BarrierInstructionWindowRef98(p) /\ BarrierInstructionImminent98(p) /\ IF DOMAIN context.state.effects={} THEN prevented /\ payload=p.payload /\ BarrierInstructionWasPrevented99(context,p) ELSE /\ ~prevented /\ Cardinality(DOMAIN context.state.effects)=1 /\ LET id == CHOOSE i \in DOMAIN context.state.effects : TRUE effect == context.state.effects[id] IN /\ effect.kind="BarrierInstruction" /\ effect.barrierInstruction=p.barrierInstruction /\ effect.baseOrigin=p.ability.source /\ effect.payload.kind="BarrierInstructionTemplate" /\ Len(effect.payload.instructions)>0 /\ payload=[p.definition EXCEPT !.instructions=effect.payload.instructions] BarrierInstructionContextClearance99(context,windowId,p) == [tag |-> "BarrierInstructionInterruptReturn",barrierInstruction |-> BarrierInstructionWindowRef98(p),windowId |-> windowId, openingRevision |-> context.openingRef.revision,complete |-> TRUE] ClearPreparedBarrierInstruction99(before,after,beforeOrigin,afterOrigin,world,history,ledger,beforeStack,afterStack,route, payload,prevented,clearance,cardFacts) == /\ beforeOrigin.kind="BarrierInstruction" /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ WouldViewCurrent99(history,before,world) /\ ExpectedBarrierInstructionProjection99(before,beforeOrigin.procedure,payload,prevented) /\ LET p == [beforeOrigin.procedure EXCEPT !.payload=payload,!.ability.instructions=payload.instructions,!.prevented=prevented] ready == [p EXCEPT !.phase="FirstTargets"] IN /\ route \in {"Window","NoModifiers"} /\ IF route="Window" THEN /\ CurrentInterruptWindow99(before,beforeStack) /\ clearance=BarrierInstructionContextClearance99(before,before.windowId,p) /\ ReturnBarrierInstructionInterrupt98(p,ready,beforeStack,afterStack,clearance) /\ \A id \in before.conditionalIds : ledger.instances[id].status \in {"Complete","Lost"} ELSE /\ before.phase="Cleared" /\ before.conditionalIds={} /\ beforeStack=afterStack /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,before.site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN OpeningPaidRelevant99(before,world,history,proposed)={} /\ clearance=BarrierInstructionContextClearance99(before,0,p) /\ NoBarrierInstructionInterrupt98(p,ready,beforeStack, [tag |-> "NoBarrierInstructionInterruptModifiers",barrierInstruction |-> BarrierInstructionWindowRef98(p),conditionalInstances |-> {},paidInterruptAbilities |-> {}],clearance) /\ afterOrigin=[beforeOrigin EXCEPT !.procedure=ready] /\ after=[before EXCEPT !.phase="Returned",!.actualEffects=ActualExpectedEffects99(before.state.effects),!.clearance=clearance] NewLingeringRegistry910 == [effects |-> [id \in {} |-> id],usedEffects |-> {},creations |-> {},cleanupIds |-> {}] LingeringObjectActive910(source,world) == IF source.kind # "Object" THEN FALSE ELSE IF source.object \notin DOMAIN world.objects THEN FALSE ELSE PlayCardDefaultActive4(world.objects[source.object],world.gameStarted,world.cardFacts, source.object \in world.playActivated) LingeringTimingRefs910(world) == (IF TurnFrameValid5(world.turn) /\ ~world.turn.formalEnded THEN {TimingRef9("Turn",world.turn.id)} ELSE {}) \cup (IF TraversalTimingPresent6(world.control.traversal) THEN {TimingRef9("SchemaAtom138",world.control.traversal.id)} ELSE {}) \cup (IF world.turnPhase.id # 0 /\ ~world.turnPhase.ended /\ ~world.turn.formalEnded THEN {TimingRef9("TurnPhase",world.turnPhase.id)} ELSE {}) \cup (IF TraversalTimingPresent6(world.control.traversal) /\ world.control.traversal.phaseId \notin world.control.phaseEndedIds THEN {TimingRef9("TraversalPhase",world.control.traversal.phaseId)} ELSE {}) \cup {TimingRef9("TraversalPhase",id) : id \in {id \in DOMAIN world.encounters : EncounterTimingLive95(world.encounters[id],world.control)}} \cup {TimingRef9("Inspection",id) : id \in {id \in DOMAIN world.siteInspections : world.siteInspections[id].active /\ ~world.siteInspections[id].complete}} \cup {TimingRef9("ItemInspection",id) : id \in {id \in DOMAIN world.itemInspections : StillItemInspectioning7(world.itemInspections[id],world.objects)}} BindTimingDuration910(requested,world) == [kind |-> "Timing",ref |-> IF requested \in LingeringTimingRefs910(world) THEN requested ELSE NoTimingRef9] StatedDurationReceipt910(effect,world) == [tag |-> "LingeringStatedDuration",effectId |-> effect.id,source |-> effect.source, creation |-> effect.creation,specification |-> effect.baseDuration.specification,snapshotId |-> world.id] LingeringBaseAlive910(effect,world) == CASE effect.baseDuration.kind="Timing" -> effect.baseDuration.ref \in LingeringTimingRefs910(world) [] effect.baseDuration.kind="UntilResolution" -> effect.baseDuration.instance \notin world.finishedInstances [] effect.baseDuration.kind="DelayedResolution" -> effect.baseDuration.effectId \notin world.finishedDelayedEffects [] effect.baseDuration.kind="Stated" -> /\ effect.id \in DOMAIN world.statedDurations /\ world.statedDurations[effect.id].receipt=StatedDurationReceipt910(effect,world) /\ world.statedDurations[effect.id].active [] OTHER -> FALSE LingeringShorterThanTurn910(effect,world) == IF effect.durationClass="Encounter" THEN TRUE ELSE /\ effect.id \in DOMAIN world.durationComparisons /\ world.durationComparisons[effect.id].tag="LingeringDurationComparison" /\ world.durationComparisons[effect.id].effect=effect /\ world.durationComparisons[effect.id].base=effect.baseDuration /\ world.durationComparisons[effect.id].snapshotId=world.id /\ world.durationComparisons[effect.id].turn=TimingRef9("Turn",world.turn.id) /\ world.durationComparisons[effect.id].shorterThanTurn GebrMaintenance910(effect,world) == {id \in DOMAIN world.extenders : LET r == world.extenders[id] IN /\ effect.kind="Strength" /\ effect.originKind \in {"Paid","Conditional","Play","BarrierInstruction"} /\ effect.value>0 /\ LingeringShorterThanTurn910(effect,world) /\ r.kind="Specimen0100Duration" /\ r.sourceSHA=world.cardFacts["Specimen0100"].sourceSHA /\ r.definition.source=r.syntax.source /\ r.syntax.kind="Static" /\ r.definition.source.kind="Object" /\ r.definition.source.object \in DOMAIN world.objects /\ world.objects[r.definition.source.object].card="Specimen0100" /\ world.objects[r.definition.source.object].host=effect.target /\ StaticAbilityActive94(r.definition,r.syntax,world.objects,world.present, LingeringObjectActive910(r.definition.source,world),world.activity,world.points) /\ effect.creationTurn=world.turn.id /\ ~world.turn.formalEnded } OrdinaryLingeringAlive910(effect,world) == LingeringBaseAlive910(effect,world) \/ GebrMaintenance910(effect,world)#{} ChoicePolicy910(blueprint) == IF blueprint.lingeringConsumers#{} /\ blueprint.otherConsumers={} THEN "Follow" ELSE IF blueprint.originKind="Conditional" /\ blueprint.whenYourTurnBegins /\ blueprint.onlyChoice THEN "TurnOrSource" ELSE "SchemaAtom149" LingeringWantsActive910(effect,effects,world) == IF effect.kind # "Choice" THEN OrdinaryLingeringAlive910(effect,world) ELSE CASE effect.choicePolicy="Follow" -> /\ Cardinality(effect.lingeringConsumers)=1 /\ \A id \in effect.lingeringConsumers : /\ id \in DOMAIN effects /\ effects[id].kind#"Choice" /\ effects[id].source=effect.source /\ effects[id].status="Active" /\ OrdinaryLingeringAlive910(effects[id],world) [] effect.choicePolicy="TurnOrSource" -> LingeringObjectActive910(effect.source,world) /\ effect.creationTurn=world.turn.id /\ ~world.turn.formalEnded [] effect.choicePolicy="SchemaAtom149" -> LingeringObjectActive910(effect.source,world) [] OTHER -> FALSE ObserveLingeringEffects910(before,world) == [id \in DOMAIN before |-> IF before[id].status="Expired" \/ ~LingeringWantsActive910(before[id],before,world) THEN [before[id] EXCEPT !.status="Expired"] ELSE before[id]] ObserveLingering910(before,after,world) == /\ world.id \in Nat \ {0} /\ after=[before EXCEPT !.effects=ObserveLingeringEffects910(@,world)] ActiveLingeringIds910(registry,world) == {id \in DOMAIN registry.effects : registry.effects[id].status="Active" /\ LingeringWantsActive910(registry.effects[id],registry.effects,world)} LingeringStrength910(registry,world,target) == IF target \notin DOMAIN world.objects THEN 0 ELSE SumMap([id \in {id \in ActiveLingeringIds910(registry,world) : registry.effects[id].kind="Strength" /\ registry.effects[id].target=target} |-> registry.effects[id].value]) LingeringBarrierSubtypes910(registry,world,target,base) == IF target \notin DOMAIN world.objects THEN base ELSE base \cup {registry.effects[id].value : id \in {id \in ActiveLingeringIds910(registry,world) : registry.effects[id].kind="Subtype" /\ registry.effects[id].target=target}} LingeringReplacementIds910(registry,world) == {id \in ActiveLingeringIds910(registry,world) : registry.effects[id].kind="Replacement"} ProjectLingeringReplacements910(registry,world,beforeExpected,afterExpected) == LET ids == {id \in DOMAIN registry.effects : registry.effects[id].kind="Replacement"} IN /\ world.id=beforeExpected.id /\ world.objects=beforeExpected.objects /\ ids={id \in DOMAIN beforeExpected.replacementDefinitions : beforeExpected.replacementDefinitions[id].provider="Maintained"} /\ \A id \in ids : /\ beforeExpected.replacementDefinitions[id].blueprint.source=registry.effects[id].source /\ beforeExpected.replacementDefinitions[id].creation.instruction=registry.effects[id].creation[2] /\ beforeExpected.replacementDefinitions[id].creation.replacement=id /\ afterExpected=[beforeExpected EXCEPT !.liveReplacementIds=LingeringReplacementIds910(registry,world)] RememberedChoices910(registry,world,source,key) == {registry.effects[id].value : id \in {id \in ActiveLingeringIds910(registry,world) : registry.effects[id].kind="Choice" /\ registry.effects[id].source=source /\ registry.effects[id].choiceKey=key}} ImplicitBarrierResponseCardStrengthDuration910(source,target,world) == /\ source.kind="Object" /\ source.object=target /\ target \in DOMAIN world.objects /\ world.objects[target].kind="Technique" /\ target \in world.barrierResponseCards ImplicitStrengthBinding910(source,target,world,requested,duration) == /\ ImplicitBarrierResponseCardStrengthDuration910(source,target,world) /\ requested=IF world.currentEncounter \in DOMAIN world.encounters THEN TimingRef9("TraversalPhase",world.currentEncounter) ELSE NoTimingRef9 /\ duration=BindTimingDuration910(requested,world) LingeringCreationKey910(context,operation) == <> LingeringExecution910(context,origin,operation,actualExecution,world) == /\ context.phase="Resolving" /\ origin.kind="Instruction" /\ origin.plan.phase="Resolving" /\ context.currentRef=InstructionWindowRef93(origin.plan) /\ context.currentWorld=world.id /\ operation \in DOMAIN context.actualEffects /\ context.actualEffects[operation].kind="CreateLingering" /\ actualExecution.tag="LingeringEffectExecution" /\ actualExecution.contextId=context.id /\ actualExecution.instruction=context.currentRef /\ actualExecution.operation=operation /\ actualExecution.snapshotId=world.id /\ actualExecution.source=origin.plan.source /\ actualExecution.blueprints=context.actualEffects[operation].blueprints /\ actualExecution.carriedOut /\ ConditionalCreationInstruction96(origin.plan,origin.parent,origin.ruleStep) NewLingeringEffect910(id,blueprint,context,operation,world) == [id |-> id,kind |-> blueprint.kind,source |-> context.currentRef.source, creation |-> LingeringCreationKey910(context,operation),creationTurn |-> world.turn.id, originKind |-> blueprint.originKind,target |-> blueprint.target,value |-> blueprint.value, baseDuration |-> blueprint.baseDuration,durationClass |-> blueprint.durationClass, choicePolicy |-> IF blueprint.kind="Choice" THEN ChoicePolicy910(blueprint) ELSE "NoValue", choiceKey |-> blueprint.choiceKey,lingeringConsumers |-> blueprint.lingeringConsumers, otherConsumers |-> blueprint.otherConsumers,definitionId |-> blueprint.definitionId,status |-> "Active"] CreateLingeringEffectsCore910(before,after,context,origin,operation,actualExecution,world) == /\ LingeringExecution910(context,origin,operation,actualExecution,world) /\ LingeringCreationKey910(context,operation) \notin before.creations /\ LET blueprints == actualExecution.blueprints ids == DOMAIN blueprints created == [id \in DOMAIN before.effects \cup ids |-> IF id \in ids THEN NewLingeringEffect910(id,blueprints[id],context,operation,world) ELSE before.effects[id]] IN /\ ids \subseteq (Nat \ {0}) \ before.usedEffects /\ \A id \in ids : /\ blueprints[id].kind \in {"Choice","Strength","Subtype","Delayed","Replacement","Ordinary"} /\ blueprints[id].source=context.currentRef.source /\ blueprints[id].originKind=IF origin.plan.origin="Rule" THEN "Rule" ELSE origin.parent.kind /\ blueprints[id].durationMode \in {"Specified","ImplicitSelfStrength"} /\ blueprints[id].durationMode="ImplicitSelfStrength" => /\ blueprints[id].kind="Strength" /\ ImplicitStrengthBinding910(blueprints[id].source,blueprints[id].target,world, IF world.currentEncounter \in DOMAIN world.encounters THEN TimingRef9("TraversalPhase",world.currentEncounter) ELSE NoTimingRef9, blueprints[id].baseDuration) /\ blueprints[id].baseDuration.kind \in {"Timing","UntilResolution","DelayedResolution","Stated"} /\ blueprints[id].baseDuration.kind="Timing" => blueprints[id].baseDuration.ref=NoTimingRef9 \/ blueprints[id].baseDuration.ref \in LingeringTimingRefs910(world) /\ blueprints[id].kind="Choice" => /\ (ChoicePolicy910(blueprints[id])#"Follow" \/ Cardinality(blueprints[id].lingeringConsumers)=1) /\ blueprints[id].lingeringConsumers \subseteq DOMAIN created /\ \A consumer \in blueprints[id].lingeringConsumers : created[consumer].kind#"Choice" /\ created[consumer].source=context.currentRef.source /\ after=[before EXCEPT !.effects=ObserveLingeringEffects910(created,world),!.usedEffects=@ \cup ids, !.creations=@ \cup {LingeringCreationKey910(context,operation)}] CreateLingeringEffects910(before,after,context,origin,operation,actualExecution,world) == /\ \A id \in DOMAIN actualExecution.blueprints : actualExecution.blueprints[id].kind#"Delayed" /\ CreateLingeringEffectsCore910(before,after,context,origin,operation,actualExecution,world) LingeringCheckpointFrame910(ledger,cp,world) == [tag |-> "LingeringCheckpointCursor",checkpointId |-> cp.id,caller |-> ledger.checkpoints[cp.id].caller, recognition |-> cp,snapshotId |-> world.id,point |-> "ProcedureCode88eda145024f",returned |-> FALSE] OpenLingeringCheckpoint910(ledger,cp,world,frame) == /\ cp.id \in DOMAIN ledger.checkpoints /\ cp.tag="ConditionalCheckpoint" /\ cp.point="ProcedureCodee605a78f5d5e" /\ ledger.lastCheckpoint=cp.id /\ ledger.checkpoints[cp.id].caller=cp.caller /\ ledger.serial=cp.serial /\ ledger.lastSnapshot=cp.processingSnapshot /\ world.id=cp.processingSnapshot.id /\ world.objects=cp.processingSnapshot.objects /\ frame=LingeringCheckpointFrame910(ledger,cp,world) CleanupLingering910(before,after,ledger,world,frame,afterFrame,actualCleanup) == /\ OpenLingeringCheckpoint910(ledger,frame.recognition,world,frame) /\ frame.checkpointId \notin before.cleanupIds /\ ~frame.returned /\ before.effects=ObserveLingeringEffects910(before.effects,world) /\ actualCleanup.tag="LingeringCheckpointCleanup" /\ actualCleanup.frame=frame /\ actualCleanup.expired={id \in DOMAIN before.effects : before.effects[id].status="Expired"} /\ actualCleanup.complete /\ after=[before EXCEPT !.effects=[id \in DOMAIN @ \ actualCleanup.expired |-> @[id]],!.cleanupIds=@ \cup {frame.checkpointId}] /\ afterFrame=[frame EXCEPT !.returned=TRUE,!.point="ProcedureCodeb681cc249a04"] DelayedLifetimeBound910(registry,ledger) == /\ {id \in DOMAIN registry.effects : registry.effects[id].kind="Delayed"}=DOMAIN ledger.effects /\ \A id \in DOMAIN ledger.effects : registry.effects[id].source=ledger.effects[id].source /\ registry.effects[id].definitionId=ledger.effects[id].definition.syntax.id LingeringConditionalSnapshot910(snapshot,registry,ledger,world) == [SnapshotWithConditionalRegistry96(snapshot,ledger) EXCEPT !.present=(@ \ DelayedConditionalAbilityIds96(ledger.effects)) \cup {ledger.effects[id].definition.syntax.id : id \in DOMAIN ledger.effects \cap ActiveLingeringIds910(registry,world)}] LingeringConditionalWorld910(snapshot,ledger,world) == /\ snapshot.objects=world.objects /\ snapshot.points=world.points /\ snapshot.activity=[world.activity EXCEPT !.instances=ConditionalActivityRows96(ledger.instances)] /\ snapshot.present \ DelayedConditionalAbilityIds96(ledger.effects)=world.present \ DelayedConditionalAbilityIds96(ledger.effects) PublishLingeringActivity910(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack, beforeSnapshot,afterSnapshot,beforeWorld,afterWorld) == /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ beforeWorld.finishedDelayedEffects=afterWorld.finishedDelayedEffects /\ beforeSnapshot.id=beforeWorld.id /\ afterSnapshot.id=afterWorld.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeWorld) /\ LingeringConditionalWorld910(afterSnapshot,beforeLedger,afterWorld) /\ ObserveLingering910(beforeRegistry,afterRegistry,afterWorld) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeWorld) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,afterRegistry,beforeLedger,afterWorld) /\ ObserveConditionalActivity96(beforeLedger,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) CleanupLingeringConditionals910(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, beforeSnapshot,afterSnapshot,world,frame,afterFrame,actualCleanup) == /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,world) /\ CleanupLingering910(beforeRegistry,afterRegistry,beforeLedger,world,frame,afterFrame,actualCleanup) /\ candidateLedger=[beforeLedger EXCEPT !.effects=[id \in DOMAIN @ \ actualCleanup.expired |-> @[id]]] /\ LingeringConditionalWorld910(afterSnapshot,candidateLedger,world) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,afterRegistry,candidateLedger,world) /\ ObserveConditionalActivity96(beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) DelayedCreationOmitted910(template,traversal) == template.thisTraversal /\ "TraversalEnds" \in ConditionalEventKinds96(template) /\ ~TraversalTimingPresent6(traversal) DelayedLifetimeDuration910(effect,world) == IF effect.policy="UntilResolution" THEN [kind |-> "DelayedResolution",effectId |-> effect.id] ELSE IF effect.duration.kind="Stated" THEN [kind |-> "Stated",specification |-> effect.duration] ELSE [kind |-> "Timing",ref |-> BindTimingDuration910(effect.duration,world).ref,requested |-> effect.duration] DelayedLifetimeBlueprint910(effect,origin,world) == [kind |-> "Delayed",source |-> effect.source,originKind |-> IF origin.plan.origin="Ability" THEN origin.parent.kind ELSE "Rule", target |-> 0,value |-> 0,baseDuration |-> DelayedLifetimeDuration910(effect,world),durationMode |-> "Specified", durationClass |-> "Delayed",choiceKey |-> "NoValue",lingeringConsumers |-> {},otherConsumers |-> {}, definitionId |-> effect.definition.syntax.id,whenYourTurnBegins |-> FALSE,onlyChoice |-> FALSE] CreateDelayedLingering910(beforeRegistry,afterRegistry,beforeLedger,createdLedger,effectId,definitionId,template, context,origin,operation,actualExecution,actualCreation,world,usedDefinitions) == /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ world.finishedDelayedEffects \subseteq beforeRegistry.usedEffects /\ origin.kind="Instruction" /\ CreateDelayedConditional96(beforeLedger,createdLedger,effectId,definitionId,template,origin.plan,origin.parent, origin.ruleStep,actualCreation,world.control.traversal,usedDefinitions) /\ actualExecution.blueprints= IF DelayedCreationOmitted910(template,world.control.traversal) THEN [id \in {} |-> id] ELSE [id \in {effectId} |-> DelayedLifetimeBlueprint910(createdLedger.effects[id],origin,world)] /\ CreateLingeringEffectsCore910(beforeRegistry,afterRegistry,context,origin,operation,actualExecution,world) /\ DelayedLifetimeBound910(afterRegistry,createdLedger) PublishCreatedDelayedLingering910(beforeRegistry,afterRegistry,beforeLedger,createdLedger,afterLedger,beforeStack,afterStack, beforeSnapshot,afterSnapshot,effectId,definitionId,template,context,origin,operation, actualExecution,actualCreation,world,usedDefinitions) == /\ CreateDelayedLingering910(beforeRegistry,afterRegistry,beforeLedger,createdLedger,effectId,definitionId,template, context,origin,operation,actualExecution,actualCreation,world,usedDefinitions) /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,world) /\ LingeringConditionalWorld910(afterSnapshot,createdLedger,world) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,world) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,afterRegistry,createdLedger,world) /\ ObserveConditionalActivity96(beforeLedger,createdLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) DelayedCarryStack910(stack,beforeLedger,coreLedger) == [i \in 1..Len(stack) |-> LET lost == {id \in stack[i].pending \cap DOMAIN beforeLedger.instances : coreLedger.instances[id].status # "Pending"} IN [stack[i] EXCEPT !.pending=@ \ lost,!.lostPending=@ \cup lost]] CarryDelayedLingeringInstruction910(beforeRegistry,afterRegistry,beforeLedger,coreLedger,retainedLedger,afterLedger, beforeStack,afterStack,beforeP,afterP,plan,afterPlan,actualStep, beforeSnapshot,afterSnapshot,beforeWorld,afterWorld) == /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ beforeWorld.finishedDelayedEffects \subseteq beforeRegistry.usedEffects /\ beforeP.definition.delayedEffect \in Nat \ {0} /\ CarryConditionalInstructionCore96(beforeLedger,coreLedger,beforeStack,DelayedCarryStack910(beforeStack,beforeLedger,coreLedger), beforeP,afterP,plan,afterPlan,actualStep) /\ retainedLedger=[coreLedger EXCEPT !.effects=beforeLedger.effects] /\ afterWorld.id \in Nat \ {0} /\ afterWorld=[beforeWorld EXCEPT !.id=afterWorld.id, !.finishedDelayedEffects=@ \cup (DOMAIN beforeLedger.effects \ DOMAIN coreLedger.effects)] /\ beforeSnapshot.id=beforeWorld.id /\ afterSnapshot.id=afterWorld.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeWorld) /\ LingeringConditionalWorld910(afterSnapshot,retainedLedger,afterWorld) /\ ObserveLingering910(beforeRegistry,afterRegistry,afterWorld) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeWorld) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,afterRegistry,retainedLedger,afterWorld) /\ ObserveConditionalActivity96(beforeLedger,retainedLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) /\ DelayedLifetimeBound910(afterRegistry,afterLedger) FinishExpectedDelayedInstruction910(beforeRegistry,afterRegistry,beforeContext,afterContext,beforeOrigin,afterOrigin,world,call, retainedLedger,afterLedger,beforeSnapshot,afterSnapshot,beforeWorld,afterWorld,actualReturn) == /\ call.kind="Conditional" /\ ExpectedWorldValid99(world) /\ world.id=beforeWorld.id /\ world.objects=beforeWorld.objects /\ world.conditional=call.beforeSnapshot /\ beforeSnapshot=call.beforeSnapshot /\ beforeContext.currentWorld=world.id /\ ContextInitialObservationBound99(call.beforeLedger,call.before,beforeContext) /\ FinishExpectedAbilityInstruction99(beforeContext,afterContext,beforeOrigin,afterOrigin,world,call,actualReturn) /\ CarryDelayedLingeringInstruction910(beforeRegistry,afterRegistry,call.beforeLedger,call.candidateLedger,retainedLedger,afterLedger, call.beforeStack,call.afterStack,call.before,call.after,call.beforePlan,call.afterPlan,call.step, beforeSnapshot,afterSnapshot,beforeWorld,afterWorld) LifetimeWorldProjection910(w) == [id |-> w.id,objects |-> w.objects,gameStarted |-> w.gameStarted,cardFacts |-> w.cardFacts,playActivated |-> w.playActivated, turn |-> w.turn,turnPhase |-> w.turnPhase,control |-> w.control,encounters |-> w.encounters,currentEncounter |-> w.currentEncounter, siteInspections |-> w.siteInspections,itemInspections |-> w.itemInspections,finishedInstances |-> w.finishedInstances,finishedDelayedEffects |-> w.finishedDelayedEffects, statedDurations |-> w.statedDurations,durationComparisons |-> w.durationComparisons,extenders |-> w.extenders, present |-> w.present,activity |-> w.activity,points |-> w.points,barrierResponseCards |-> w.barrierResponseCards] NewLifetimeAuthority910(w) == [current |-> LifetimeWorldProjection910(w),order |-> <>,worlds |-> [id \in {w.id} |-> LifetimeWorldProjection910(w)], transitions |-> [id \in {} |-> id]] LifetimeFaceTransition910(before,after,object,face,actualEffectAuthorizes,events) == [kind |-> "Face8",before |-> LifetimeWorldProjection910(before),after |-> LifetimeWorldProjection910(after), object |-> object,face |-> face,actualEffectAuthorizes |-> actualEffectAuthorizes,events |-> events] LifetimeKernelTransition910(before,after,execution) == [kind |-> "Kernel",before |-> LifetimeWorldProjection910(before),after |-> LifetimeWorldProjection910(after), receipt |-> [tag |-> "AtomicLifetimeWorldCommit",previous |-> before.id,id |-> after.id, before |-> LifetimeWorldProjection910(before),after |-> LifetimeWorldProjection910(after),execution |-> execution]] LifetimeTransitionValid910(t) == /\ t.before.id \in Nat \ {0} /\ t.after.id \in Nat \ {0} /\ t.before.id#t.after.id /\ t.before.cardFacts=t.after.cardFacts /\ (t.before.gameStarted => t.after.gameStarted) /\ CASE t.kind="Face8" -> /\ TurnSideBFace8(t.before.objects,t.after.objects,t.object,t.face,t.actualEffectAuthorizes,t.events) /\ t.after=[t.before EXCEPT !.id=t.after.id,!.objects=t.after.objects] [] t.kind="Kernel" -> /\ t.receipt.tag="AtomicLifetimeWorldCommit" /\ t.receipt.previous=t.before.id /\ t.receipt.id=t.after.id /\ t.receipt.before=t.before /\ t.receipt.after=t.after /\ t.receipt.execution.tag \in {"CurrentCharacteristicsEvaluation","ActualTimingTransition","ActualObjectTransition","ActualDelayedReturn"} /\ t.receipt.execution.id \in Nat \ {0} /\ t.receipt.execution.snapshotId=t.after.id /\ t.receipt.execution.source.kind \in {"Object","Rule"} /\ CASE t.receipt.execution.tag="CurrentCharacteristicsEvaluation" -> /\ t.after.objects=t.before.objects /\ t.after.turn=t.before.turn /\ t.after.turnPhase=t.before.turnPhase /\ t.after.control=t.before.control /\ t.after.encounters=t.before.encounters /\ t.after.siteInspections=t.before.siteInspections /\ t.after.itemInspections=t.before.itemInspections /\ t.after.finishedInstances=t.before.finishedInstances /\ t.after.finishedDelayedEffects=t.before.finishedDelayedEffects [] t.receipt.execution.tag="ActualTimingTransition" -> /\ t.after.objects=t.before.objects /\ t.after.finishedDelayedEffects=t.before.finishedDelayedEffects [] t.receipt.execution.tag="ActualObjectTransition" -> /\ t.after.turn=t.before.turn /\ t.after.turnPhase=t.before.turnPhase /\ t.after.control=t.before.control /\ t.after.encounters=t.before.encounters /\ t.after.siteInspections=t.before.siteInspections /\ t.after.itemInspections=t.before.itemInspections /\ t.after.finishedDelayedEffects=t.before.finishedDelayedEffects [] t.receipt.execution.tag="ActualDelayedReturn" -> /\ t.after=[t.before EXCEPT !.id=t.after.id,!.finishedDelayedEffects=t.after.finishedDelayedEffects] /\ t.before.finishedDelayedEffects \subseteq t.after.finishedDelayedEffects /\ t.receipt.execution.instruction.source=t.receipt.execution.source /\ t.receipt.execution.return.tag="ExpectedEffectsProcedureReturn" /\ t.receipt.execution.return.contextId=t.receipt.execution.id /\ t.receipt.execution.return.instruction=t.receipt.execution.instruction /\ t.receipt.execution.return.snapshotId=t.before.id /\ t.receipt.execution.return.complete /\ t.receipt.execution.return.childrenReturned [] OTHER -> FALSE [] OTHER -> FALSE LifetimeAuthorityValid910(a) == /\ DeckSequenceValid4(a.order) /\ Len(a.order)>0 /\ DOMAIN a.worlds=SubIds6(a.order) /\ a.current=a.worlds[a.order[Len(a.order)]] /\ DOMAIN a.transitions=SubIds6(Tail(a.order)) /\ \A i \in 1..Len(a.order) : a.worlds[a.order[i]].id=a.order[i] /\ \A i \in 2..Len(a.order) : /\ a.transitions[a.order[i]].before=a.worlds[a.order[i-1]] /\ a.transitions[a.order[i]].after=a.worlds[a.order[i]] /\ LifetimeTransitionValid910(a.transitions[a.order[i]]) LifetimeAuthorityAfter910(before,transition) == [current |-> transition.after,order |-> Append(before.order,transition.after.id), worlds |-> ReplacementOverlay99(before.worlds,[id \in {transition.after.id} |-> transition.after]), transitions |-> ReplacementOverlay99(before.transitions,[id \in {transition.after.id} |-> transition])] AppendLifetimeTransitionCore910(before,after,transition) == /\ LifetimeAuthorityValid910(before) /\ LifetimeTransitionValid910(transition) /\ transition.before=before.current /\ transition.after.id \notin DOMAIN before.worlds /\ after=LifetimeAuthorityAfter910(before,transition) CommitLifetimeFace910(before,after,afterWorld,object,face,actualEffectAuthorizes,events) == AppendLifetimeTransitionCore910(before,after, LifetimeFaceTransition910(before.current,afterWorld,object,face,actualEffectAuthorizes,events)) CommitLifetimeKernelCore910(before,after,afterWorld,actualExecution) == AppendLifetimeTransitionCore910(before,after,LifetimeKernelTransition910(before.current,afterWorld,actualExecution)) LifetimeFrontier910(a,position) == LET order == SubSeq(a.order,1,position) IN [position |-> position,order |-> order,world |-> a.worlds[order[position]], worlds |-> [id \in SubIds6(order) |-> a.worlds[id]], transitions |-> [id \in SubIds6(Tail(order)) |-> a.transitions[id]]] OpenObservedLingering910(a,registry) == /\ LifetimeAuthorityValid910(a) /\ Len(a.order)=1 /\ registry=ReplacementOverlay99(NewLingeringRegistry910,[frontier |-> LifetimeFrontier910(a,Len(a.order))]) LifetimeFrontierBound910(registry,a) == /\ LifetimeAuthorityValid910(a) /\ "frontier" \in DOMAIN registry /\ registry.frontier.position \in 1..Len(a.order) /\ registry.frontier=LifetimeFrontier910(a,registry.frontier.position) LifetimeReady910(registry,a) == LifetimeFrontierBound910(registry,a) /\ registry.frontier.position=Len(a.order) NextLifetimeWorld910(registry,a) == a.worlds[a.order[registry.frontier.position+1]] PublishNextLifetime910(before,after,a) == /\ LifetimeFrontierBound910(before,a) /\ before.frontier.position "CurrentRememberedChoices",worldId |-> a.current.id,source |-> source,key |-> key, values |-> RememberedChoices910(registry,a.current,source,key)] ReadLingeringStrength910(registry,a,target,receipt) == /\ LifetimeReady910(registry,a) /\ receipt=[tag |-> "CurrentLingeringStrength",worldId |-> a.current.id,target |-> target, value |-> LingeringStrength910(registry,a.current,target)] ReadActiveLingering910(registry,a,receipt) == /\ LifetimeReady910(registry,a) /\ receipt=[tag |-> "CurrentActiveLingeringEffects",worldId |-> a.current.id,ids |-> ActiveLingeringIds910(registry,a.current)] CreateObservedLingeringEffects910(before,after,context,origin,operation,execution,a) == /\ LifetimeReady910(before,a) /\ CreateLingeringEffects910(before,after,context,origin,operation,execution,a.current) CleanupObservedLingering910(before,after,ledger,a,frame,afterFrame,actualCleanup) == /\ LifetimeReady910(before,a) /\ CleanupLingering910(before,after,ledger,a.current,frame,afterFrame,actualCleanup) PublishNextLingeringActivity910(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot,a) == /\ LifetimeFrontierBound910(beforeRegistry,a) /\ beforeRegistry.frontier.position "ActualDelayedReturn",id |-> beforeContext.id,snapshotId |-> next.id, source |-> beforeOrigin.plan.source,instruction |-> beforeContext.currentRef,return |-> actualReturn] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ AppendLifetimeTransitionCore910(beforeAuthority,afterAuthority, LifetimeKernelTransition910(beforeAuthority.current,next,execution)) /\ FinishExpectedDelayedInstruction910(beforeRegistry,local,beforeContext,afterContext,beforeOrigin,afterOrigin,world,call, retainedLedger,afterLedger,beforeSnapshot,afterSnapshot,beforeAuthority.current,next,actualReturn) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) ReadLingeringSubtypes910(registry,a,target,base,receipt) == /\ LifetimeReady910(registry,a) /\ receipt=[tag |-> "CurrentLingeringSubtypes",worldId |-> a.current.id,target |-> target, values |-> LingeringBarrierSubtypes910(registry,a.current,target,base)] ProjectObservedLingeringReplacements910(registry,a,beforeExpected,afterExpected) == /\ LifetimeReady910(registry,a) /\ ProjectLingeringReplacements910(registry,a.current,beforeExpected,afterExpected) PublishCreatedObservedDelayedLingering910(beforeRegistry,afterRegistry,beforeLedger,createdLedger,afterLedger,beforeStack,afterStack, beforeSnapshot,afterSnapshot,effectId,definitionId,template,context,origin,operation, execution,creation,a,usedDefinitions) == /\ LifetimeReady910(beforeRegistry,a) /\ PublishCreatedDelayedLingering910(beforeRegistry,afterRegistry,beforeLedger,createdLedger,afterLedger,beforeStack,afterStack, beforeSnapshot,afterSnapshot,effectId,definitionId,template,context,origin,operation,execution,creation,a.current,usedDefinitions) ObserveResolvingLifetimeContext910(before,after,registry,a,origin) == /\ LifetimeReady910(registry,a) /\ before.phase="Resolving" /\ before.currentWorld \in DOMAIN a.worlds /\ origin.kind="Instruction" /\ ConditionalCreationInstruction96(origin.plan,origin.parent,origin.ruleStep) /\ before.currentRef=InstructionWindowRef93(origin.plan) /\ after=[before EXCEPT !.currentWorld=a.current.id] InstructionNode911(id,kind,steps,requiresTargets,next,options,rank,segments) == [id |-> id,kind |-> kind,steps |-> steps,requiresTargets |-> requiresTargets, next |-> next,options |-> options,rank |-> rank,segments |-> segments] TechniqueEdges911(node) == (IF node.next=0 THEN {} ELSE {node.next}) \cup {node.options[option] : option \in {option \in DOMAIN node.options : node.options[option]#0}} RECURSIVE ReachableTechniqueNodes911(_,_,_) ReachableTechniqueNodes911(p,seen,remaining) == IF remaining=0 THEN seen ELSE ReachableTechniqueNodes911(p,seen \cup UNION {TechniqueEdges911(p.nodes[id]) : id \in seen},remaining-1) InstructionTechniqueValid911(p) == /\ p.tag="NormalizedInstructionTechnique" /\ p.source=p.definition.syntax.source /\ p.ability=p.definition.syntax.id /\ IF DOMAIN p.nodes={} THEN p.entry=0 ELSE p.entry \in DOMAIN p.nodes /\ SubIds6(p.definition.instructions)=DOMAIN p.nodes /\ DOMAIN p.nodes \subseteq Nat \ {0} /\ \A id \in DOMAIN p.nodes : LET n == p.nodes[id] IN /\ n.id=id /\ n.kind \in {"Plain","Choice","NestedCost","Search","Look","TimingStart","PerCard"} /\ Len(n.steps)>0 /\ n.requiresTargets \in BOOLEAN /\ n.rank \in Nat /\ TechniqueEdges911(n) \subseteq DOMAIN p.nodes /\ \A next \in TechniqueEdges911(n) : p.nodes[next].rank DOMAIN n.options={"Pay","Decline"} /\ ReachableTechniqueNodes911(p,IF DOMAIN p.nodes={} THEN {} ELSE {p.entry},Cardinality(DOMAIN p.nodes))=DOMAIN p.nodes /\ p.nonoperative={unit \in DOMAIN p.units : p.units[unit].category \in {"Restriction","SchemaAtom043","Clarification","Declaration"}} /\ p.linked={unit \in DOMAIN p.units : p.units[unit].category="LinkedAbility"} /\ \A id \in DOMAIN p.nodes : p.nodes[id].segments \cap (p.nonoperative \cup p.linked)={} InstructionTechniqueSource911(p,objects,cardFacts) == /\ InstructionTechniqueValid911(p) /\ AbilityLexemesValid99(p.definition,p.lexemes,objects,cardFacts) /\ p.sourceSHA=p.lexemes.sourceSHA /\ p.card=p.lexemes.card /\ p.originalUnits=p.definition.syntax.units NewInstructionRuntime911(id,p,kind,sourceZone,caller) == [id |-> id,technique |-> p,pc |-> p.entry,visited |-> <<>>,choices |-> [i \in {} |-> i], ability |-> OpenAbilityResolution9(id,kind,p.source,sourceZone,<>,caller), phase |-> "Targets",checkpoint |-> 0,pause |-> [id |-> 0],pauseKeys |-> {},boundary |-> [i \in {} |-> i]] RuntimeLookOwner911(r) == ReplacementOverlay99(r,[definition |-> r.technique.definition]) RuntimeOwnerCurrent911(r,authority) == /\ r.id \in DOMAIN authority.current.activity.instances /\ "owner" \in DOMAIN authority.current.activity.instances[r.id] /\ authority.current.activity.instances[r.id].owner.ability=r.ability /\ authority.current.activity.instances[r.id].owner.technique=r.technique /\ authority.current.activity.instances[r.id].owner.pc=r.pc /\ authority.current.activity.instances[r.id].owner.visited=r.visited /\ authority.current.activity.instances[r.id].owner.choices=r.choices /\ IF "sourceEntry" \in DOMAIN r THEN /\ authority.current.activity.instances[r.id].owner.sourceEntry=r.sourceEntry /\ authority.current.activity.instances[r.id].owner.sourceOwner=r.sourceOwner ELSE IF "windowId" \in DOMAIN r THEN /\ authority.current.activity.instances[r.id].owner.windowId=r.windowId /\ authority.current.activity.instances[r.id].owner.option=r.option /\ authority.current.activity.instances[r.id].owner.transaction=r.transaction /\ authority.current.activity.instances[r.id].owner.turnId=r.turnId ELSE TRUE RuntimeProfile911(r) == /\ InstructionTechniqueValid911(r.technique) /\ r.id=r.ability.id /\ r.ability.source=r.technique.source /\ r.ability.kind=r.technique.definition.syntax.kind /\ DeckSequenceValid4(r.visited) /\ SubIds6(r.visited) \subseteq DOMAIN r.technique.nodes /\ IF r.visited# <<>> THEN Head(r.visited)=r.technique.entry ELSE r.pc=r.technique.entry /\ r.pc=0 \/ r.pc \in DOMAIN r.technique.nodes /\ IF r.pc=0 THEN r.ability.instructions=r.visited ELSE r.pc \notin SubIds6(r.visited) /\ r.ability.instructions=Append(r.visited,r.pc) /\ r.phase \in {"Targets","Imminent","Resolve","Paused","Checkpoint","Complete","Returned"} /\ IF r.pc=0 THEN r.ability.lastFinished /\ r.ability.complete ELSE r.technique.nodes[r.pc].id=r.pc RuntimeCurrentPlan911(r,plan) == /\ r.pc \in DOMAIN r.technique.nodes /\ plan.id=r.pc /\ plan.source=r.ability.source /\ plan.abilityInstance=r.id /\ plan.index=Len(r.visited)+1 /\ plan.steps=r.technique.nodes[r.pc].steps /\ plan.requiresTargets=r.technique.nodes[r.pc].requiresTargets ControlResultBound911(r,context,actualReturn,result) == /\ r.phase="Resolve" /\ r.pc \in DOMAIN r.technique.nodes /\ context.phase="Resolving" /\ context.currentRef.abilityInstance=r.id /\ context.currentRef.id=r.pc /\ result.tag="ResolvedInstructionControl" /\ result.instance=r.id /\ result.node=r.pc /\ result.instruction=context.currentRef /\ result.contextId=context.id /\ result.actualEffects=context.actualEffects /\ result.completion=actualReturn /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=context.id /\ actualReturn.instruction=context.currentRef /\ actualReturn.effects=context.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ result.mode \in {"Selected","Removed"} /\ IF result.mode="Selected" THEN /\ result.operation \in DOMAIN context.actualEffects /\ context.actualEffects[result.operation].kind \in {"InstructionChoice","NestedCostChoice"} /\ context.actualEffects[result.operation].controlNode=r.pc /\ result.option \in DOMAIN r.technique.nodes[r.pc].options /\ result.option \in context.actualEffects[result.operation].options /\ result.chooser=context.actualEffects[result.operation].chooser /\ result.chooser \in SetupPlayers ELSE ~\E op \in DOMAIN context.actualEffects : context.actualEffects[op].kind \in {"InstructionChoice","NestedCostChoice"} /\ context.actualEffects[op].controlNode=r.pc RuntimeNext911(r,result) == IF r.technique.nodes[r.pc].kind \notin {"Choice","NestedCost"} THEN r.technique.nodes[r.pc].next ELSE IF result.mode="Removed" THEN r.technique.nodes[r.pc].next ELSE r.technique.nodes[r.pc].options[result.option] RuntimeFinishFrame911(r,next) == [r.ability EXCEPT !.instructions=IF next=0 THEN Append(r.visited,r.pc) ELSE Append(Append(r.visited,r.pc),next)] NoInstructionControl911 == [mode |-> "NoValue"] GraphInstructionBoundary911(r,context,causes,costTransaction) == [tag |-> "InstructionBoundary",instance |-> r.id,source |-> r.ability.source,instruction |-> context.currentRef, node |-> r.pc,index |-> Len(r.visited)+1,causes |-> causes,costTransaction |-> costTransaction] GraphBoundaryCaller911(boundary) == [kind |-> "GraphInstructionBoundary",boundary |-> boundary] FinishRuntimeInstruction911(before,after,plan,afterPlan,context,actualReturn,step,control,payment,boundary) == /\ RuntimeProfile911(before) /\ before.phase="Resolve" /\ before.pause.id=0 /\ RuntimeCurrentPlan911(before,plan) /\ plan.phase="Resolving" /\ plan.cursor=Len(plan.steps) /\ context.phase="Resolving" /\ context.currentRef=InstructionWindowRef93(plan) /\ context.currentRef.abilityInstance=before.id /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=context.id /\ actualReturn.instruction=context.currentRef /\ actualReturn.effects=context.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ step.expectedReturn=actualReturn /\ IF before.technique.nodes[before.pc].kind \in {"Choice","NestedCost"} THEN ControlResultBound911(before,context,actualReturn,control) ELSE control=NoInstructionControl911 /\ Len(before.visited)+1 \notin DOMAIN before.choices /\ LET next == RuntimeNext911(before,control) projected == RuntimeFinishFrame911(before,next) finished == IF next=0 THEN [projected EXCEPT !.phase="Complete",!.lastFinished=TRUE,!.complete=TRUE] ELSE [projected EXCEPT !.phase="Between"] choices == IF before.technique.nodes[before.pc].kind \in {"Choice","NestedCost"} THEN ReplacementOverlay99(before.choices,[i \in {Len(before.visited)+1} |-> control]) ELSE before.choices paid == payment.tag="CompletedInstructionCost" IN /\ CarryAbilityInstructionStep93(projected,finished,plan,afterPlan,step) /\ afterPlan.phase="Complete" /\ ((before.technique.nodes[before.pc].kind="NestedCost" /\ control.mode="Selected" /\ control.option="Pay") => paid) /\ IF paid THEN /\ payment.instruction=context.currentRef /\ payment.instance=before.id /\ payment.source=before.ability.source /\ payment.transaction \in Nat \ {0} /\ payment.operation \in DOMAIN context.actualEffects /\ context.actualEffects[payment.operation].kind="NestedCostChoice" /\ context.actualEffects[payment.operation].controlNode=before.pc /\ control.mode="Selected" /\ control.operation=payment.operation /\ control.option="Pay" /\ payment.payer=context.actualEffects[payment.operation].payer /\ payment.payer \in SetupPlayers /\ payment.specification=context.actualEffects[payment.operation].cost /\ payment.receipt.tag="CompletedCostTransaction" /\ payment.receipt.id=payment.transaction /\ payment.receipt.instance=before.id /\ payment.receipt.instruction=context.currentRef /\ payment.receipt.source=before.ability.source /\ payment.receipt.payer=payment.payer /\ payment.receipt.specification=payment.specification /\ payment.receipt.allCostsPaid /\ payment.paid /\ payment.lastAction /\ payment.completion=actualReturn ELSE payment=[tag |-> "NoInstructionPayment"] /\ boundary=GraphInstructionBoundary911(before,context, IF paid THEN {"InstructionEnd","CostPaid"} ELSE {"InstructionEnd"},IF paid THEN payment.transaction ELSE 0) /\ after=[before EXCEPT !.ability=finished,!.visited=Append(@,before.pc),!.pc=next,!.choices=choices, !.phase="Checkpoint",!.checkpoint=0,!.boundary=boundary] CompleteRuntimeCheckpoint911(before,after,ledger,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeProfile911(before) /\ before.phase="Checkpoint" /\ receipt.tag="GraphInstructionCheckpoint" /\ receipt.instance=before.id /\ receipt.source=before.ability.source /\ receipt.boundary=before.boundary /\ receipt.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[receipt.id].caller=GraphBoundaryCaller911(before.boundary) /\ receipt.complete /\ receipt.allNewerChainsComplete /\ ConditionalCheckpointDrained96(ledger,stack,receipt.id) /\ after=[before EXCEPT !.checkpoint=receipt.id,!.phase=IF before.pc=0 THEN "Complete" ELSE "Targets"] EnterRuntimeInstructionCore911(before,after,plan,afterPlan,targets,entry,ledger,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeProfile911(before) /\ before.phase="Targets" /\ before.pause.id=0 /\ RuntimeCurrentPlan911(before,plan) /\ ~plan.announced /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] first == before.visited= <<>> imminent == IF first THEN [before.ability EXCEPT !.phase="Imminent",!.firstImminent=TRUE, !.detached=@ \/ before.ability.kind="Conditional"] ELSE [before.ability EXCEPT !.phase="Imminent",!.cursor=@+1] IN /\ AnnounceInstructionTargets93(plan,announced,targets,before.ability,"NoValue") /\ IF first THEN EnterFirstAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) ELSE /\ before.checkpoint \in Nat \ {0} /\ entry.checkpointId=before.checkpoint /\ ConditionalCheckpointDrained96(ledger,stack,before.checkpoint) /\ EnterNextAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.phase="Imminent",!.checkpoint=0] BeginRuntimeInstructionAtomic911(before,after,plan,afterPlan,context,origin,clearance,world,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeProfile911(before) /\ before.phase="Imminent" /\ RuntimeCurrentPlan911(before,plan) /\ context.phase="InstructionCleared" /\ context.currentRef=InstructionWindowRef93(plan) /\ context.clearance=clearance /\ origin.plan=plan /\ origin.parent=before.ability /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ ExpectedContextWorld99(context,world) /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] IRField911(row,key,fallback) == IF key \in DOMAIN row THEN row[key] ELSE fallback UnitShape911(unit) == IRField911(unit,"shape","Single") GroupUnitsShape911(p,g,category,shape) == Cardinality(g.units)=1 /\ LET u == CHOOSE id \in g.units : TRUE IN p.units[u].category=category /\ UnitShape911(p.units[u])=shape GroupNodeSegments911(p,g) == /\ DeckSequenceValid4(g.nodes) /\ SubIds6(g.nodes) \subseteq DOMAIN p.nodes /\ \A id \in SubIds6(g.nodes) : p.nodes[id].segments \subseteq g.units /\ UNION {p.nodes[id].segments : id \in SubIds6(g.nodes)}=IF Len(g.nodes)=0 THEN {} ELSE g.units InstructionGroupValid911(p,g) == /\ g.units \subseteq DOMAIN p.units /\ g.units#{} /\ GroupNodeSegments911(p,g) /\ CASE g.rule="ProcedureCode8b36a14c1569" -> /\ Cardinality(g.units)=1 /\ Len(g.nodes)=1 /\ LET u == CHOOSE id \in g.units : TRUE IN p.units[u].category="Trait" /\ UnitShape911(p.units[u]) \in {"Single","Effect","TimingStart"} [] g.rule="ProcedureCodee085dc6e3123" -> /\ g.nodes= <<>> /\ \A u \in g.units : p.units[u].category \in {"Restriction","SchemaAtom043","Clarification","Declaration"} [] g.rule="ProcedureCode3a5790c241a3" -> /\ GroupUnitsShape911(p,g,"Trait","MultiCard") /\ LET u == CHOOSE id \in g.units : TRUE unit == p.units[u] IN /\ unit.action \in {"Play","Deploy","ItemInspection"} /\ unit.count \in Nat \ {0} /\ Len(g.nodes)=unit.count /\ \A i \in 1..unit.count : /\ p.nodes[g.nodes[i]].kind="PerCard" /\ p.nodes[g.nodes[i]].cardAction=unit.action /\ p.nodes[g.nodes[i]].cardOrdinal=i /\ p.nodes[g.nodes[i]].optional=unit.optional /\ p.nodes[g.nodes[i]].next=IF i=unit.count THEN g.join ELSE g.nodes[i+1] [] g.rule="ProcedureCoded3a7d2154f9f" -> /\ Cardinality(g.units)=2 /\ Len(g.nodes)=1 /\ \E a,b \in g.units : /\ a#b /\ p.units[a].sentence+1=p.units[b].sentence /\ UnitShape911(p.units[a])="TargetOnly" /\ p.units[a].onlyTargets /\ ~p.units[a].otherEffects /\ UnitShape911(p.units[b])="Effect" /\ p.units[b].actsOnChoice /\ p.nodes[Head(g.nodes)].requiresTargets [] g.rule="ProcedureCode1e9a46bbcc9d" -> /\ Len(g.nodes)=2 /\ Cardinality({u \in g.units : UnitShape911(p.units[u])="SearchAndAct"})=1 /\ \A u \in g.units : UnitShape911(p.units[u]) \in {"SearchAndAct","PrintedSearchShuffle"} /\ p.nodes[g.nodes[1]].kind="Search" /\ p.nodes[g.nodes[2]].kind="Plain" /\ p.nodes[g.nodes[1]].searchShuffleRequired /\ p.nodes[g.nodes[2]].foundAction /\ p.nodes[g.nodes[1]].next=g.nodes[2] /\ p.nodes[g.nodes[2]].next=g.join /\ LET primary == CHOOSE u \in g.units : UnitShape911(p.units[u])="SearchAndAct" IN primary \in p.nodes[g.nodes[1]].segments /\ primary \in p.nodes[g.nodes[2]].segments /\ g.dischargedShuffleUnits={u \in g.units : UnitShape911(p.units[u])="PrintedSearchShuffle"} [] g.rule="ProcedureCoded0cd74215226" -> /\ GroupUnitsShape911(p,g,"Trait","LookAndAct") /\ Len(g.nodes)=2 /\ p.nodes[g.nodes[1]].kind="Look" /\ p.nodes[g.nodes[2]].requiresVisibleCohort /\ p.nodes[g.nodes[1]].next=g.nodes[2] /\ p.nodes[g.nodes[2]].next=g.join [] g.rule \in {"ProcedureCoded9954050183f","ProcedureCodef6fc0286cf28"} -> /\ Cardinality(g.units)=1 /\ Len(g.nodes)>0 /\ LET u == CHOOSE id \in g.units : TRUE unit == p.units[u] control == p.nodes[Head(g.nodes)] IN /\ unit.category="Trait" /\ UnitShape911(unit)=IF g.rule="ProcedureCoded9954050183f" THEN "NestedCost" ELSE "Options" /\ control.kind=IF g.rule="ProcedureCoded9954050183f" THEN "NestedCost" ELSE "Choice" /\ DOMAIN control.options=DOMAIN unit.optionInstructions /\ g.rule="ProcedureCoded9954050183f" => DOMAIN control.options={"Pay","Decline"} /\ control.next=g.join /\ SubIds6(g.nodes)={control.id} \cup UNION {SubIds6(unit.optionInstructions[choice]) : choice \in DOMAIN unit.optionInstructions} /\ \A choice \in DOMAIN unit.optionInstructions : LET body == unit.optionInstructions[choice] IN /\ control.options[choice]=IF Len(body)=0 THEN g.join ELSE Head(body) /\ \A i \in 1..Len(body) : p.nodes[body[i]].next=IF i=Len(body) THEN g.join ELSE body[i+1] [] g.rule="ProcedureCodefabf14494c15" -> /\ g.nodes= <<>> /\ \A u \in g.units : p.units[u].category="LinkedAbility" [] OTHER -> FALSE RECURSIVE GroupInstructionOrder911(_) GroupInstructionOrder911(groups) == IF groups= <<>> THEN <<>> ELSE Head(groups).nodes \o GroupInstructionOrder911(Tail(groups)) ExecutableInstructionGroups911(p) == SelectSeq(p.groups,LAMBDA g : Len(g.nodes)>0) InstructionGroupContinuation911(p,g) == IF g.rule \in {"ProcedureCoded9954050183f","ProcedureCodef6fc0286cf28"} THEN g.join ELSE p.nodes[g.nodes[Len(g.nodes)]].next InstructionSourceFlow911(p) == /\ p.definition.instructions=GroupInstructionOrder911(p.groups) /\ LET groups == ExecutableInstructionGroups911(p) IN /\ IF Len(groups)=0 THEN p.entry=0 ELSE p.entry=Head(groups[1].nodes) /\ \A i \in 1..Len(groups) : InstructionGroupContinuation911(p,groups[i])=IF i=Len(groups) THEN 0 ELSE Head(groups[i+1].nodes) InstructionPartitionValid911(p) == /\ "groups" \in DOMAIN p /\ Len(p.groups)>0 /\ InstructionSourceFlow911(p) /\ \A i \in 1..Len(p.groups) : InstructionGroupValid911(p,p.groups[i]) /\ UNION {p.groups[i].units : i \in 1..Len(p.groups)}=DOMAIN p.units /\ \A i,j \in 1..Len(p.groups) : i#j => p.groups[i].units \cap p.groups[j].units={} /\ UNION {SubIds6(p.groups[i].nodes) : i \in 1..Len(p.groups)}=DOMAIN p.nodes /\ \A i,j \in 1..Len(p.groups) : i#j => SubIds6(p.groups[i].nodes) \cap SubIds6(p.groups[j].nodes)={} CompiledInstructionTechnique911(p,objects,cardFacts) == InstructionTechniqueSource911(p,objects,cardFacts) /\ InstructionPartitionValid911(p) ProcedureStepIsInstruction911(kind) == kind \in TimingStructureKinds9 InstructionPauseCaller911(r,plan,cause,child,point) == CASE cause="CostPaid" -> [kind |-> "InstructionCostCheckpoint",instance |-> r.id,instruction |-> InstructionWindowRef93(plan),transaction |-> child.id] [] cause="Draw" -> [kind |-> "DrawCheckpoint",batchId |-> child.id,ability |-> r.id,caller |-> InstructionWindowRef93(plan),point |-> point] [] cause="Play" -> PlayActivationCaller97(child) [] cause="EscalatingResourceContest" -> [kind |-> "EscalatingResourceContestCheckpoint",escalatingResourceContestId |-> child.id,instance |-> r.id,caller |-> InstructionWindowRef93(plan),point |-> point] [] cause="Timing" -> [kind |-> "TimingStructureCheckpoint",structure |-> child.structure,procedure |-> child.id,step |-> child.step,caller |-> InstructionWindowRef93(plan)] [] OTHER -> [kind |-> "Invalid"] InstructionPausePoint911(r,plan,context,cause,child,point,operation) == /\ context.phase="Resolving" /\ context.currentRef=InstructionWindowRef93(plan) /\ context.currentRef.abilityInstance=r.id /\ operation \in DOMAIN context.actualEffects /\ child.id \in Nat \ {0} /\ CASE cause="CostPaid" -> /\ point="CostPaid" /\ context.actualEffects[operation].kind \in {"Cost","PayNestedCost"} /\ child.tag="CompletedInstructionCost" /\ child.instance=r.id /\ child.instruction=context.currentRef /\ child.source=r.ability.source /\ child.paid /\ ~child.lastAction /\ child.id=child.transaction /\ child.operation=operation /\ child.payer=context.actualEffects[operation].payer /\ child.specification=context.actualEffects[operation].cost /\ child.receipt.tag="CompletedCostTransaction" /\ child.receipt.id=child.transaction /\ child.receipt.instance=r.id /\ child.receipt.instruction=context.currentRef /\ child.receipt.source=r.ability.source /\ child.receipt.payer=child.payer /\ child.receipt.specification=child.specification /\ child.receipt.allCostsPaid [] cause="Draw" -> /\ point="ProcedureCode8be6d2dd1e98" /\ context.actualEffects[operation].kind="Draw" /\ DrawBatchValid8(child) /\ child.stage="Checkpoint" /\ child.ability=r.id /\ child.caller=context.currentRef [] cause="Play" -> /\ point="ProcedureCodebddd9a1a600b" /\ context.actualEffects[operation].kind="Play" /\ child.stage="ProcedureCodebddd9a1a600b" /\ child.activationReached /\ ~child.complete /\ child.caller=context.currentRef [] cause="EscalatingResourceContest" -> /\ point="ProcedureCoded1e36ce96789" /\ context.actualEffects[operation].kind="EscalatingResourceContest" /\ child.tag="ActualEscalatingResourceContestProcedure" /\ child.point=point /\ child.instance=r.id /\ child.caller=context.currentRef [] cause="Timing" -> /\ context.actualEffects[operation].kind="OpenTimingStructure" /\ child.tag="ActualTimingStructureCheckpoint" /\ TimingRefValid9(child.structure) /\ child.step=point /\ child.parent=context.currentRef [] OTHER -> FALSE InstructionPauseKey911(context,plan,cause,child,point,operation) == <> PauseRuntimeInstruction911(before,after,plan,context,id,cause,child,point,operation,request,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeProfile911(before) /\ before.phase="Resolve" /\ before.ability.phase="Resolving" /\ before.pause.id=0 /\ RuntimeCurrentPlan911(before,plan) /\ plan.phase="Resolving" /\ id \in Nat \ {0} /\ InstructionPausePoint911(before,plan,context,cause,child,point,operation) /\ InstructionPauseKey911(context,plan,cause,child,point,operation) \notin before.pauseKeys /\ request.tag="OwnedInstructionCheckpointRequest" /\ request.id \in Nat \ {0} /\ request.caller=InstructionPauseCaller911(before,plan,cause,child,point) /\ after=[before EXCEPT !.phase="Paused",!.pauseKeys=@ \cup {InstructionPauseKey911(context,plan,cause,child,point,operation)},!.pause=[id |-> id,cause |-> cause,childId |-> child.id,point |-> point, instruction |-> InstructionWindowRef93(plan),cursor |-> plan.cursor,operation |-> operation,request |-> request]] ResumeRuntimeInstruction911(before,after,plan,ledger,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeProfile911(before) /\ before.phase="Paused" /\ before.ability.phase="Resolving" /\ before.pause.id \in Nat \ {0} /\ before.pause.instruction=InstructionWindowRef93(plan) /\ before.pause.cursor=plan.cursor /\ plan.phase="Resolving" /\ receipt.tag="OwnedInstructionCheckpointReturn" /\ receipt.pauseId=before.pause.id /\ receipt.childId=before.pause.childId /\ receipt.instruction=before.pause.instruction /\ receipt.point=before.pause.point /\ receipt.id=before.pause.request.id /\ receipt.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[receipt.id].caller=before.pause.request.caller /\ receipt.complete /\ receipt.allNewerChainsComplete /\ ConditionalCheckpointDrained96(ledger,stack,receipt.id) /\ after=[before EXCEPT !.phase="Resolve",!.pause=[id |-> 0]] CarryRuntimeWorkStep911(before,after,plan,afterPlan,context,step,work) == /\ RuntimeProfile911(before) /\ before.phase="Resolve" /\ before.pause.id=0 /\ RuntimeCurrentPlan911(before,plan) /\ plan.cursor id,instance |-> p.id,definition |-> p.definition.syntax.id,source |-> p.ability.source, instruction |-> InstructionWindowRef93(plan),player |-> execution.player,zone |-> execution.zone, objects |-> SubIds6(SubSeq(deck,1,MinOf(execution.amount,Len(deck)))), execution |-> execution] GrantInstructionLook911(before,after,id,p,plan,objects,deck,execution,cardFacts) == /\ id \in (Nat \ {0}) \ DOMAIN before /\ p.id=p.ability.id /\ p.phase="Resolve" /\ AbilityIsResolving9(p.ability) /\ p.ability.phase="Resolving" /\ InstructionPlanMatches93(plan,p.ability,p.ability.cursor) /\ plan.phase="Resolving" /\ execution.tag="LookInstructionExecution" /\ execution.instance=p.id /\ execution.definition=p.definition.syntax.id /\ execution.instruction=InstructionWindowRef93(plan) /\ execution.source=p.ability.source /\ execution.player \in SetupPlayers /\ execution.amount \in Nat /\ execution.zone \in {"SideADeck","SideBDeck"} /\ execution.deck=deck /\ DeckSequenceValid4(deck) /\ SubIds6(deck) \subseteq DOMAIN objects /\ \A object \in SubIds6(deck) : objects[object].zone=execution.zone /\ execution.carriedOut /\ LookExecutionSource911(execution,objects,cardFacts) /\ ~\E old \in DOMAIN before : before[old].instance=p.id /\ before[old].instruction=InstructionWindowRef93(plan) /\ before[old].execution.context.id=execution.context.id /\ before[old].execution.operation=execution.operation /\ execution.context.phase="Resolving" /\ execution.context.currentRef=InstructionWindowRef93(plan) /\ execution.operation \in DOMAIN execution.context.actualEffects /\ execution.context.actualEffects[execution.operation].kind="Look" /\ execution.context.actualEffects[execution.operation].amount=execution.amount /\ execution.context.actualEffects[execution.operation].player=execution.player /\ execution.context.actualEffects[execution.operation].zone=execution.zone /\ after=ReplacementOverlay99(before,[key \in {id} |-> ScopedLookGrant911(id,p,plan,objects,deck,execution)]) ScopedLookPermission911(grants,id,viewer,object,owners,objects) == IF id \notin DOMAIN grants THEN FALSE ELSE LET grant == grants[id] IN IF grant.instance \notin DOMAIN owners \/ object \notin DOMAIN objects THEN FALSE ELSE LET owner == owners[grant.instance] IN /\ owner.ability.id=grant.instance /\ owner.definition.syntax.id=grant.definition /\ owner.ability.source=grant.source /\ AbilityIsResolving9(owner.ability) /\ ~owner.ability.lastFinished /\ ~owner.ability.complete /\ viewer=grant.player /\ object \in grant.objects /\ objects[object].zone=grant.zone /\ DeckMayLook4(viewer,TRUE) CurrentLookOwner911(grants,id,owners,authority) == IF id \notin DOMAIN grants THEN TRUE ELSE LET instance == grants[id].instance IN IF instance \notin DOMAIN owners THEN instance \notin DOMAIN authority.current.activity.instances ELSE /\ instance \in DOMAIN authority.current.activity.instances /\ "owner" \in DOMAIN authority.current.activity.instances[instance] /\ owners[instance]=authority.current.activity.instances[instance].owner /\ authority.current.activity.instances[instance].ability=owners[instance].definition.syntax.id /\ authority.current.activity.instances[instance].sourceObject=owners[instance].ability.source.object ReadScopedLookPermission911(grants,id,viewer,object,owners,objects,lifetimes,authority,receipt) == /\ LifetimeReady910(lifetimes,authority) /\ objects=authority.current.objects /\ CurrentLookOwner911(grants,id,owners,authority) /\ receipt=[tag |-> "CurrentScopedLookPermission",worldId |-> authority.current.id,grantId |-> id,viewer |-> viewer,object |-> object, allowed |-> ScopedLookPermission911(grants,id,viewer,object,owners,objects)] GrantCurrentInstructionLook911(before,after,id,p,plan,objects,deck,execution,cardFacts,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ objects=authority.current.objects /\ p.id \in DOMAIN authority.current.activity.instances /\ "owner" \in DOMAIN authority.current.activity.instances[p.id] /\ authority.current.activity.instances[p.id].owner=p /\ GrantInstructionLook911(before,after,id,p,plan,objects,deck,execution,cardFacts) SourceEntryDefinition911(entry) == CASE entry.kind="Paid" -> entry.after.definition [] entry.kind="PlayFirst" -> CurrentPlayDefinition97(entry.after) [] OTHER -> entry.after.payload SourceEntryOwner911(entry) == IF entry.kind="Paid" THEN [windowId |-> entry.after.windowId,option |-> entry.after.option,transaction |-> entry.after.transaction] ELSE entry.after.owner AdoptedRuntimeValue911(technique,entry) == ReplacementOverlay99(NewInstructionRuntime911(entry.after.id,technique,entry.after.ability.kind,entry.after.ability.sourceZone,entry.after.ability.caller), [ability |-> [entry.after.ability EXCEPT !.instructions= <>],phase |-> "Imminent", sourceEntry |-> entry,sourceOwner |-> SourceEntryOwner911(entry)]) AdoptSourceRuntime911(r,technique,entry,sourceOrigin,world,lifetimes,authority,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ entry.kind \in {"Paid","PlayFirst","BarrierInstructionFirst","NestedBarrierInstructionFirst"} /\ ActualImminenceEntry99(entry,sourceOrigin,world,cardFacts) /\ entry.after.ability.firstImminent /\ entry.after.ability.cursor=1 /\ entry.beforePlan.index=1 /\ CompiledInstructionTechnique911(technique,world.objects,cardFacts) /\ technique.definition=SourceEntryDefinition911(entry) /\ technique.entry=entry.afterPlan.id /\ r=AdoptedRuntimeValue911(technique,entry) /\ RuntimeCurrentPlan911(r,entry.afterPlan) SourceRuntimeBound911(r) == /\ RuntimeProfile911(r) /\ r.sourceEntry.kind \in {"Paid","PlayFirst","BarrierInstructionFirst","NestedBarrierInstructionFirst"} /\ r.technique.definition=SourceEntryDefinition911(r.sourceEntry) /\ r.id=r.sourceEntry.after.id /\ r.ability.source=r.sourceEntry.after.ability.source /\ r.ability.kind=r.sourceEntry.after.ability.kind /\ r.ability.caller=r.sourceEntry.after.ability.caller /\ r.ability.sourceZone=r.sourceEntry.after.ability.sourceZone /\ r.sourceOwner=SourceEntryOwner911(r.sourceEntry) /\ r.ability.detached=r.sourceEntry.after.ability.detached EnterNextSourceRuntime911(before,after,plan,afterPlan,targets,entry,ledger,stack,lifetimes,authority) == /\ SourceRuntimeBound911(before) /\ before.visited# <<>> /\ BarrierInstructionOwnerAtTop98(before.sourceOwner,stack) /\ RuntimeOwnerCurrent911(before,authority) /\ EnterRuntimeInstructionCore911(before,after,plan,afterPlan,targets,entry,ledger,stack,lifetimes,authority) OpenConditionalRuntime911(id,technique,w,option,transaction,sourceZone) == ReplacementOverlay99(NewInstructionRuntime911(id,technique,"Conditional",sourceZone,w.id), [windowId |-> w.id,option |-> option,transaction |-> transaction,turnId |-> w.site.turnId]) ConditionalRuntimeBound911(ledger,r) == /\ RuntimeProfile911(r) /\ r.id \in DOMAIN ledger.instances /\ LET i == ledger.instances[r.id] IN /\ i.definition=ConditionalKey96(r.technique.definition) /\ i.definitionCopy=r.technique.definition /\ r.ability.kind="Conditional" /\ r.ability.source=i.member.source /\ r.ability.caller=r.windowId /\ r.windowId=i.member.windowId /\ r.option.instance=r.id /\ r.option.ability=i.member.ability /\ r.option.source=i.member.source /\ r.option.controller=i.member.controller /\ r.transaction \in Nat \ {0} BeginConditionalRuntimeCore911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,snapshot,option,legality,currentEffect, plan,afterPlan,targets,entry,turnUses,restrictions,lifetimes,authority,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ snapshot.objects=authority.current.objects /\ ConditionalSnapshotBound96(snapshot,beforeLedger) /\ CompiledInstructionTechnique911(before.technique,snapshot.objects,cardFacts) /\ LET d == before.technique.definition id == before.id IN /\ ConditionalDefinitionValid96(d) /\ id \in DOMAIN beforeLedger.instances /\ beforeLedger.instances[id].status="Pending" /\ beforeLedger.instances[id].definitionCopy=d /\ ConditionalKey96(d) \in DOMAIN snapshot.definitions /\ snapshot.definitions[ConditionalKey96(d)]=d /\ ConditionalInstanceCurrent96(beforeLedger.instances[id],snapshot.definitions,snapshot) /\ Len(beforeStack)>0 /\ WindowTop9(beforeStack).kind=(IF AbilityInterrupt99(d,before.technique.lexemes) THEN "Interrupt" ELSE "Reaction") /\ id \in DOMAIN WindowTop9(beforeStack).members /\ WindowTop9(beforeStack).members[id]=beforeLedger.instances[id].member /\ option.instance=id /\ option.ability=d.syntax.id /\ option.source=d.syntax.source /\ option.kind=IF AbilityInterrupt99(d,before.technique.lexemes) THEN "ConditionalInterrupt" ELSE "Conditional" /\ WholeAbilityRestrictionGate93(d.syntax,restrictions) /\ OncePerTurnAllowed93(d.syntax,WindowTop9(beforeStack).site.turnId,turnUses) /\ BeginPriorityOption9(beforeStack,afterStack,option,snapshot.objects,legality,currentEffect) /\ before=OpenConditionalRuntime911(id,before.technique,WindowTop9(beforeStack),option,legality.transactionId, IF d.syntax.source.kind="Rule" THEN "Rule" ELSE IF d.syntax.source.object \in DOMAIN snapshot.objects THEN snapshot.objects[d.syntax.source.object].zone ELSE "NoValue") /\ entry.sourceEligible=ConditionalActive96(d,snapshot) /\ EnterRuntimeInstructionCore911(before,after,plan,afterPlan,targets,entry,beforeLedger,afterStack,lifetimes,authority) /\ afterLedger=[beforeLedger EXCEPT !.instances[id].status="Imminent"] /\ ConditionalRuntimeBound911(afterLedger,after) BeginConditionalRuntime911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,snapshot,option,legality,currentEffect, plan,afterPlan,targets,entry,turnUses,restrictions,lifetimes,authority,cardFacts) == /\ Len(beforeStack)>0 /\ WindowTop9(beforeStack).kind="Reaction" /\ BeginConditionalRuntimeCore911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,snapshot,option,legality,currentEffect, plan,afterPlan,targets,entry,turnUses,restrictions,lifetimes,authority,cardFacts) BeginInterruptRuntime911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,snapshot,option,legality, plan,afterPlan,targets,entry,turnUses,restrictions,lifetimes,authority,context,origin,world,history,cardFacts) == /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ CurrentInterruptWorld99(world,beforeLedger,cardFacts) /\ ExpectedContextWorld99(context,world) /\ ExpectedContextOrigin99(context,origin) /\ WouldViewCurrent99(history,context,world) /\ CurrentInterruptWindow99(context,beforeStack) /\ snapshot=world.conditional /\ turnUses=world.turnUses /\ before.id \in context.conditionalIds /\ before.id \in CurrentPendingRelevant99(context,world,history,beforeLedger) /\ before.technique.lexemes=world.lexemes[AbilityKey99(before.technique.definition)] /\ BeginConditionalRuntimeCore911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,snapshot,option,legality, CurrentEffectReceipt99(context,world,history,beforeLedger,WindowTop9(beforeStack)), plan,afterPlan,targets,entry,turnUses,restrictions,lifetimes,authority,cardFacts) EnterNextConditionalRuntime911(beforeLedger,afterLedger,stack,before,after,plan,afterPlan,targets,entry,lifetimes,authority) == /\ ConditionalRuntimeBound911(beforeLedger,before) /\ beforeLedger.instances[before.id].status="Resolving" /\ RuntimeOwnerCurrent911(before,authority) /\ ConditionalAtTop96(stack,before) /\ before.visited# <<>> /\ before.ability.detached /\ EnterRuntimeInstructionCore911(before,after,plan,afterPlan,targets,entry,beforeLedger,stack,lifetimes,authority) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status="Imminent"] ConditionalStartWorld911(entry,world,authority) == /\ entry.snapshot=SnapshotWithConditionalRegistry96(world.conditional,entry.beforeLedger) /\ entry.snapshot.id=world.id /\ entry.turnUses=world.turnUses /\ world.conditional.points=authority.current.points /\ world.conditional.present=authority.current.present /\ [world.conditional.activity EXCEPT !.instances=authority.current.activity.instances]=authority.current.activity ActualRuntimeEntry911(entry,origin,world,lifetimes,authority,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ ExpectedWorldValid99(world) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ entry.id \in DOMAIN world.entries /\ world.entries[entry.id]=entry /\ entry.tag="ActualGraphInstructionEntry" /\ entry.id \in Nat \ {0} /\ entry.snapshotId=world.id /\ origin.kind="Instruction" /\ origin.ruleStep="NoValue" /\ origin.plan=entry.afterPlan /\ origin.parent=entry.after.ability /\ entry.owner=IF entry.kind \in {"SourceFirst","SourceNext"} THEN entry.after.sourceOwner ELSE [windowId |-> entry.after.windowId,option |-> entry.after.option,transaction |-> entry.after.transaction] /\ BarrierInstructionOwnerAtTop98(entry.owner,entry.stackAfter) /\ CASE entry.kind="ConditionalFirst" -> /\ ConditionalSnapshotBound96(world.conditional,entry.afterLedger) /\ ConditionalStartWorld911(entry,world,authority) /\ IF WindowTop9(entry.stackBefore).kind="Interrupt" THEN /\ entry.parentWorld.id=world.id /\ entry.parentWorld.objects=world.objects /\ entry.parentWorld.turn=world.turn /\ entry.parentWorld.traversalControl=world.traversalControl /\ entry.parentWorld.conditional=SnapshotWithConditionalRegistry96(world.conditional,entry.beforeLedger) /\ entry.parentWorld.turnUses=world.turnUses /\ BeginInterruptRuntime911(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.stackAfter,entry.before,entry.after, entry.snapshot,entry.option,entry.legality,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt,entry.turnUses, entry.restrictions,lifetimes,authority,entry.parentContext,entry.parentOrigin,entry.parentWorld,entry.parentHistory,cardFacts) ELSE BeginConditionalRuntime911(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.stackAfter,entry.before,entry.after, entry.snapshot,entry.option,entry.legality,entry.currentEffect,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt, entry.turnUses,entry.restrictions,lifetimes,authority,cardFacts) [] entry.kind="ConditionalNext" -> /\ ConditionalSnapshotBound96(world.conditional,entry.afterLedger) /\ entry.stackBefore=entry.stackAfter /\ EnterNextConditionalRuntime911(entry.beforeLedger,entry.afterLedger,entry.stackBefore,entry.before,entry.after, entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt,lifetimes,authority) [] entry.kind="SourceFirst" -> /\ entry.owner=entry.after.sourceOwner /\ AdoptSourceRuntime911(entry.after,entry.after.technique,entry.sourceEntry,entry.sourceOrigin,world,lifetimes,authority,cardFacts) /\ entry.afterPlan=entry.sourceEntry.afterPlan /\ entry.stackAfter=entry.sourceEntry.stackAfter [] entry.kind="SourceNext" -> /\ entry.owner=entry.after.sourceOwner /\ entry.stackBefore=entry.stackAfter /\ EnterNextSourceRuntime911(entry.before,entry.after,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt, entry.ledger,entry.stackBefore,lifetimes,authority) [] OTHER -> FALSE RuntimeEntryIds911(entry) == IF entry.kind="SourceFirst" THEN {entry.id,entry.sourceEntry.id} ELSE {entry.id} BeginRuntimeExpectedContext911(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,lifetimes,authority) == /\ \A prior \in DOMAIN before.contexts : InitialWouldCaptured99(before.contexts[prior],beforeWould) /\ ActualRuntimeEntry911(entry,origin,world,lifetimes,authority,cardFacts) /\ RuntimeEntryIds911(entry) \cap before.entryIds={} /\ id \in (Nat \ {0}) \ before.usedContextIds /\ ~\E other \in DOMAIN before.contexts : WouldContextKey99(before.contexts[other].initialRef)=WouldContextKey99(OriginReference99(origin)) /\ owner=entry.owner /\ InitialExpectedProjection99(origin,world,description,projection,initial) /\ LET context == NewExpectedContext99(id,entry.id,origin,world,description,initial,owner) IN /\ observation=InitialWouldObservation99(context,observation.id) /\ RecordWouldDescriptors99(beforeWould,afterWould,id,entry.id,context.initialRef,world.id,initial,context.initialWouldGroups, context.initialPeriods,InitialWouldOrder99(context),observation) /\ after=[before EXCEPT !.entryIds=@ \cup RuntimeEntryIds911(entry),!.usedContextIds=@ \cup {id}, !.contexts=[key \in DOMAIN @ \cup {id} |-> IF key=id THEN context ELSE @[key]]] ObserveConditionalRuntimeExpected911(before,after,r,plan,context,history) == /\ ConditionalRuntimeBound911(before,r) /\ before.instances[r.id].status="Imminent" /\ r.phase="Imminent" /\ RuntimeCurrentPlan911(r,plan) /\ context.initialRef=InstructionWindowRef93(plan) /\ InitialWouldCaptured99(context,history) /\ plan.index \notin DOMAIN before.instances[r.id].expected /\ after=[before EXCEPT !.instances[r.id].expected=ReplacementOverlay99(@,[i \in {plan.index} |-> [instruction |-> context.initialRef,effects |-> ExpectedObservationSet99(context.initialEffects)]])] BeginConditionalRuntimeAtomic911(beforeLedger,afterLedger,before,after,plan,afterPlan,context,origin,clearance,world,lifetimes,authority,stack) == /\ ConditionalRuntimeBound911(beforeLedger,before) /\ beforeLedger.instances[before.id].status="Imminent" /\ ConditionalAtTop96(stack,before) /\ plan.index \in DOMAIN beforeLedger.instances[before.id].expected /\ beforeLedger.instances[before.id].expected[plan.index].instruction=context.initialRef /\ beforeLedger.instances[before.id].expected[plan.index].effects=ExpectedObservationSet99(context.initialEffects) /\ BeginRuntimeInstructionAtomic911(before,after,plan,afterPlan,context,origin,clearance,world,lifetimes,authority) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status="Resolving"] RecordConditionalRuntimeUse911(before,after,r,plan,execution,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) == /\ ConditionalRuntimeBound911(before,r) /\ before.instances[r.id].status="Resolving" /\ r.phase="Resolve" /\ RuntimeCurrentPlan911(r,plan) /\ plan.phase="Resolving" /\ execution.tag="ConditionalEffectExecution" /\ execution.instruction=InstructionWindowRef93(plan) /\ execution.abilityInstance=r.id /\ execution.source=r.ability.source /\ execution.partIds \subseteq r.technique.definition.partsByInstruction[plan.id] /\ LET d == r.technique.definition optional == execution.partIds \cap ConditionalUseOptionalParts96(d) first == optional#{} /\ ~before.instances[r.id].used used == [tag |-> "AbilityUsed",useId |-> useId,abilityInstance |-> r.id,source |-> r.ability.source,player |-> d.syntax.controller] IN IF first THEN /\ OncePerTurnAllowed93(d.syntax,r.turnId,beforeTurnUses) /\ RecordAbilityUse9(beforeUses,afterUses,useId,r.id,r.ability.source,d.syntax.controller,TRUE,{used}) /\ RecordTurnAbilityUse93(beforeTurnUses,afterTurnUses,d.syntax,r.turnId, [id |-> r.id,ability |-> d.syntax.id,source |-> r.ability.source],used) /\ after=[before EXCEPT !.instances[r.id].used=TRUE] /\ events={used} ELSE after=before /\ afterUses=beforeUses /\ afterTurnUses=beforeTurnUses /\ events={} FinishConditionalRuntimeCore911(beforeLedger,afterLedger,beforeStack,afterStack,before,after,plan,afterPlan,context, actualReturn,step,control,payment,boundary) == /\ ConditionalRuntimeBound911(beforeLedger,before) /\ ConditionalAtTop96(beforeStack,before) /\ beforeLedger.instances[before.id].status="Resolving" /\ plan.index \in DOMAIN beforeLedger.instances[before.id].expected /\ FinishRuntimeInstruction911(before,after,plan,afterPlan,context,actualReturn,step,control,payment,boundary) /\ LET last == after.pc=0 d == before.technique.definition expected == beforeLedger.instances[before.id].expected throttle == last /\ d.primaryKind="Static" /\ DOMAIN expected=1..Len(after.visited) /\ \A i \in DOMAIN expected : expected[i].effects={} IN /\ last => DOMAIN expected=1..Len(after.visited) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status=IF last THEN "Complete" ELSE "Resolving", !.throttle=IF throttle THEN ReplacementOverlay99(@,[key \in {ConditionalKey96(d)} |-> beforeLedger.stepSerial]) ELSE @] /\ SyncConditionalWindows96(beforeStack,afterStack,beforeLedger,afterLedger) ReturnConditionalRuntime911(beforeStack,afterStack,before,after,ledger,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(before,authority) /\ before.id \in authority.current.finishedInstances /\ ConditionalRuntimeBound911(ledger,before) /\ before.phase="Complete" /\ before.pc=0 /\ ledger.instances[before.id].status="Complete" /\ ConditionalAtTop96(beforeStack,before) /\ before.checkpoint \in Nat \ {0} /\ receipt.finalCheckpointId=before.checkpoint /\ LET returned == [before.ability EXCEPT !.returned=TRUE] IN /\ ReturnAbility9(before.ability,returned,TRUE,before.windowId) /\ CompletePriorityOption9(beforeStack,afterStack,receipt) /\ after=[before EXCEPT !.ability=returned,!.phase="Returned"] RuntimeFinishedDelayed911(r,ledger) == LET effect == r.technique.definition.delayedEffect IN IF r.pc=0 /\ effect \in DOMAIN ledger.effects /\ ledger.effects[effect].policy="UntilResolution" THEN {effect} ELSE {} RuntimeFinishWorld911(beforeWorld,afterWorld,r,ledger) == /\ r.id \in DOMAIN beforeWorld.activity.instances /\ afterWorld=[beforeWorld EXCEPT !.id=afterWorld.id, !.finishedInstances=@ \cup (IF r.pc=0 THEN {r.id} ELSE {}), !.finishedDelayedEffects=@, !.activity.instances[r.id]=ReplacementOverlay99(@, [ability |-> r.technique.definition.syntax.id,sourceObject |-> IF r.ability.source.kind="Object" THEN r.ability.source.object ELSE 0, status |-> IF r.pc=0 THEN "Complete" ELSE "Resolving",owner |-> RuntimeLookOwner911(r)])] FinishObservedConditionalRuntimeCore911(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ RuntimeOwnerCurrent911(before,beforeAuthority) /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ ExpectedWorldValid99(world) /\ world.id=beforeAuthority.current.id /\ world.objects=beforeAuthority.current.objects /\ world.turn=beforeAuthority.current.turn /\ world.traversalControl=beforeAuthority.current.control /\ beforeContext.phase="Resolving" /\ beforeContext.currentWorld=world.id /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.ruleStep="NoValue" /\ beforeOrigin.plan=plan /\ beforeOrigin.parent=before.ability /\ beforeContext.initialRef.source=before.ability.source /\ beforeContext.initialRef.abilityInstance=before.id /\ beforeContext.currentRef=InstructionWindowRef93(plan) /\ actualReturn.snapshotId=world.id /\ FinishConditionalRuntimeCore911(beforeLedger,candidateLedger,beforeStack,DelayedCarryStack910(beforeStack,beforeLedger,candidateLedger), before,after,plan,afterPlan,beforeContext,actualReturn,step,control,payment,boundary) /\ LET next == afterAuthority.current execution == [tag |-> "ActualObjectTransition",id |-> beforeContext.id,snapshotId |-> next.id, source |-> before.ability.source,instruction |-> beforeContext.currentRef,return |-> actualReturn] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ RuntimeFinishWorld911(beforeAuthority.current,next,after,candidateLedger) /\ AppendLifetimeTransitionCore910(beforeAuthority,afterAuthority,LifetimeKernelTransition910(beforeAuthority.current,next,execution)) /\ ObserveLingering910(beforeRegistry,local,next) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=next.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,candidateLedger,next) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeAuthority.current) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,candidateLedger,next) /\ ObserveConditionalActivity96(beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ DelayedLifetimeBound910(afterRegistry,afterLedger) /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan,!.parent=after.ability] /\ afterContext=[beforeContext EXCEPT !.phase="Returned"] FinishObservedConditionalRuntime911(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ RuntimeFinishedDelayed911(after,candidateLedger)={} /\ FinishObservedConditionalRuntimeCore911(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) DelayedRuntimePublicationAck911(original,world) == ReplacementOverlay99([original EXCEPT !.snapshotId=world.id], [publication |-> "DelayedRuntimeLifetimePublication",originatingReturn |-> original]) FinishObservedDelayedRuntime911(before,mid,after,call) == /\ call.before.technique.definition.delayedEffect \in Nat \ {0} /\ RuntimeFinishedDelayed911(call.after,call.candidateLedger)={call.before.technique.definition.delayedEffect} /\ FinishObservedConditionalRuntimeCore911(before.registry,mid.registry,before.ledger,call.candidateLedger,mid.ledger,before.stack,mid.stack, call.before,call.after,call.plan,call.afterPlan,call.context,call.afterContext,call.origin,call.afterOrigin,call.world, call.actualReturn,call.step,call.control,call.payment,call.boundary,before.snapshot,mid.snapshot,before.authority,mid.authority) /\ LET next == after.authority.current acknowledgement == DelayedRuntimePublicationAck911(call.actualReturn,mid.authority.current) execution == [tag |-> "ActualDelayedReturn",id |-> call.context.id,snapshotId |-> next.id, source |-> call.before.ability.source,instruction |-> call.context.currentRef,return |-> acknowledgement] local == [after.registry EXCEPT !.frontier=mid.registry.frontier] IN /\ next=[mid.authority.current EXCEPT !.id=next.id, !.finishedDelayedEffects=@ \cup RuntimeFinishedDelayed911(call.after,call.candidateLedger)] /\ AppendLifetimeTransitionCore910(mid.authority,after.authority,LifetimeKernelTransition910(mid.authority.current,next,execution)) /\ ObserveLingering910(mid.registry,local,next) /\ after.snapshot.id=next.id /\ LingeringConditionalWorld910(after.snapshot,mid.ledger,next) /\ after.snapshot=LingeringConditionalSnapshot910(after.snapshot,local,mid.ledger,next) /\ ObserveConditionalActivity96(mid.ledger,mid.ledger,after.ledger,mid.stack,after.stack,mid.snapshot,after.snapshot) /\ after.registry.frontier=LifetimeFrontier910(after.authority,Len(after.authority.order)) /\ DelayedLifetimeBound910(after.registry,after.ledger) CompleteObservedRuntimeCheckpoint911(before,after,ledger,stack,receipt,lifetimes,authority) == /\ RuntimeOwnerCurrent911(before,authority) /\ CompleteRuntimeCheckpoint911(before,after,ledger,stack,receipt,lifetimes,authority) RecordObservedConditionalRuntimeUse911(before,after,r,plan,execution,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events, world,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ ConditionalSnapshotBound96(world.conditional,before) /\ beforeTurnUses=world.turnUses /\ RecordConditionalRuntimeUse911(before,after,r,plan,execution,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events) FinishObservedSourceRuntime911(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack,before,after, plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ RuntimeOwnerCurrent911(before,beforeAuthority) /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ SourceRuntimeBound911(before) /\ BarrierInstructionOwnerAtTop98(before.sourceOwner,beforeStack) /\ ExpectedWorldValid99(world) /\ world.id=beforeAuthority.current.id /\ world.objects=beforeAuthority.current.objects /\ world.turn=beforeAuthority.current.turn /\ world.traversalControl=beforeAuthority.current.control /\ beforeContext.phase="Resolving" /\ beforeContext.currentWorld=world.id /\ beforeContext.currentRef=InstructionWindowRef93(plan) /\ actualReturn.snapshotId=world.id /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.ruleStep="NoValue" /\ beforeOrigin.plan=plan /\ beforeOrigin.parent=before.ability /\ beforeContext.initialRef.source=before.ability.source /\ beforeContext.initialRef.abilityInstance=before.id /\ FinishRuntimeInstruction911(before,after,plan,afterPlan,beforeContext,actualReturn,step,control,payment,boundary) /\ LET next == afterAuthority.current execution == [tag |-> "ActualObjectTransition",id |-> beforeContext.id,snapshotId |-> next.id, source |-> before.ability.source,instruction |-> beforeContext.currentRef,return |-> actualReturn] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ RuntimeFinishWorld911(beforeAuthority.current,next,after,beforeLedger) /\ AppendLifetimeTransitionCore910(beforeAuthority,afterAuthority,LifetimeKernelTransition910(beforeAuthority.current,next,execution)) /\ ObserveLingering910(beforeRegistry,local,next) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=next.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,beforeLedger,next) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeAuthority.current) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,beforeLedger,next) /\ ObserveConditionalActivity96(beforeLedger,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan,!.parent=after.ability] /\ afterContext=[beforeContext EXCEPT !.phase="Returned"] ReturnPaidRuntime911(beforeStack,afterStack,r,afterRuntime,afterProcedure,receipt,objects,transits,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceRuntimeBound911(r) /\ r.sourceEntry.kind="Paid" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ LET p == [r.sourceEntry.after EXCEPT !.ability=r.ability,!.phase="Complete",!.checkpoint=r.checkpoint] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ FinishPaidProcedure95(beforeStack,afterStack,p,afterProcedure,receipt) /\ afterRuntime=[r EXCEPT !.ability=afterProcedure.ability,!.phase="Returned"] ReturnPlayRuntime911(r,afterRuntime,beforeCohort,afterCohort,f,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceRuntimeBound911(r) /\ r.sourceEntry.kind="PlayFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ ~r.ability.detached /\ beforeCohort=r.sourceEntry.after /\ CurrentPlayDefinition97(beforeCohort)=r.technique.definition /\ PlayOwnerAtTop97(beforeCohort,f,stack) /\ BarrierInstructionOwnerAtTop98(r.sourceOwner,stack) /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,beforeCohort.playId) /\ afterCohort=PlayAdvanceDisposition97([beforeCohort EXCEPT !.ability=r.ability],"Resolved",r.id) /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] ReturnEncounterBarrierInstructionRuntime911(r,afterRuntime,beforeLoop,afterLoop,e,afterEncounter,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceRuntimeBound911(r) /\ r.sourceEntry.kind="BarrierInstructionFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ LET p == r.sourceEntry.after IN /\ BarrierInstructionLoopMatches98(beforeLoop,e) /\ p.origin="Encounter" /\ beforeLoop.current=r.id /\ e.id=p.encounter /\ e.barrierCard=p.barrierCard /\ beforeLoop.owner=r.sourceOwner /\ BarrierInstructionOwnerAtTop98(r.sourceOwner,stack) /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,p.caller) /\ afterEncounter=[e EXCEPT !.resolved=@ \cup {p.barrierInstruction}] /\ afterLoop=[beforeLoop EXCEPT !.current=0,!.handled=@ \cup {p.barrierInstruction},!.resolved=@ \cup {p.barrierInstruction}, !.history=Append(@,[barrierInstruction |-> p.barrierInstruction,instance |-> r.id,disposition |-> "Resolved",source |-> r.ability.source])] /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] ReturnNestedBarrierInstructionRuntime911(r,afterRuntime,beforeCalls,afterCalls,parentPlan,parent,ruleStep,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceRuntimeBound911(r) /\ r.sourceEntry.kind="NestedBarrierInstructionFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ BarrierInstructionOwnerAtTop98(r.sourceOwner,stack) /\ LET p == r.sourceEntry.after IN /\ NestedBarrierInstructionInvocation98(p,parentPlan,parent,ruleStep,p.invocation) /\ p.invocation.id \in DOMAIN beforeCalls /\ beforeCalls[p.invocation.id]=[instruction |-> InstructionWindowRef93(parentPlan),instance |-> r.id,status |-> "Active", source |-> r.ability.source,encounter |-> p.encounter,barrierInstruction |-> p.barrierInstruction,disposition |-> "NoValue"] /\ receipt=[tag |-> "NestedBarrierInstructionReturn",instruction |-> InstructionWindowRef93(parentPlan),invocation |-> p.invocation.id, instance |-> r.id,source |-> r.ability.source,barrierInstruction |-> p.barrierInstruction,complete |-> TRUE, disposition |-> "Resolved",finalCheckpoint |-> r.checkpoint] /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,p.caller) /\ afterCalls=[beforeCalls EXCEPT ![p.invocation.id].status="Returned",![p.invocation.id].disposition="Resolved"] /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] GrantRuntimeInstructionLook911(beforeGrants,afterGrants,id,r,plan,objects,deck,execution,lifetimes,authority) == /\ RuntimeProfile911(r) /\ r.phase="Resolve" /\ r.pause.id=0 /\ RuntimeCurrentPlan911(r,plan) /\ GrantCurrentInstructionLook911(beforeGrants,afterGrants,id,RuntimeLookOwner911(r),plan,objects,deck,execution,authority.current.cardFacts,lifetimes,authority) BeginSourceRuntimeAtomic911(before,after,plan,afterPlan,context,origin,clearance,world,stack,lifetimes,authority) == /\ SourceRuntimeBound911(before) /\ BarrierInstructionOwnerAtTop98(before.sourceOwner,stack) /\ BeginRuntimeInstructionAtomic911(before,after,plan,afterPlan,context,origin,clearance,world,lifetimes,authority) CompletePaidRuntimeCheckpoint911(before,after,ledger,stack,receipt,objects,transits,lifetimes,authority) == /\ SourceRuntimeBound911(before) /\ before.sourceEntry.kind="Paid" /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ BarrierInstructionOwnerAtTop98(before.sourceOwner,stack) /\ LET p == [before.sourceEntry.after EXCEPT !.ability=before.ability] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ before.pc=0 => PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ RuntimeOwnerCurrent911(before,authority) /\ CompleteRuntimeCheckpoint911(before,after,ledger,stack,receipt,lifetimes,authority) ReturnMidItemInspectionRuntime911(beforeStack,afterStack,r,afterRuntime,afterProcedure,receipt,objects,transits,a,afterItemInspection,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceRuntimeBound911(r) /\ r.sourceEntry.kind="Paid" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ LET p == [r.sourceEntry.after EXCEPT !.ability=r.ability,!.phase="Complete",!.checkpoint=r.checkpoint] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ FinishPaidMidItemInspection95(beforeStack,afterStack,p,afterProcedure,receipt,a,afterItemInspection) /\ afterRuntime=[r EXCEPT !.ability=afterProcedure.ability,!.phase="Returned"] TimingStepInvocation911(entry,world) == /\ entry.kind="Rule" /\ entry.ruleInvocation \in DOMAIN world.ruleInvocations /\ LET invocation == world.ruleInvocations[entry.ruleInvocation] IN /\ invocation.tag="ActualRuleInvocation" /\ ~invocation.returned /\ TimingRefValid9(invocation.structure) /\ invocation.structure.kind \in TimingStructureKinds9 /\ invocation.step=entry.ruleStep /\ entry.sourceProcedure=invocation.structure BeginTimingStepExpected911(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ TimingStepInvocation911(entry,world) /\ BeginExpectedContext99(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts,beforeWould,afterWould,observation) LinkedTimingAbility911(technique,unit,linked,context,operation,started,association) == /\ InstructionTechniqueValid911(technique) /\ unit \in technique.linked /\ technique.units[unit].category="LinkedAbility" /\ technique.units[unit].definition=linked /\ linked.syntax.id#technique.definition.syntax.id /\ linked.syntax.source=technique.source /\ context.phase="Resolving" /\ operation \in DOMAIN context.actualEffects /\ context.actualEffects[operation].kind="OpenTimingStructure" /\ started.tag="ActualTimingStructureStarted" /\ TimingRefValid9(started.structure) /\ started.parent=context.currentRef /\ started.source=technique.source /\ started.operation=operation /\ association=[tag |-> "LinkedTimingAbility",definition |-> ConditionalKey96(linked),source |-> technique.source, structure |-> started.structure,parentInstruction |-> context.currentRef,sourceUnit |-> unit] RECURSIVE SumSimultaneous912(_) SumSimultaneous912(rows) == IF rows={} THEN 0 ELSE LET r == CHOOSE r \in rows : TRUE IN r.amount+SumSimultaneous912(rows \ {r}) NumericFinal912(default,modifiers) == LET setters == {m.value : m \in {m \in modifiers : m.operation="Set"}} supported == Cardinality(setters)<=1 /\ \A m \in modifiers : IRField911(m,"known",TRUE) result == IF ~supported THEN 0 ELSE (IF setters={} THEN default ELSE CHOOSE value \in setters : TRUE) +SumSimultaneous912({[id |-> m.id,amount |-> m.value] : m \in {m \in modifiers : m.operation="Increase"}}) -SumSimultaneous912({[id |-> m.id,amount |-> m.value] : m \in {m \in modifiers : m.operation="SchemaAtom100"}}) IN [status |-> IF supported THEN "Supported" ELSE "NormalizationRequired",value |-> result] SubtypePresent912(printed,contributions,subtype) == (IF subtype \in printed THEN 1 ELSE 0) +SumSimultaneous912({[id |-> c.id,amount |-> c.amount] : c \in {c \in contributions : c.subtype=subtype}})>0 PrintedCharacteristicsBound912(printed,world,cardFacts) == /\ DOMAIN printed=DOMAIN world.objects /\ \A id \in DOMAIN printed : /\ printed[id].card=world.objects[id].card /\ printed[id].sourceSHA=cardFacts[printed[id].card].sourceSHA /\ printed[id].printedBarrierInstructions \subseteq printed[id].abilities /\ \A key \in DOMAIN printed[id].values : printed[id].values[key] \in Int CharacteristicInitial912(printed) == [id \in DOMAIN printed |-> [subtypes |-> printed[id].subtypes,abilities |-> printed[id].abilities, cannotGain |-> FALSE,values |-> printed[id].values,unresolved |-> {}]] SimultaneousSourceBound912(e,world,cardFacts) == /\ e.id \in Nat \ {0} /\ e.provider \in {"Static","Lingering","Rule"} /\ e.source=e.definition.syntax.source /\ e.definition.activity.source=e.source /\ e.definition.activity.id=e.definition.syntax.id /\ AbilityLexemesValid99(e.definition,e.lexemes,world.objects,cardFacts) /\ e.card=e.lexemes.card /\ e.sourceSHA=e.lexemes.sourceSHA /\ IF e.source.kind="Rule" THEN /\ e.provider \in {"Rule","Lingering"} /\ e.card="NoValue" /\ e.sourceSHA="0186148ecd6da8170b6555aa90d3f0115a8d5150d807078b75ac2339a2a1421e" ELSE /\ e.card \in DOMAIN cardFacts /\ e.sourceSHA=cardFacts[e.card].sourceSHA /\ IF e.source.object \in DOMAIN world.objects THEN (e.definition.activity.provider="Printed" => world.objects[e.source.object].card=e.card) ELSE e.provider="Lingering" /\ e.provider="Static" => e.definition.syntax.kind="Static" /\ e.definition.activity.kind="Static" SimultaneousPresent912(s) == UNION {s.chars[id].abilities : id \in DOMAIN s.chars} SimultaneousEnabled912(s,e) == CASE e.provider="Static" -> StaticAbilityActive94(e.definition.activity,e.definition.syntax,s.world.objects,SimultaneousPresent912(s), LingeringObjectActive910(e.source,s.world),s.world.activity,s.world.points) [] e.provider="Lingering" -> e.lifetimeId \in DOMAIN s.lifetimes.effects /\ s.lifetimes.effects[e.lifetimeId].status="Active" [] OTHER -> TRUE SimultaneousTargets912(s,e) == CASE e.query.kind="Self" -> IF e.source.object \in DOMAIN s.chars THEN {e.source.object} ELSE {} [] e.query.kind="Host" -> IF e.source.object \in DOMAIN s.world.objects /\ s.world.objects[e.source.object].host \in DOMAIN s.chars THEN {s.world.objects[e.source.object].host} ELSE {} [] e.query.kind="ItemActivatedSubtype" -> {id \in DOMAIN s.chars : s.world.objects[id].kind="Barrier" /\ s.world.objects[id].activated /\ e.query.subtype \in s.chars[id].subtypes} [] e.query.kind="HostedTechniques" -> {id \in DOMAIN s.chars : s.world.objects[id].host=e.source.object /\ s.world.objects[id].kind="Technique"} [] OTHER -> e.query.objects \cap DOMAIN s.chars SimultaneousActionValue912(s,value) == IF value.kind="Literal" THEN [known |-> TRUE,value |-> value.value] ELSE [known |-> value.attribute \notin s.chars[value.object].unresolved,value |-> s.chars[value.object].values[value.attribute]] SimultaneousActions912(s,e,targets) == CASE e.action.kind="CopyItemActivatedBarrierSubtypes" -> {[id |-> e.id,target |-> target,kind |-> "Subtype",subtype |-> subtype,amount |-> 1] : target \in targets,subtype \in UNION {s.chars[id].subtypes : id \in {id \in DOMAIN s.chars : id#e.source.object /\ s.world.objects[id].kind="Barrier" /\ s.world.objects[id].activated}}} [] e.action.kind="Subtype" -> {[id |-> e.id,target |-> target,kind |-> "Subtype",subtype |-> e.action.subtype,amount |-> e.action.amount] : target \in targets} [] e.action.kind="Numeric" -> {[id |-> e.id,target |-> target,kind |-> "Numeric",attribute |-> e.action.attribute,operation |-> e.action.operation, value |-> SimultaneousActionValue912(s,e.action.value).value,known |-> SimultaneousActionValue912(s,e.action.value).known] : target \in targets} [] e.action.kind="GrantAbility" -> {[id |-> e.id,target |-> target,kind |-> "GrantAbility",ability |-> e.action.ability,placement |-> e.action.placement] : target \in {target \in targets : ~s.chars[target].cannotGain}} [] OTHER -> {[id |-> e.id,target |-> target,kind |-> e.action.kind] : target \in targets} SimultaneousView912(s,id) == LET e == s.effects[id] enabled == SimultaneousEnabled912(s,e) targets == IF enabled THEN SimultaneousTargets912(s,e) ELSE {} IN [enabled |-> enabled,targets |-> targets,actions |-> IF enabled THEN SimultaneousActions912(s,e,targets) ELSE {}] SimultaneousAllActions912(outputs) == UNION {outputs[id] : id \in DOMAIN outputs} SimultaneousProject912(s,outputs,actions) == LET all == SimultaneousAllActions912(outputs) IN [target \in DOMAIN s.chars |-> LET row == s.chars[target] local == {a \in actions : a.target=target} numeric == {a \in all : a.target=target /\ a.kind="Numeric"} subtype == {a \in all : a.target=target /\ a.kind="Subtype"} lossAll == \E a \in local : a.kind="LoseAllAbilities" lossExcept == \E a \in local : a.kind="LoseExceptPrintedBarrierInstructions" blocked == row.cannotGain \/ lossAll \/ lossExcept abilities == IF lossAll THEN {} ELSE IF lossExcept THEN row.abilities \cap s.printed[target].printedBarrierInstructions ELSE row.abilities IN [subtypes |-> {subtypeName \in s.printed[target].subtypes \cup {a.subtype : a \in subtype} : SubtypePresent912(s.printed[target].subtypes,subtype,subtypeName)}, values |-> [key \in DOMAIN s.printed[target].values |-> NumericFinal912(s.printed[target].values[key],{m \in numeric : m.attribute=key}).value], unresolved |-> {key \in DOMAIN s.printed[target].values : NumericFinal912(s.printed[target].values[key],{m \in numeric : m.attribute=key}).status#"Supported"}, cannotGain |-> blocked,abilities |-> abilities \cup (IF blocked THEN {} ELSE {a.ability : a \in {a \in local : a.kind="GrantAbility"}})]] SimultaneousPreview912(s,id) == LET view == SimultaneousView912(s,id) outputs == ReplacementOverlay99(s.outputs,[key \in {id} |-> view.actions]) IN [s EXCEPT !.outputs=outputs,!.chars=SimultaneousProject912(s,outputs,view.actions)] SimultaneousRawDependencies912(s) == LET pairs == {[dependent |-> b,prerequisite |-> a] : b \in s.waiting,a \in s.waiting} IN {edge \in pairs : edge.dependent#edge.prerequisite /\ SimultaneousView912(s,edge.dependent)#SimultaneousView912(SimultaneousPreview912(s,edge.prerequisite),edge.dependent)} SimultaneousIndependent912(s,dependencies) == {id \in s.waiting : ~\E edge \in dependencies : edge.dependent=id} SimultaneousHostedEdge912(s,edge) == LET child == s.effects[edge.dependent].source host == s.effects[edge.prerequisite].source IN /\ child.kind="Object" /\ host.kind="Object" /\ child.object \in DOMAIN s.world.objects /\ s.world.objects[child.object].host=host.object SimultaneousDependencies912(s) == LET raw == SimultaneousRawDependencies912(s) IN IF SimultaneousIndependent912(s,raw)#{} THEN raw ELSE {edge \in raw : ~SimultaneousHostedEdge912(s,edge)} SimultaneousEligible912(s) == SimultaneousIndependent912(s,SimultaneousDependencies912(s)) SimultaneousBoundary912(s) == IF s.waiting#{} /\ SimultaneousEligible912(s)={} THEN "ResidualCycleNormalizationRequired" ELSE IF \E id \in DOMAIN s.chars : s.chars[id].unresolved#{} THEN "SetterNormalizationRequired" ELSE "Supported" NewSimultaneousEvaluation912(world,printed,effects,lifetimes) == [tag |-> "SimultaneousCharacteristics",world |-> world,printed |-> printed,effects |-> effects,lifetimes |-> lifetimes, chars |-> CharacteristicInitial912(printed),outputs |-> [emptyId \in {} |-> emptyId],waiting |-> DOMAIN effects,applied |-> <<>>,skipped |-> {},trace |-> <<>>] SimultaneousPotentialTargets912(e,world) == CASE e.query.kind="Explicit" -> e.query.objects [] e.query.kind="Self" -> {e.source.object} \cap DOMAIN world.objects [] e.query.kind="Host" -> IF e.source.object \in DOMAIN world.objects THEN {world.objects[e.source.object].host} \cap DOMAIN world.objects ELSE {} [] e.query.kind="ItemActivatedSubtype" -> {id \in DOMAIN world.objects : world.objects[id].kind="Barrier" /\ world.objects[id].activated} [] OTHER -> {id \in DOMAIN world.objects : world.objects[id].host=e.source.object /\ world.objects[id].kind="Technique"} SimultaneousIRValid912(e,world,printed) == /\ e.query.kind \in {"Self","Host","ItemActivatedSubtype","HostedTechniques","Explicit"} /\ e.action.kind \in {"CopyItemActivatedBarrierSubtypes","Subtype","Numeric","GrantAbility","LoseAllAbilities","LoseExceptPrintedBarrierInstructions"} /\ e.query.kind="Explicit" => e.query.objects \subseteq DOMAIN printed /\ e.action.kind="Numeric" => /\ e.action.operation \in {"Set","Increase","SchemaAtom100"} /\ \A id \in SimultaneousPotentialTargets912(e,world) : e.action.attribute \in DOMAIN printed[id].values /\ e.action.value.kind \in {"Literal","Attribute"} /\ IF e.action.value.kind="Literal" THEN e.action.value.value \in Int ELSE e.action.value.object \in DOMAIN printed /\ e.action.value.attribute \in DOMAIN printed[e.action.value.object].values /\ e.action.kind="Subtype" => e.action.amount \in Int OpenSimultaneousEvaluation912(after,world,printed,effects,lifetimes,authority,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ world=authority.current /\ PrintedCharacteristicsBound912(printed,world,cardFacts) /\ \A id \in DOMAIN effects : /\ effects[id].id=id /\ SimultaneousSourceBound912(effects[id],world,cardFacts) /\ SimultaneousIRValid912(effects[id],world,printed) /\ effects[id].provider="Lingering" => /\ effects[id].lifetimeId \in DOMAIN lifetimes.effects /\ LET maintained == lifetimes.effects[effects[id].lifetimeId] IN /\ maintained.source=effects[id].source /\ maintained.kind="Strength" /\ effects[id].query=[kind |-> "Explicit",objects |-> {maintained.target}] /\ effects[id].action=[kind |-> "Numeric",attribute |-> "Strength",operation |-> "Increase", value |-> [kind |-> "Literal",value |-> maintained.value]] /\ after=NewSimultaneousEvaluation912(world,printed,effects,lifetimes) ApplySimultaneousEffect912(before,after,id,receipt) == /\ before.tag="SimultaneousCharacteristics" /\ id \in before.waiting /\ id \in SimultaneousEligible912(before) /\ LET view == SimultaneousView912(before,id) preview == SimultaneousPreview912(before,id) IN /\ \A target \in DOMAIN preview.chars : preview.chars[target].unresolved={} /\ receipt=[tag |-> "AppliedCharacteristicEffect",worldId |-> before.world.id,effect |-> id, source |-> before.effects[id].source,before |-> before.chars,view |-> view,dependencies |-> SimultaneousDependencies912(before)] /\ after=[preview EXCEPT !.waiting=@ \ {id},!.applied=IF view.enabled THEN Append(@,id) ELSE @, !.skipped=IF view.enabled THEN @ ELSE @ \cup {id},!.trace=Append(@,receipt)] OnceChoiceController912(rows,active) == LET players == {rows[id].chooser : id \in DOMAIN rows} IN IF Cardinality(players)>1 THEN active ELSE CHOOSE p \in players : TRUE ResolveOnceChoice912(before,after,key,rows,turn,choice,receipt) == /\ rows#[emptyId \in {} |-> emptyId] /\ key \notin DOMAIN before /\ turn.owner \in SetupPlayers /\ \A id \in DOMAIN rows : rows[id].key=key /\ rows[id].chooser \in SetupPlayers /\ choice.player=OnceChoiceController912(rows,turn.owner) /\ choice.selection \in UNION {rows[id].options : id \in {id \in DOMAIN rows : rows[id].chooser=choice.player}} /\ receipt=[tag |-> "OnceOnlySimultaneousChoice",key |-> key,turnId |-> turn.id,active |-> turn.owner, chooser |-> choice.player,choice |-> choice.selection,remainder |-> [id \in DOMAIN rows |-> rows[id].remainder],sources |-> rows] /\ after=ReplacementOverlay99(before,[id \in {key} |-> receipt]) ResolveCurrentOnceChoice912(before,after,key,rows,world,lifetimes,authority,package,choice,receipt,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ world=authority.current /\ package.tag="AuthoritativeResolvedChoiceGrants" /\ package.worldId=world.id /\ package.turnId=world.turn.id /\ package.decision=key /\ package.effects=rows /\ \A id \in DOMAIN rows : LET row == rows[id] IN /\ row.tag="SourceBoundOnceChoiceEffect" /\ row.occurrence=id /\ row.card \in DOMAIN cardFacts /\ row.sourceSHA=cardFacts[row.card].sourceSHA /\ row.source.kind="Object" /\ IF row.source.object \in DOMAIN world.objects THEN world.objects[row.source.object].card=row.card ELSE TRUE /\ row.grant.tag="ResolvedOnceChoiceGrant" /\ row.grant.occurrence=id /\ row.grant.decision=key /\ row.grant.source=row.source /\ row.grant.card=row.card /\ row.grant.sourceSHA=row.sourceSHA /\ row.grant.chooser=row.chooser /\ row.grant.options=row.options /\ row.grant.remainder=row.remainder /\ ResolveOnceChoice912(before,after,key,rows,world.turn,choice,receipt) CompleteSimultaneousEvaluation912(s,lifetimes,authority,receipt) == /\ LifetimeReady910(lifetimes,authority) /\ s.world=authority.current /\ s.lifetimes=lifetimes /\ s.waiting={} /\ SimultaneousBoundary912(s)="Supported" /\ DeckSequenceValid4(s.applied) /\ SubIds6(s.applied) \cap s.skipped={} /\ SubIds6(s.applied) \cup s.skipped=DOMAIN s.effects /\ DOMAIN s.outputs=DOMAIN s.effects /\ Len(s.trace)=Cardinality(DOMAIN s.effects) /\ receipt=[tag |-> "CompleteCharacteristicProjection",worldId |-> s.world.id,printed |-> s.printed,effects |-> s.effects, characteristics |-> s.chars,applied |-> s.applied,skipped |-> s.skipped,trace |-> s.trace] AggregatedOperations912 == {"GainResourceUnits","LoseResourceUnits","SpendResourceUnits","GainActionPoints","LoseActionPoints","SpendActionPoints", "TakeExposureMarkers","RemoveExposureMarkers","PreventExposureMarkers","TakeLiabilityMarker","RemoveLiabilityMarker","PreventLiabilityMarker", "LookAtCards","RevealCards","Draw","RetireCards","Damage","ShuffleDiscardIntoDeck"} RECURSIVE QuantitySum912(_) QuantitySum912(values) == IF values= <<>> THEN 0 ELSE Head(values)+QuantitySum912(Tail(values)) QuantityPartOrder912(g) == g.partOrder QuantityRepeatCount912(g) == IF g.mode="Items" THEN Len(g.items) ELSE IF g.count>0 THEN g.count ELSE 0 QuantityGroupShape912(g) == /\ g.tag="NormalizedQuantityGroup" /\ g.id \in Nat \ {0} /\ g.mode \in {"Count","Items"} /\ DeckSequenceValid4(g.partOrder) /\ SubIds6(g.partOrder)=DOMAIN g.parts /\ Len(g.partOrder)>0 /\ IF g.mode="Count" THEN g.count \in Int ELSE DeckSequenceValid4(g.items) /\ \A part \in DOMAIN g.parts : LET p == g.parts[part] IN /\ p.id=part /\ p.basePresent \in BOOLEAN /\ p.base \in Int /\ IF g.mode="Count" THEN p.unit \in Int ELSE /\ DOMAIN p.units=SubIds6(g.items) /\ DOMAIN p.arguments=SubIds6(g.items) /\ \A item \in SubIds6(g.items) : p.units[item] \in Int QuantitySourceBound912(g,reference,world,cardFacts) == /\ QuantityGroupShape912(g) /\ g.instruction=reference /\ g.source=reference.source /\ g.snapshotId=world.id /\ g.origin.tag="FixedAbilitySourceObservation" /\ g.origin.source=g.source /\ g.origin.card=g.card /\ g.origin.sourceSHA=g.sourceSHA /\ IF g.source.kind="Rule" THEN g.card="Rule" /\ g.sourceSHA="0186148ecd6da8170b6555aa90d3f0115a8d5150d807078b75ac2339a2a1421e" ELSE /\ g.card \in DOMAIN cardFacts /\ g.sourceSHA=cardFacts[g.card].sourceSHA /\ IF g.source.object \in DOMAIN world.objects THEN world.objects[g.source.object].card=g.card ELSE TRUE QuantityPartAggregates912(part) == /\ part.operation \in AggregatedOperations912 /\ IF part.operation \in {"LookAtCards","RevealCards","RetireCards"} THEN ("location" \in DOMAIN part.specifications /\ part.specifications.location#"NoValue") \/ ("locations" \in DOMAIN part.specifications /\ part.specifications.locations#{}) ELSE TRUE QuantityAggregates912(g) == \A part \in DOMAIN g.parts : QuantityPartAggregates912(g.parts[part]) QuantityUnitValue912(g,part,index) == IF g.mode="Count" THEN g.parts[part].unit ELSE g.parts[part].units[g.items[index]] QuantityUnitArguments912(g,part,index) == IF g.mode="Count" THEN g.parts[part].arguments ELSE g.parts[part].arguments[g.items[index]] QuantityTotal912(g,part) == (IF g.parts[part].basePresent THEN g.parts[part].base ELSE 0) + (IF g.mode="Count" THEN g.parts[part].unit*g.count ELSE QuantitySum912([i \in 1..Len(g.items) |-> g.parts[part].units[g.items[i]]])) QuantityEmission912(g,part,index,aggregated) == [tag |-> "NormalizedQuantityEmission",group |-> g.id,instruction |-> g.instruction,source |-> g.source, part |-> part,operation |-> g.parts[part].operation,specifications |-> g.parts[part].specifications, value |-> IF aggregated THEN QuantityTotal912(g,part) ELSE IF index=0 THEN g.parts[part].base ELSE QuantityUnitValue912(g,part,index), occurrence |-> index,aggregated |-> aggregated, arguments |-> IF aggregated THEN (IF g.parts[part].basePresent THEN <> ELSE <<>>) \o [i \in 1..QuantityRepeatCount912(g) |-> QuantityUnitArguments912(g,part,i)] ELSE IF index=0 THEN g.parts[part].baseArguments ELSE QuantityUnitArguments912(g,part,index)] RECURSIVE QuantityEmitParts912(_,_,_,_) QuantityEmitParts912(g,parts,index,aggregated) == IF parts= <<>> THEN <<>> ELSE LET part == Head(parts) include == IF aggregated THEN QuantityTotal912(g,part)>0 ELSE index#0 \/ g.parts[part].basePresent IN (IF include THEN <> ELSE <<>>) \o QuantityEmitParts912(g,Tail(parts),index,aggregated) RECURSIVE QuantityEmitRounds912(_,_,_) QuantityEmitRounds912(g,index,remaining) == IF remaining=0 THEN <<>> ELSE QuantityEmitParts912(g,g.partOrder,index,FALSE) \o QuantityEmitRounds912(g,index+1,remaining-1) QuantityEmissions912(g) == IF QuantityAggregates912(g) THEN QuantityEmitParts912(g,g.partOrder,0,TRUE) ELSE QuantityEmitParts912(g,g.partOrder,0,FALSE) \o QuantityEmitRounds912(g,1,QuantityRepeatCount912(g)) NormalizeQuantityGroup912(g,reference,world,cardFacts,emissions) == QuantitySourceBound912(g,reference,world,cardFacts) /\ emissions=QuantityEmissions912(g) AllSetSatisfied912(items,matching,actualPoint,earliestPoint) == /\ TimingRefValid9(actualPoint.structure) /\ actualPoint.structure=earliestPoint.structure /\ actualPoint.ordinal>=earliestPoint.ordinal /\ items \subseteq matching EncounterAllSetPoint912(e) == [structure |-> TimingRef9("TraversalPhase",e.id),ordinal |-> IF e.paidReached /\ ~e.aborted /\ ~e.bypassed THEN 1 ELSE 0] EncounterAllSubsSatisfied912(e) == AllSetSatisfied912(SubIds6(e.order),e.barrierInstructionSuppressed,EncounterAllSetPoint912(e), [structure |-> TimingRef9("TraversalPhase",e.id),ordinal |-> IF Len(e.order)=0 THEN 1 ELSE 0]) CurrentXDefinitionActive912(d,world,cardFacts) == LET source == d.syntax.source default == IF source.kind="Object" /\ source.object \in DOMAIN world.objects THEN world.cardActivity[source.object] ELSE FALSE IN FlagActivity93(d.syntax,world.present, AbilityActive9(d.activity,world.objects,world.present,default,world.activity), world.activity.persistentAbilities,world.points) VariableXValue912(d,world,cardFacts,evaluation) == IF ~CurrentXDefinitionActive912(d,world,cardFacts) \/ ~evaluation.available THEN 0 ELSE evaluation.value ObserveVariableX912(d,world,cardFacts,evaluation,value) == /\ evaluation.tag="CurrentVariableEvaluation" /\ evaluation.ability=d.syntax.id /\ evaluation.source=d.syntax.source /\ evaluation.snapshotId=world.id /\ evaluation.available \in BOOLEAN /\ evaluation.value \in Int /\ value=VariableXValue912(d,world,cardFacts,evaluation) Specimen0232ProtectingBarrier912(source,objects) == IF source.kind#"Object" \/ source.object \notin DOMAIN objects THEN {} ELSE {id \in DOMAIN objects : objects[id].form="Card" /\ objects[id].kind="Barrier" /\ objects[id].zone="Play" /\ objects[id].deployed /\ objects[id].area="Protecting" /\ objects[id].targetSite=objects[source.object].targetSite} Specimen0232XEvaluation912(d,world) == [tag |-> "CurrentVariableEvaluation",ability |-> d.syntax.id,source |-> d.syntax.source,snapshotId |-> world.id, available |-> TRUE,value |-> 2*Cardinality(Specimen0232ProtectingBarrier912(d.syntax.source,world.objects))] HostedQuantityCounters912(objects,host,kind) == {id \in DOMAIN objects : objects[id].form="Counter" /\ objects[id].host=host /\ objects[id].zone="Play" /\ objects[id].kind=kind} Specimen0202DrawQuantity912(g,reference,world,cardFacts,emissions) == /\ g.card="Specimen0202" /\ g.mode="Count" /\ g.count=world.actionPoints["SideB"] /\ g.partOrder= <<1>> /\ g.parts[1].operation="Draw" /\ ~g.parts[1].basePresent /\ g.parts[1].unit=1 /\ NormalizeQuantityGroup912(g,reference,world,cardFacts,emissions) ExampleFamily072DamageQuantity912(g,reference,world,cardFacts,emissions) == /\ g.card="Specimen0255" /\ g.source.kind="Object" /\ g.mode="Count" /\ g.count=Cardinality(HostedQuantityCounters912(world.objects,g.source.object,"Progress")) /\ g.partOrder= <<1>> /\ g.parts[1].operation="Damage" /\ g.parts[1].basePresent /\ g.parts[1].base=2 /\ g.parts[1].unit=1 /\ g.parts[1].specifications.damageType="HarmClassA" /\ g.parts[1].specifications.actor="SideA" /\ NormalizeQuantityGroup912(g,reference,world,cardFacts,emissions) Specimen0219RootCards912(world) == {id \in DOMAIN world.objects : world.objects[id].form="Card" /\ world.objects[id].side="SideA" /\ world.objects[id].zone="Play" /\ world.objects[id].deployed /\ world.objects[id].area="Root" /\ world.objects[id].targetSite=world.traversal.attacked /\ world.objects[id].host=0} Specimen0219RetireSet912(world,afterObjects,effect,directive,context,successors,usedObjects,receipt,cardFacts) == /\ effect.tag="ResolvedSpecimen0219Replacement" /\ effect.card="NeutralValue00015" /\ TraversalTimingPresent6(world.traversal) /\ effect.sourceSHA=cardFacts["NeutralValue00015"].sourceSHA /\ effect.source.kind="Object" /\ effect.origin.source=effect.source /\ effect.origin.card=effect.card /\ effect.origin.sourceSHA=effect.sourceSHA /\ effect.origin.tag="FixedAbilitySourceObservation" /\ effect.traversalId=world.traversal.id /\ world.targetSiteKinds[world.traversal.attacked]="SchemaAtom132" /\ world.traversal.successful /\ world.traversal.phase="Success" /\ world.traversal.step="ProcedureCoded75d879e00ff" /\ ~world.traversal.ending /\ TraversalInspectionModifierApplies6(effect,world.traversal,directive) /\ directive.kind="Replacement" /\ directive.choice="Specimen0219" /\ directive.targetSite=world.traversal.attacked /\ context.phase="Resolving" /\ context.currentWorld=world.id /\ context.currentRef.origin="Rule" /\ context.currentRef.source=RuleAbilitySource9("ProcedureCoded75d879e00ff") /\ context.currentRef.abilityInstance=0 /\ context.currentRef.index=0 /\ LET selected == Specimen0219RootCards912(world) IN /\ \A id \in DOMAIN world.objects : world.objects[id].host \notin selected /\ receipt=[tag |-> "CompletedSimultaneousRetireSet",id |-> effect.id,contextId |-> context.id, instruction |-> context.currentRef,snapshotId |-> world.id,source |-> effect.source, actor |-> "SideB",members |-> selected,purpose |-> "Specimen0219Root",targetSite |-> world.traversal.attacked, beforeObjects |-> world.objects,afterObjects |-> afterObjects] /\ CardBatchTransfer8(world.objects,afterObjects,selected,successors,usedObjects,"SideADiscard","Up",[id \in selected |-> "Discard"]) ExampleFamily075BatchMembers912(batch,beforeObjects,targetSite) == {id \in batch.members \cap DOMAIN beforeObjects : beforeObjects[id].form="Card" /\ beforeObjects[id].zone="Play" /\ beforeObjects[id].targetSite=targetSite /\ beforeObjects[id].area \in {"Root","Protecting","TargetSite"}} QuantityRetireOccurrences912(batch,beforeSnapshot,successors,exampleFamily075Definition,targetSite,ids) == LET sideA == {id \in batch.members : beforeSnapshot.objects[id].side="SideA"} perCard == [id \in sideA |-> [tag |-> "ConditionalOccurrence",id |-> ids.perCard[id],kind |-> "Retireed",object |-> id, actor |-> batch.actor,side |-> "SideA",snapshot |-> beforeSnapshot,effectId |-> batch.id, scopeKind |-> "Global",scopeDefinition |-> [ability |-> 0,source |-> RuleAbilitySource9("NoValue")], structure |-> NoTimingRef9,step |-> "NoValue",traversal |-> NoTraversal6,siteInspection |-> [traversalId |-> 0,origin |-> "NoValue"],movement |-> [tag |-> "SourceZoneChange",oldObject |-> id,newObject |-> successors[id],beforeSnapshot |-> beforeSnapshot]]] relevant == ExampleFamily075BatchMembers912(batch,beforeSnapshot.objects,targetSite) anchor == exampleFamily075Definition.syntax.source.object batchEvent == [tag |-> "ConditionalOccurrence",id |-> ids.batch,kind |-> "AtLeastOneRetireed",object |-> anchor, actor |-> batch.actor,side |-> "SchemaAtom016",snapshot |-> beforeSnapshot,effectId |-> batch.id, scopeKind |-> "Ability",scopeDefinition |-> ConditionalKey96(exampleFamily075Definition),members |-> relevant, structure |-> NoTimingRef9,step |-> "NoValue",traversal |-> NoTraversal6,siteInspection |-> [traversalId |-> 0,origin |-> "NoValue"], movement |-> IF anchor \in DOMAIN successors THEN [tag |-> "SourceZoneChange",oldObject |-> anchor,newObject |-> successors[anchor],beforeSnapshot |-> beforeSnapshot] ELSE [tag |-> "NoValue",oldObject |-> 0,newObject |-> 0,beforeSnapshot |-> beforeSnapshot]] IN [perCard |-> perCard,batchEvent |-> batchEvent,batchEvents |-> IF relevant#{} THEN [id \in {batchEvent.id} |-> batchEvent] ELSE [id \in {} |-> id]] ExampleFamily092LookCount912(context,effectId) == context.state.effects[effectId].value+1 ExampleFamily033GainSourceMatches912(definition,event) == event.actor=definition.syntax.controller /\ event.effectSource.kind="Object" /\ event.effectSource#definition.syntax.source Specimen0094FullySuppressInstructionMatch912(effect,before,after,event,occurrenceSubtypes,earlierMatchingEvents,cardFacts) == /\ effect.card="Specimen0094" /\ effect.sourceSHA=cardFacts["Specimen0094"].sourceSHA /\ effect.traversalId=after.traversalId /\ earlierMatchingEvents={} /\ event \in NewFullySuppressInstructionEvents6(before,after) /\ event.traversalId=effect.traversalId /\ event.barrierCard=after.barrierCard /\ "Sentry" \in occurrenceSubtypes /\ EncounterAllSubsSatisfied912(after) QuantityRetireIdsValid912(batch,beforeObjects,ids,used) == LET sideA == {id \in batch.members : beforeObjects[id].side="SideA"} values == {ids.perCard[id] : id \in DOMAIN ids.perCard} IN /\ DOMAIN ids.perCard=sideA /\ values \subseteq (Nat \ {0}) \ used /\ Cardinality(values)=Cardinality(sideA) /\ ids.batch \in (Nat \ {0}) \ (used \cup values) ObserveQuantityRetireOccurrences912(batch,beforeSnapshot,successors,exampleFamily075Definition,targetSite,ids,used,result) == /\ batch.tag="CompletedSimultaneousRetireSet" /\ batch.snapshotId=beforeSnapshot.id /\ batch.beforeObjects=beforeSnapshot.objects /\ QuantityRetireIdsValid912(batch,beforeSnapshot.objects,ids,used) /\ result=QuantityRetireOccurrences912(batch,beforeSnapshot,successors,exampleFamily075Definition,targetSite,ids) MustResourcePlanAffordable912(plan,world) == /\ DOMAIN plan \subseteq DOMAIN world.resources /\ \A resource \in DOMAIN plan : plan[resource] \in Nat /\ plan[resource]<=world.resources[resource] MustSourceBound912(declaration,site,world,cardFacts) == /\ world.tag="CurrentMustWorld" /\ world.id \in Nat \ {0} /\ \A resource \in DOMAIN world.resources : world.resources[resource] \in Nat /\ declaration.tag="NormalizedMustDeclaration" /\ declaration.card \in DOMAIN cardFacts /\ declaration.sourceSHA=cardFacts[declaration.card].sourceSHA /\ declaration.source=declaration.definition.syntax.source /\ declaration.controller=declaration.definition.syntax.controller /\ declaration.actor \in SetupPlayers /\ declaration.source.kind="Object" /\ declaration.source.object \in Nat \ {0} /\ IF declaration.source.object \in DOMAIN world.objects THEN world.objects[declaration.source.object].card=declaration.card ELSE declaration.origin="Instruction" /\ AbilityTextValid93(declaration.definition.syntax) /\ site.tag="CurrentMustDecisionSite" /\ site.id \in Nat \ {0} /\ site.snapshotId=world.id /\ CASE declaration.origin="Instruction" -> /\ declaration.definition.syntax.kind \in {"Paid","Conditional","Play","BarrierInstruction"} /\ site.context.phase="Resolving" /\ site.context.currentWorld=world.id /\ site.context.currentRef=InstructionWindowRef93(site.plan) /\ site.context.currentRef.source=declaration.source /\ site.plan.phase="Resolving" /\ AbilityIsResolving9(site.ability) /\ site.ability.kind=declaration.definition.syntax.kind /\ InstructionPlanMatches93(site.plan,site.ability,site.ability.cursor) /\ site.operation \in DOMAIN site.context.actualEffects /\ site.context.actualEffects[site.operation].must=declaration /\ site.context.actualEffects[site.operation].chooser=declaration.actor /\ site.checkpointSource=[source |-> declaration.source,instruction |-> site.context.currentRef,caller |-> site.checkpointCaller] [] declaration.origin="ActionRestriction" -> /\ declaration.definition.syntax.kind="Static" /\ StaticAbilityActive94(declaration.definition.activity,declaration.definition.syntax,world.objects,world.present, world.cardActivity[declaration.source.object],world.activity,world.points) /\ site.window.kind="NeutralValue00001" /\ site.window.open /\ site.window.stage="Ready" /\ site.window.priority=declaration.actor /\ site.window.site.turnId=world.turn.id /\ site.window.site.actionPoints>0 /\ site.window.site.timingLive /\ declaration.actionScope \in {"FirstActionPoint","AnyAction"} /\ declaration.actionScope="FirstActionPoint" => world.actionPointsSpent=0 /\ site.window.site.route="Turn" /\ site.window.site.step \in {"ProcedureCode0e20572a4bab","ProcedureCode989abc27e0c6"} /\ declaration=site.activeRequirement [] OTHER -> FALSE /\ declaration.form \in {"Requirement","Choice"} /\ DOMAIN declaration.options#{} /\ declaration.form="Choice" => Cardinality(DOMAIN declaration.options)>=2 /\ declaration.means \in STRING /\ declaration.goal \in STRING /\ \A option \in DOMAIN declaration.options : /\ declaration.options[option].id=option /\ declaration.options[option].means \in STRING /\ declaration.options[option].additionalCosts \subseteq STRING /\ declaration.form="Requirement" => declaration.options[option].goal=declaration.goal MustFeasibilityBound912(declaration,site,world,feasibility) == /\ feasibility.tag="CompleteMustFeasibility" /\ feasibility.declaration=declaration /\ feasibility.site=site /\ feasibility.snapshot=world /\ feasibility.actor=declaration.actor /\ DOMAIN feasibility.options=DOMAIN declaration.options /\ \A option \in DOMAIN feasibility.options : LET row == feasibility.options[option] IN /\ row.tag="CurrentMustOptionProfile" /\ row.option=declaration.options[option] /\ row.source=declaration.source /\ row.actor=declaration.actor /\ row.site=site /\ row.snapshot=world /\ row.targetSpecification=row.option.targetSpecification /\ row.paymentSpecification=row.option.paymentSpecification /\ row.ordinary.tag="OrdinaryOptionLegality" /\ row.ordinary.option=row.option /\ row.ordinary.site=site /\ row.ordinary.snapshot=world /\ row.ordinary.source=declaration.source /\ row.ordinary.actor=declaration.actor /\ row.ordinary.failures \subseteq {"Prohibited","Inactive","WrongTiming","OnceUsed","OneShotUsed","MissingReferent","UnavailableAbility"} /\ \A targets \in row.targetAlternatives : targets \subseteq DOMAIN world.objects /\ \A plan \in row.paymentAlternatives : DOMAIN plan \subseteq DOMAIN world.resources /\ \A resource \in DOMAIN plan : plan[resource] \in Nat MustFullyResolvable912(declaration,world,feasibility) == {option \in DOMAIN declaration.options : (declaration.form="Choice" \/ declaration.means="SchemaAtom016" \/ declaration.options[option].means=declaration.means) /\ feasibility.options[option].ordinary.failures={} /\ feasibility.options[option].targetAlternatives#{} /\ \E plan \in feasibility.options[option].paymentAlternatives : MustResourcePlanAffordable912(plan,world)} NewMustDecision912(id,declaration,site) == [id |-> id,declaration |-> declaration,site |-> site,phase |-> "Choosing",chosen |-> "NoValue",disposition |-> "NoValue", choiceSnapshot |-> 0,feasibleAtChoice |-> {},decision |-> [key \in {} |-> key],result |-> [key \in {} |-> key]] MustAdditionalDeclineBound912(declaration,site,world,feasibility,decision) == /\ declaration.form="Requirement" /\ decision.option \in DOMAIN declaration.options /\ declaration.means="SchemaAtom016" \/ declaration.options[decision.option].means=declaration.means /\ feasibility.options[decision.option].ordinary.failures={} /\ feasibility.options[decision.option].targetAlternatives#{} /\ decision.decline.tag="ActualAdditionalCostDecline" /\ decision.decline.declaration=declaration /\ decision.decline.site=site /\ decision.decline.snapshot=world /\ decision.decline.actor=declaration.actor /\ decision.decline.option=declaration.options[decision.option] /\ decision.decline.costs#{} /\ decision.decline.costs \subseteq declaration.options[decision.option].additionalCosts DecideMust912(before,after,world,feasibility,decision,cardFacts) == /\ before.id \in Nat \ {0} /\ before.phase="Choosing" /\ MustSourceBound912(before.declaration,before.site,world,cardFacts) /\ MustFeasibilityBound912(before.declaration,before.site,world,feasibility) /\ decision.tag="MustDecision" /\ decision.id \in Nat \ {0} /\ decision.requirement=before.id /\ decision.site=before.site /\ decision.snapshot=world /\ decision.actor=before.declaration.actor /\ decision.kind \in {"Choose","NoEffect","DeclineAdditional"} /\ LET feasible == MustFullyResolvable912(before.declaration,world,feasibility) IN /\ CASE decision.kind="Choose" -> decision.option \in feasible [] decision.kind="NoEffect" -> feasible={} /\ decision.option="NoValue" [] OTHER -> MustAdditionalDeclineBound912(before.declaration,before.site,world,feasibility,decision) /\ after=[before EXCEPT !.phase="Committed",!.chosen=IF decision.kind="Choose" THEN decision.option ELSE "NoValue", !.disposition=decision.kind,!.choiceSnapshot=world.id,!.feasibleAtChoice=feasible,!.decision=decision] MustChoiceCaller912(committed) == committed.site.checkpointCaller EnterChosenMust912(before,after,ledger,stack,checkpoint,entry) == /\ before.phase="Committed" /\ before.disposition="Choose" /\ before.declaration.form="Choice" /\ checkpoint.tag="MustChoiceCheckpoint" /\ checkpoint.id \in DOMAIN ledger.checkpoints /\ checkpoint.requirement=before.id /\ checkpoint.decision=before.decision.id /\ checkpoint.complete /\ checkpoint.allNewerChainsComplete /\ ledger.checkpoints[checkpoint.id].caller=MustChoiceCaller912(before) /\ ConditionalCheckpointDrained96(ledger,stack,checkpoint.id) /\ entry.tag="ActualChosenMustEffectEntry" /\ entry.requirement=before.id /\ entry.decision=before.decision /\ entry.option=before.declaration.options[before.chosen] /\ entry.actor=before.declaration.actor /\ entry.source=before.declaration.source /\ entry.checkpointId=checkpoint.id /\ entry.instruction.source=before.declaration.source /\ entry.instruction.abilityInstance=before.site.ability.id /\ entry.instruction#InstructionWindowRef93(before.site.plan) /\ after=[before EXCEPT !.phase="Resolving",!.result=[entry |-> entry]] CompleteChosenMust912(before,after,actualReturn,completion) == /\ before.phase="Resolving" /\ before.chosen \in DOMAIN before.declaration.options /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ WouldContextKey99(actualReturn.instruction)=WouldContextKey99(before.result.entry.instruction) /\ actualReturn.instruction.revision>=before.result.entry.instruction.revision /\ actualReturn.complete /\ actualReturn.childrenReturned /\ completion.tag="MustChosenEffectReturn" /\ completion.requirement=before.id /\ completion.decision=before.decision /\ completion.entry=before.result.entry /\ completion.actualReturn=actualReturn /\ completion.originalAdditionalDeclines \subseteq before.declaration.options[before.chosen].additionalCosts /\ before.declaration.form="Choice" => completion.originalAdditionalDeclines={} /\ after=[before EXCEPT !.phase="Complete",!.result=completion] NewPersistentRegistry912(base) == ReplacementOverlay99(base, [persistent |-> [key \in {} |-> key],persistentRetireIds |-> {}]) PersistentKnownIds912(registry) == {registry.persistent[key].definition.syntax.id : key \in DOMAIN registry.persistent} PersistentLiveKeys912(registry) == {key \in DOMAIN registry.persistent : registry.persistent[key].phase="Persisting" /\ registry.persistent[key].effectId \in DOMAIN registry.effects /\ registry.effects[registry.persistent[key].effectId].status="Active"} PersistentLiveIds912(registry) == {registry.persistent[key].definition.syntax.id : key \in PersistentLiveKeys912(registry)} PersistentOrigin912(id,d,lex,trash,world) == [tag |-> "PersistentAbilityMaintenance",effectId |-> id,key |-> AbilityKey99(d),definition |-> d,lexemes |-> lex, sourceCard |-> world.objects[trash.source].card,sourceCardSHA |-> world.cardFacts[world.objects[trash.source].card].sourceSHA, sourceZone |-> world.objects[trash.source].zone,sourceTargetSite |-> world.objects[trash.source].targetSite, successor |-> trash.successor,trashId |-> trash.id,itemInspectionId |-> trash.itemInspection.id,traversalId |-> trash.itemInspection.traversalId] PersistentRowOrigin912(key,row) == [tag |-> "PersistentAbilityMaintenance",effectId |-> row.effectId,key |-> key,definition |-> row.definition,lexemes |-> row.lexemes, sourceCard |-> row.sourceCard,sourceCardSHA |-> row.sourceCardSHA,sourceZone |-> row.sourceZone,sourceTargetSite |-> row.sourceTargetSite, successor |-> row.successor,trashId |-> row.trashId,itemInspectionId |-> row.itemInspectionId,traversalId |-> row.traversalId] PersistentHasExposureMarkersIds912(rows) == {id \in DOMAIN rows : "persistence" \in DOMAIN rows[id]} PersistentRegistryBound912(registry) == /\ Cardinality({registry.persistent[key].effectId : key \in DOMAIN registry.persistent})=Cardinality(DOMAIN registry.persistent) /\ PersistentHasExposureMarkersIds912(registry.effects)={registry.persistent[key].effectId : key \in {key \in DOMAIN registry.persistent : registry.persistent[key].effectId \in DOMAIN registry.effects}} /\ \A key \in DOMAIN registry.persistent : LET row == registry.persistent[key] IN /\ key=AbilityKey99(row.definition) /\ FlagPresent93(row.definition.syntax.units,"Persistent") /\ row.effectId \in registry.usedEffects /\ row.trashId \in registry.persistentRetireIds /\ row.phase \in {"Persisting","Expired"} /\ (row.phase="Expired" => ~row.creationOpen) /\ IF row.effectId \notin DOMAIN registry.effects THEN row.phase="Expired" ELSE LET effect == registry.effects[row.effectId] IN /\ effect.persistence=PersistentRowOrigin912(key,row) /\ effect.id=row.effectId /\ effect.source=row.definition.syntax.source /\ effect.definitionId=row.definition.syntax.id /\ effect.kind="Ordinary" /\ effect.originKind="Rule" /\ effect.value="MaintainOriginalAbility" /\ effect.creation= <<"PersistentItemInspectionRetire",row.trashId,key>> /\ effect.baseDuration=[kind |-> "Stated",specification |-> [kind |-> "PersistentOriginalTraversalEndReaction",ability |-> key, traversalId |-> row.traversalId,trash |-> row.trashId,itemInspection |-> row.itemInspectionId]] /\ effect.status=IF row.phase="Persisting" THEN "Active" ELSE "Expired" PersistentRegistryWorldBound912(registry,world) == /\ PersistentRegistryBound912(registry) /\ world.activity.persistentAbilities=PersistentLiveIds912(registry) /\ world.present \cap PersistentKnownIds912(registry)=PersistentLiveIds912(registry) /\ PersistentHasExposureMarkersIds912(world.statedDurations)={registry.persistent[key].effectId : key \in DOMAIN registry.persistent} /\ \A key \in DOMAIN registry.persistent : LET row == registry.persistent[key] observation == world.statedDurations[row.effectId] IN /\ observation.persistence=PersistentRowOrigin912(key,row) /\ observation.active=(row.phase="Persisting") PersistentEffect912(id,d,lex,trash,traversalId,world) == [id |-> id,kind |-> "Ordinary",source |-> d.syntax.source,creation |-> <<"PersistentItemInspectionRetire",trash.id,AbilityKey99(d)>>, creationTurn |-> world.turn.id,originKind |-> "Rule",target |-> trash.source,value |-> "MaintainOriginalAbility", baseDuration |-> [kind |-> "Stated",specification |-> [kind |-> "PersistentOriginalTraversalEndReaction",ability |-> AbilityKey99(d), traversalId |-> traversalId,trash |-> trash.id,itemInspection |-> trash.itemInspection.id]],durationClass |-> "Stated",choicePolicy |-> "NoValue",choiceKey |-> "NoValue", lingeringConsumers |-> {},otherConsumers |-> {},definitionId |-> d.syntax.id,persistence |-> PersistentOrigin912(id,d,lex,trash,world), status |-> IF traversalId=0 THEN "Expired" ELSE "Active"] PersistentRecord912(d,lex,id,trash,world) == [definition |-> d,lexemes |-> lex,effectId |-> id,sourceCard |-> world.objects[trash.source].card, sourceCardSHA |-> world.cardFacts[world.objects[trash.source].card].sourceSHA,sourceZone |-> world.objects[trash.source].zone, sourceTargetSite |-> world.objects[trash.source].targetSite,successor |-> trash.successor,trashId |-> trash.id,itemInspectionId |-> trash.itemInspection.id, traversalId |-> trash.itemInspection.traversalId,phase |-> IF trash.itemInspection.traversalId=0 THEN "Expired" ELSE "Persisting", creationOpen |-> trash.itemInspection.traversalId#0,endCheckpoint |-> 0,endWindow |-> 0,endMembers |-> {}] PersistentWorld912(base,registry) == LET ids == {registry.persistent[key].effectId : key \in DOMAIN registry.persistent} IN [base EXCEPT !.present=(@ \ PersistentKnownIds912(registry)) \cup PersistentLiveIds912(registry), !.activity.persistentAbilities=(@ \ PersistentKnownIds912(registry)) \cup PersistentLiveIds912(registry), !.statedDurations=ReplacementOverlay99(@,[id \in ids |-> LET key == CHOOSE key \in DOMAIN registry.persistent : registry.persistent[key].effectId=id IN IF id \in DOMAIN registry.effects THEN [receipt |-> StatedDurationReceipt910(registry.effects[id],base),active |-> registry.persistent[key].phase="Persisting", persistence |-> PersistentRowOrigin912(key,registry.persistent[key])] ELSE [active |-> FALSE,persistence |-> PersistentRowOrigin912(key,registry.persistent[key])]] )] PersistentSourceActive912(d,world) == FlagActivity93(d.syntax,world.present,AbilityActive9(d.activity,world.objects,world.present, LingeringObjectActive910(d.syntax.source,world),world.activity),world.activity.persistentAbilities,world.points) PersistentInventory912(inventory,trash,world,cardFacts) == /\ inventory.tag="AuthoritativeSourceAbilityInventory" /\ inventory.worldId=world.id /\ inventory.source=ObjectAbilitySource9(trash.source) /\ inventory.card=world.objects[trash.source].card /\ inventory.sourceSHA=cardFacts[inventory.card].sourceSHA /\ DOMAIN inventory.lexemes=DOMAIN inventory.definitions /\ \A key \in DOMAIN inventory.definitions : LET d == inventory.definitions[key] IN /\ key=AbilityKey99(d) /\ d.syntax.source=inventory.source /\ d.activity.source=inventory.source /\ d.activity.provider \in {"Printed","Granted"} /\ AbilityTextValid93(d.syntax) /\ AbilityLexemesValid99(d,inventory.lexemes[key],world.objects,cardFacts) PersistentBirthCohort912(inventory,world) == {key \in DOMAIN inventory.definitions : FlagPresent93(inventory.definitions[key].syntax.units,"Persistent") /\ inventory.definitions[key].syntax.side="SideA" /\ inventory.definitions[key].syntax.id \in world.present} PersistentRetireBound912(trash,inventory,beforeWorld,afterObjects,usedObjects,cardFacts) == /\ trash.tag="ActualSideBItemInspectionRetire" /\ trash.id \in Nat \ {0} /\ trash.actor="SideB" /\ trash.source \in DOMAIN beforeWorld.objects /\ beforeWorld.objects[trash.source].side="SideA" /\ ActivationStatus8(beforeWorld.objects[trash.source])="ItemActivated" /\ trash.itemInspection.id \in DOMAIN beforeWorld.itemInspections /\ beforeWorld.itemInspections[trash.itemInspection.id]=trash.itemInspection /\ trash.itemInspection.object=trash.source /\ StillItemInspectioning7(trash.itemInspection,beforeWorld.objects) /\ trash.itemInspection.traversalId=0 \/ (trash.itemInspection.traversalId=beforeWorld.control.traversal.id /\ TraversalTimingPresent6(beforeWorld.control.traversal)) /\ PersistentInventory912(inventory,trash,beforeWorld,cardFacts) /\ CardBatchTransfer8(beforeWorld.objects,afterObjects,{trash.source},[id \in {trash.source} |-> trash.successor],usedObjects, "SideADiscard","Up",[id \in {trash.source} |-> "SideADiscard"]) /\ trash.movement.tag="CardMovement" /\ trash.movement.kind="Retire" /\ trash.movement.sources={trash.source} /\ trash.movement.successors=[id \in {trash.source} |-> trash.successor] /\ trash.movement.id=trash.id /\ trash.movement.disposition="Complete" /\ RecordMovement8(trash.historyBefore,trash.historyAfter,trash.id,"Retire",{trash.source},"Complete",TRUE,trash.events) PersistentDefinitionProfile912(registry,d) == LET owners == {key \in DOMAIN registry.persistent : registry.persistent[key].definition.syntax.id=d.syntax.id} IN owners={} \/ (owners={AbilityKey99(d)} /\ registry.persistent[AbilityKey99(d)].definition=d) PersistentDefinitionsProfile912(registry,definitions) == \A key \in DOMAIN definitions : PersistentDefinitionProfile912(registry,definitions[key]) PersistentConditionalDefinitions912(registry,definitions) == /\ PersistentDefinitionsProfile912(registry,definitions) /\ \A key \in PersistentLiveKeys912(registry) : registry.persistent[key].definition.syntax.kind="Conditional" => /\ key \in DOMAIN definitions /\ definitions[key]=registry.persistent[key].definition PersistentPaidDefinitions912(registry,definitions) == /\ PersistentDefinitionsProfile912(registry,definitions) /\ \A key \in PersistentLiveKeys912(registry) : registry.persistent[key].definition.syntax.kind="Paid" => /\ key \in DOMAIN definitions /\ definitions[key]=registry.persistent[key].definition PersistentCapturedLexemes912(registry,definitions,lexemes) == \A key \in PersistentLiveKeys912(registry) \cap DOMAIN definitions : registry.persistent[key].definition.syntax.kind \in {"Conditional","Paid"} => /\ key \in DOMAIN lexemes /\ lexemes[key]=registry.persistent[key].lexemes PersistentStaticDefinitions912(registry) == [key \in {k \in PersistentLiveKeys912(registry) : registry.persistent[k].definition.syntax.kind="Static"} |-> registry.persistent[key].definition] PersistentApplicationAllowed912(registry,d,traversalId) == /\ PersistentDefinitionProfile912(registry,d) /\ LET key == AbilityKey99(d) IN IF key \notin DOMAIN registry.persistent THEN TRUE ELSE LET row == registry.persistent[key] IN row.definition=d /\ key \in PersistentLiveKeys912(registry) /\ row.traversalId#0 /\ traversalId=row.traversalId PersistentGenerationAllowed912(registry,d,traversalId) == /\ PersistentApplicationAllowed912(registry,d,traversalId) /\ AbilityKey99(d) \notin DOMAIN registry.persistent \/ registry.persistent[AbilityKey99(d)].creationOpen PersistentCandidateAllowed912(registry,d,cp,eventId,scope) == IF eventId=0 THEN PersistentGenerationAllowed912(registry,d,scope.traversalId) ELSE PersistentGenerationAllowed912(registry,d,cp.occurrences[eventId].traversal.id) PersistentCheckpointCandidates912(registry,definitions,lexemes,ledger,cp,conditions,scope) == {candidate \in CheckpointCandidates99(definitions,lexemes,ledger,cp,conditions) : PersistentCandidateAllowed912(registry,definitions[candidate.definition],cp,candidate.occurrence,scope)} PersistentInstanceRows912(rows,ledger) == [id \in DOMAIN rows \cup DOMAIN ledger.instances |-> IF id \in DOMAIN ledger.instances THEN ReplacementOverlay99(IF id \in DOMAIN rows THEN rows[id] ELSE [field \in {} |-> field], [ability |-> ledger.instances[id].member.ability,sourceObject |-> ledger.instances[id].member.source.object,status |-> ledger.instances[id].status]) ELSE rows[id]] CreatePersistentOnRetire912(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot, inventory,trash,effectIds,usedObjects,beforeAuthority,afterAuthority,cardFacts) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ PersistentRegistryWorldBound912(beforeRegistry,beforeAuthority.current) /\ trash.id \notin beforeRegistry.persistentRetireIds /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=afterAuthority.current.id /\ beforeSnapshot.objects=beforeAuthority.current.objects /\ afterSnapshot.objects=afterAuthority.current.objects /\ PersistentRetireBound912(trash,inventory,beforeAuthority.current,afterAuthority.current.objects,usedObjects,cardFacts) /\ usedObjects=beforeSnapshot.usedObjects /\ afterSnapshot.usedObjects=usedObjects \cup {trash.successor} /\ afterSnapshot.definitions=beforeSnapshot.definitions /\ PersistentConditionalDefinitions912(beforeRegistry,beforeSnapshot.definitions) /\ PersistentConditionalDefinitions912(afterRegistry,afterSnapshot.definitions) /\ LET world == beforeAuthority.current next == afterAuthority.current cohort == PersistentBirthCohort912(inventory,world) sourceIds == {inventory.definitions[key].syntax.id : key \in DOMAIN inventory.definitions} records == [key \in cohort |-> PersistentRecord912(inventory.definitions[key],inventory.lexemes[key],effectIds[key],trash,world)] effects == [id \in {effectIds[key] : key \in cohort} |-> LET key == CHOOSE key \in cohort : effectIds[key]=id IN PersistentEffect912(id,inventory.definitions[key],inventory.lexemes[key],trash,trash.itemInspection.traversalId,world)] created == [beforeRegistry EXCEPT !.persistent=ReplacementOverlay99(@,records),!.effects=ReplacementOverlay99(@,effects), !.usedEffects=@ \cup DOMAIN effects,!.creations=@ \cup {effects[id].creation : id \in DOMAIN effects},!.persistentRetireIds=@ \cup {trash.id}] base == [world EXCEPT !.id=next.id,!.objects=next.objects,!.present=@ \ sourceIds, !.activity.instances=PersistentInstanceRows912(world.activity.instances,afterLedger)] execution == [tag |-> "ActualObjectTransition",id |-> trash.id,snapshotId |-> next.id,source |-> RuleAbilitySource9("ProcedureCode17f2a65162fb"),trash |-> trash] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ cohort#{} /\ DOMAIN effectIds=cohort /\ cohort \cap DOMAIN beforeRegistry.persistent={} /\ {inventory.definitions[key].syntax.id : key \in cohort} \cap PersistentKnownIds912(beforeRegistry)={} /\ Cardinality({inventory.definitions[key].syntax.id : key \in cohort})=Cardinality(cohort) /\ {effectIds[key] : key \in cohort} \subseteq (Nat \ {0}) \ beforeRegistry.usedEffects /\ Cardinality({effectIds[key] : key \in cohort})=Cardinality(cohort) /\ next=PersistentWorld912(base,created) /\ CommitLifetimeKernelCore910(beforeAuthority,afterAuthority,next,execution) /\ ObserveLingering910(created,local,next) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ PersistentRegistryWorldBound912(afterRegistry,afterAuthority.current) /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,world) /\ LingeringConditionalWorld910(afterSnapshot,beforeLedger,next) /\ \A key \in cohort : inventory.definitions[key].syntax.kind="Conditional" => key \in DOMAIN beforeSnapshot.definitions /\ beforeSnapshot.definitions[key]=inventory.definitions[key] /\ ~afterSnapshot.ordinaryActivity[key] /\ ObserveConditionalActivity96(beforeLedger,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) PersistentTraversalEndCaller912(traversalId) == [kind |-> "TraversalStep",structure |-> TimingRef9("SchemaAtom138",traversalId),step |-> "ProcedureCode9606a4cd52b4"] PersistentCheckpointBound912(registry,ledger) == \A key \in PersistentLiveKeys912(registry) : LET row == registry.persistent[key] seen == {id \in DOMAIN ledger.checkpoints : ledger.checkpoints[id].caller=PersistentTraversalEndCaller912(row.traversalId)} IN IF seen={} THEN row.creationOpen /\ row.endCheckpoint=0 /\ row.endWindow=0 /\ row.endMembers={} ELSE /\ ~row.creationOpen /\ row.endCheckpoint \in seen /\ row.endMembers \subseteq {id \in DOMAIN ledger.instances : ledger.instances[id].checkpointId=row.endCheckpoint} /\ {id \in DOMAIN ledger.instances : ledger.instances[id].checkpointId=row.endCheckpoint /\ ledger.instances[id].status="Pending"} \subseteq row.endMembers /\ IF row.endMembers={} THEN row.endWindow=0 ELSE row.endWindow \in Nat \ {0} /\ \A id \in row.endMembers : ledger.instances[id].member.windowId=row.endWindow ProcessPersistentCheckpointCore912(registry,before,after,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,scope,cardFacts) == LET stable == ConditionalActivityLedger96(before,definitions,cp.processingSnapshot) ordinary == PersistentCheckpointCandidates912(registry,definitions,lexemes,stable,cp,conditions,scope) departing == {candidate \in DepartureCandidates99(definitions,lexemes,cp,conditions,departures) : PersistentCandidateAllowed912(registry,definitions[candidate.definition],cp,candidate.occurrence,scope)} candidates == ordinary \cup departing departureKeys == {key.definition : key \in departing} ids == {allocation[key] : key \in candidates} IN /\ PersistentConditionalDefinitions912(registry,definitions) /\ PersistentCapturedLexemes912(registry,definitions,lexemes) /\ scope.tag="PersistentCheckpointTraversalScope" /\ scope.checkpointId=cp.id /\ scope.caller=cp.caller /\ ConditionalLexemesBound99(definitions,lexemes,cp.processingSnapshot,cardFacts) /\ definitions=cp.processingSnapshot.definitions /\ ConditionalDefinitionsStable96(before.lastSnapshot,cp.processingSnapshot) /\ \A key \in DOMAIN definitions : key=ConditionalKey96(definitions[key]) /\ ConditionalDefinitionValid96(definitions[key]) /\ ConditionalSnapshotBound96(cp.processingSnapshot,before) /\ CheckpointBatchValid96(before,cp,candidates,allocation,bindings) /\ DOMAIN holds=departureKeys /\ \A key \in departureKeys : DepartureAuthority96(definitions[key],cp,conditions[key],allocation,departures[key],holds[key]) /\ after=[stable EXCEPT !.activationEpoch=cp.processingSnapshot.activationEpoch, !.holds=[key \in DOMAIN @ \cup departureKeys |-> IF key \in departureKeys THEN holds[key] ELSE @[key]], !.lastCheckpoint=cp.id,!.checkpointIds=@ \cup {cp.id},!.checkpoints=ReplacementOverlay99(@,[id \in {cp.id} |-> [caller |-> cp.caller]]), !.serial=cp.serial,!.lastSnapshot=cp.processingSnapshot,!.processed=@ \cup DOMAIN cp.occurrences, !.instances=ReplacementOverlay99(@,[id \in ids |-> LET key == CHOOSE k \in candidates : allocation[k]=id IN NewConditionalInstance96(id,definitions[key.definition],cp,key.occurrence,bindings[key].windowId,bindings[key].group)])] /\ \A key \in departureKeys : ConditionalActive96(definitions[key],SnapshotWithConditionalRegistry96(cp.processingSnapshot,after)) ProcessPersistentCheckpoint912(registry,before,after,beforeStack,afterStack,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,scope,usedWindows,cardFacts,world,authority) == /\ LifetimeReady910(registry,authority) /\ PersistentRegistryWorldBound912(registry,authority.current) /\ world=authority.current /\ PersistentCheckpointBound912(registry,before) /\ cp.processingSnapshot.id=world.id /\ LingeringConditionalWorld910(cp.processingSnapshot,before,world) /\ scope.traversalId=world.control.traversal.id /\ ProcessPersistentCheckpointCore912(registry,before,after,definitions,lexemes,cp,conditions,allocation,bindings,departures,holds,scope,cardFacts) /\ \A key \in DOMAIN bindings : bindings[key].windowId \notin usedWindows \cup {beforeStack[i].id : i \in 1..Len(beforeStack)} /\ SyncConditionalWindows96(beforeStack,afterStack,before,after) PersistentRecognizedIds912(ledger,cpId) == {id \in DOMAIN ledger.instances : ledger.instances[id].checkpointId=cpId} PersistentCheckpointCompletion912(ledger,cp,world) == [tag |-> "NormalCheckpointCompletion",checkpointId |-> cp.id,caller |-> cp.caller,snapshotId |-> world.id,point |-> "ProcedureCodeb74d673a0fc6", recognizedInstances |-> PersistentRecognizedIds912(ledger,cp.id), members |-> [id \in PersistentRecognizedIds912(ledger,cp.id) |-> ledger.instances[id].member]] PersistentGeneratedIds912(ledger,cpId) == {id \in DOMAIN ledger.instances : ledger.instances[id].checkpointId=cpId /\ ledger.instances[id].status="Pending"} PersistentGeneratedWindow912(ledger,cpId) == LET ids == PersistentGeneratedIds912(ledger,cpId) IN IF ids={} THEN 0 ELSE ledger.instances[CHOOSE id \in ids : TRUE].member.windowId CutoffPersistentAtTraversalEnd912(before,after,ledger,cp,beforeEnd,afterEnd,events,expired,boundary) == /\ CompleteTraversal6(beforeEnd,afterEnd,TRUE,events,expired) /\ PersistentRegistryWorldBound912(before,before.frontier.world) /\ before.frontier.world.control.traversal=afterEnd.traversal /\ cp.processingSnapshot.id=before.frontier.world.id /\ cp.id=ledger.lastCheckpoint /\ cp.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[cp.id].caller=cp.caller /\ ledger.lastSnapshot=cp.processingSnapshot /\ cp.caller=PersistentTraversalEndCaller912(afterEnd.traversal.id) /\ \E id \in DOMAIN cp.occurrences : /\ cp.occurrences[id].kind="TraversalEnds" /\ cp.occurrences[id].traversal=afterEnd.traversal /\ cp.occurrences[id].actualEvent \in events /\ cp.occurrences[id].actualEvent=[tag |-> "TraversalEnds",traversalId |-> afterEnd.traversal.id] /\ PersistentRecognizedIds912(ledger,cp.id)=PersistentGeneratedIds912(ledger,cp.id) /\ boundary=[tag |-> "PersistentLastCreationCheckpoint",traversal |-> afterEnd.traversal,checkpointId |-> cp.id,caller |-> cp.caller, windowId |-> PersistentGeneratedWindow912(ledger,cp.id),completion |-> PersistentCheckpointCompletion912(ledger,cp,before.frontier.world)] /\ LET keys == {key \in DOMAIN before.persistent : before.persistent[key].phase="Persisting" /\ before.persistent[key].traversalId=afterEnd.traversal.id} IN /\ keys#{} /\ \A key \in keys : before.persistent[key].creationOpen /\ after=[before EXCEPT !.persistent=[key \in DOMAIN @ |-> IF key \in keys THEN [@[key] EXCEPT !.creationOpen=FALSE,!.endCheckpoint=cp.id,!.endWindow=boundary.windowId,!.endMembers=PersistentGeneratedIds912(ledger,cp.id)] ELSE @[key]]] /\ PersistentRegistryWorldBound912(after,after.frontier.world) /\ PersistentCheckpointBound912(after,ledger) PersistentEndWindows912(registry,windowId) == {key \in DOMAIN registry.persistent : registry.persistent[key].phase="Persisting" /\ ~registry.persistent[key].creationOpen /\ registry.persistent[key].endCheckpoint#0 /\ registry.persistent[key].endWindow=windowId} ObservePersistentKernel912(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot, baseWorld,execution,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ PersistentRegistryWorldBound912(beforeRegistry,beforeAuthority.current) /\ PersistentCheckpointBound912(beforeRegistry,beforeLedger) /\ PersistentConditionalDefinitions912(beforeRegistry,beforeSnapshot.definitions) /\ afterAuthority.current=PersistentWorld912(baseWorld,beforeRegistry) /\ CommitLifetimeKernelCore910(beforeAuthority,afterAuthority,afterAuthority.current,execution) /\ LET local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ ObserveLingering910(beforeRegistry,local,afterAuthority.current) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ PersistentRegistryWorldBound912(afterRegistry,afterAuthority.current) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=afterAuthority.current.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,beforeLedger,afterAuthority.current) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,beforeLedger,afterAuthority.current) /\ PersistentConditionalDefinitions912(local,afterSnapshot.definitions) /\ ObserveConditionalActivity96(beforeLedger,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) PersistentExpirationRegistry912(registry,keys) == [registry EXCEPT !.persistent=[key \in DOMAIN @ |-> IF key \in keys THEN [@[key] EXCEPT !.phase="Expired",!.creationOpen=FALSE] ELSE @[key]]] PublishPersistentExpiration912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,candidateStack,afterStack,beforeSnapshot,afterSnapshot, keys,execution,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ PersistentRegistryWorldBound912(beforeRegistry,beforeAuthority.current) /\ keys \subseteq PersistentLiveKeys912(beforeRegistry) /\ PersistentConditionalDefinitions912(beforeRegistry,beforeSnapshot.definitions) /\ LET changed == PersistentExpirationRegistry912(beforeRegistry,keys) next == afterAuthority.current base == [beforeAuthority.current EXCEPT !.id=next.id,!.activity.instances=PersistentInstanceRows912(@,afterLedger)] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ next=PersistentWorld912(base,changed) /\ CommitLifetimeKernelCore910(beforeAuthority,afterAuthority,next,execution) /\ ObserveLingering910(changed,local,next) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ PersistentRegistryWorldBound912(afterRegistry,afterAuthority.current) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=next.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,candidateLedger,next) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,candidateLedger,next) /\ PersistentConditionalDefinitions912(local,afterSnapshot.definitions) /\ ObserveConditionalActivity96(beforeLedger,candidateLedger,afterLedger,candidateStack,afterStack,beforeSnapshot,afterSnapshot) PassPersistentPriority912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,candidateStack,afterStack, player,currentEffect,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ PassConditionalPriorityCore96(beforeLedger,candidateLedger,beforeStack,candidateStack,player,currentEffect) /\ LET w == WindowTop9(beforeStack) closed == WindowTop9(candidateStack) keys == IF w.kind="Reaction" /\ w.open /\ ~closed.open THEN PersistentEndWindows912(beforeRegistry,w.id) ELSE {} execution == [tag |-> "CurrentCharacteristicsEvaluation",id |-> w.id,snapshotId |-> afterAuthority.current.id, source |-> RuleAbilitySource9("ProcedureCode17f2a65162fb"),closedWindow |-> IF closed.open THEN 0 ELSE closed.id] IN /\ \A key \in keys : /\ w.site.traversalId=beforeRegistry.persistent[key].traversalId /\ DOMAIN w.members=beforeRegistry.persistent[key].endMembers /\ \A id \in DOMAIN w.members : w.members[id]=beforeLedger.instances[id].member /\ PublishPersistentExpiration912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,candidateStack,afterStack, beforeSnapshot,afterSnapshot,keys,execution,beforeAuthority,afterAuthority) ExpirePersistentNoReaction912(beforeRegistry,afterRegistry,beforeLedger,afterLedger,stack,afterStack,beforeSnapshot,afterSnapshot, cp,clearance,beforeAuthority,afterAuthority) == /\ cp.id=beforeLedger.lastCheckpoint /\ cp.id \in DOMAIN beforeLedger.checkpoints /\ beforeLedger.checkpoints[cp.id].caller=cp.caller /\ PersistentRecognizedIds912(beforeLedger,cp.id)={} /\ \A i \in 1..Len(stack) : stack[i].id \notin {beforeLedger.instances[id].member.windowId : id \in {id \in DOMAIN beforeLedger.instances : beforeLedger.instances[id].checkpointId=cp.id}} /\ clearance=[tag |-> "NormalCheckpointNoReactionWindow",checkpointId |-> cp.id,caller |-> cp.caller, pendingInstances |-> {},point |-> "ProcedureCodeb74d673a0fc6"] /\ LET keys == {key \in PersistentEndWindows912(beforeRegistry,0) : beforeRegistry.persistent[key].endCheckpoint=cp.id} execution == [tag |-> "CurrentCharacteristicsEvaluation",id |-> cp.id,snapshotId |-> afterAuthority.current.id, source |-> RuleAbilitySource9("ProcedureCode17f2a65162fb"),noWindow |-> clearance] IN /\ keys#{} /\ PublishPersistentExpiration912(beforeRegistry,afterRegistry,beforeLedger,beforeLedger,afterLedger,stack,afterStack, beforeSnapshot,afterSnapshot,keys,execution,beforeAuthority,afterAuthority) PersistentStaticPart912(registry,d,part,conditions,world,application,ledger,authority) == /\ LifetimeReady910(registry,authority) /\ PersistentRegistryWorldBound912(registry,authority.current) /\ world=authority.current /\ application.tag="CurrentStaticApplication" /\ application.worldId=world.id /\ application.traversalId=world.control.traversal.id /\ PersistentApplicationAllowed912(registry,d,application.traversalId) /\ StaticPartApplies94(d.syntax,part,PersistentSourceActive912(d,world),conditions) PersistentPaidContext912(c,ledger,world) == /\ c.points=world.points /\ c.present \ DelayedConditionalAbilityIds96(ledger.effects)=world.present \ DelayedConditionalAbilityIds96(ledger.effects) /\ c.activity=world.activity \/ c.activity=[world.activity EXCEPT !.instances=ConditionalActivityRows96(ledger.instances)] ReservePersistentPaid912(registry,before,after,p,id,d,lex,c,option,legality,usedInstances,cardFacts,ledger,authority) == /\ LifetimeReady910(registry,authority) /\ PersistentRegistryWorldBound912(registry,authority.current) /\ PersistentCheckpointBound912(registry,ledger) /\ c.objects=authority.current.objects /\ c.turn=authority.current.turn /\ c.traversalControl=authority.current.control /\ PersistentPaidContext912(c,ledger,authority.current) /\ PersistentCapturedLexemes912(registry,[key \in {AbilityKey99(d)} |-> d],[key \in {AbilityKey99(d)} |-> lex]) /\ Len(before)>0 /\ PersistentGenerationAllowed912(registry,d,WindowTop9(before).site.traversalId) /\ id \in (Nat \ {0}) \ usedInstances /\ PaidEligibility99(d,lex,c,WindowTop9(before),cardFacts) /\ PaidOptionMatches95(d,option,WindowTop9(before)) /\ BeginPriorityOption9(before,after,option,c.objects,legality,c.currentEffect) /\ p=OpenPaidProcedure95(id,d,option,WindowTop9(before),legality.transactionId, IF AbilityKey99(d) \in DOMAIN registry.persistent THEN registry.persistent[AbilityKey99(d)].sourceZone ELSE IF d.syntax.source.kind="Object" THEN c.objects[d.syntax.source.object].zone ELSE "Rule") PersistentInterruptWorld912(registry,world,ledger,authority) == /\ LifetimeReady910(registry,authority) /\ PersistentRegistryWorldBound912(registry,authority.current) /\ PersistentCheckpointBound912(registry,ledger) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ world.conditional.id=world.id /\ ConditionalSnapshotBound96(world.conditional,ledger) /\ LingeringConditionalWorld910(world.conditional,ledger,authority.current) /\ PersistentConditionalDefinitions912(registry,world.conditional.definitions) /\ PersistentPaidDefinitions912(registry,world.paidDefinitions) /\ PersistentCapturedLexemes912(registry,CurrentInterruptDefinitions99(world),world.lexemes) PersistentOpeningPaidRelevant912(registry,context,world,history,w) == {key \in OpeningPaidRelevant99(context,world,history,w) : PersistentGenerationAllowed912(registry,world.paidDefinitions[key],world.traversalControl.traversal.id)} PersistentCurrentPaidRelevant912(registry,context,world,history,w) == {key \in CurrentPaidRelevant99(context,world,history,w) : PersistentGenerationAllowed912(registry,world.paidDefinitions[key],world.traversalControl.traversal.id)} PersistentCurrentEffect912(registry,context,world,history,ledger,w) == [tag |-> "CurrentImminentEffect",windowId |-> w.id,instruction |-> w.instruction,revision |-> context.currentRef.revision+1, relevantConditional |-> CurrentPendingRelevant99(context,world,history,ledger), paidInterruptAbilities |-> {key.ability : key \in PersistentCurrentPaidRelevant912(registry,context,world,history,w)}] PersistentCurrentPaidRelevance912(registry,context,world,history,w) == [tag |-> "PaidInterruptRelevance",windowId |-> w.id,instruction |-> w.instruction,revision |-> context.currentRef.revision+1, eligible |-> PersistentCurrentPaidRelevant912(registry,context,world,history,w)] PreparePersistentOpening912(registry,beforeContext,afterContext,beforeLedger,afterLedger,origin,world,history,windowId,group,allocation,usedWindows,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,beforeLedger,authority) /\ InitialWouldCaptured99(beforeContext,history) /\ beforeContext.phase="Replacing" /\ ExpectedContextOrigin99(beforeContext,origin) /\ ExpectedContextWorld99(beforeContext,world) /\ WouldViewCurrent99(history,beforeContext,world) /\ CurrentInterruptWorld99(world,beforeLedger,cardFacts) /\ ReplacementSourcesBound99(beforeContext,world,cardFacts) /\ ReplacementPreparationComplete99(beforeContext.state,ActiveReplacementBlueprints99(beforeContext,world)) /\ windowId \in (Nat \ {0}) \ usedWindows /\ group \in Nat \ {0} /\ LET candidates == {key \in OpeningConditionalKeys99(beforeContext,world,history,beforeLedger) : PersistentGenerationAllowed912(registry,world.conditional.definitions[key],world.traversalControl.traversal.id)} ids == {allocation[key] : key \in candidates} recognitions == {[definition |-> key,occurrence |-> beforeContext.imminenceId] : key \in candidates} additions == [id \in ids |-> LET key == CHOOSE k \in candidates : allocation[k]=id IN NewOpeningInterruptInstance99(id,world.conditional.definitions[key],world.conditional,beforeLedger,beforeContext,windowId,group)] IN /\ DOMAIN allocation=candidates /\ Cardinality(ids)=Cardinality(candidates) /\ ids \subseteq (Nat \ {0}) \ DOMAIN beforeLedger.instances /\ recognitions \cap beforeLedger.interruptRecognitions={} /\ afterLedger=[beforeLedger EXCEPT !.instances=ReplacementOverlay99(@,additions),!.interruptRecognitions=@ \cup recognitions] /\ afterContext=[beforeContext EXCEPT !.phase="Prepared",!.preparedEffects=beforeContext.state.effects,!.openingRef=beforeContext.currentRef, !.conditionalIds=ids,!.conditionalDefinitions=[key \in candidates |-> world.conditional.definitions[key]], !.windowId=windowId,!.group=group,!.openingMembers=[id \in ids |-> additions[id].member]] OpenPersistentPrepared912(registry,beforeContext,afterContext,beforeStack,afterStack,origin,world,history,ledger,site,opening,usedWindows,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,ledger,authority) /\ beforeContext.phase="Prepared" /\ ExpectedContextOrigin99(beforeContext,origin) /\ ExpectedContextWorld99(beforeContext,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ BarrierInstructionOwnerAtTop98(beforeContext.owner,beforeStack) /\ WouldViewCurrent99(history,beforeContext,world) /\ site.turnId=world.turn.id /\ site.active=world.turn.owner /\ opening=PreparedOriginOpening99(beforeContext,site) /\ LET proposed == NewPriorityWindow9(beforeContext.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,site),beforeContext.openingMembers, beforeContext.group,NoTimingRef9,beforeContext.openingRef,beforeContext.openingRef.revision+1) IN /\ beforeContext.conditionalIds # {} \/ PersistentOpeningPaidRelevant912(registry,beforeContext,world,history,proposed) # {} /\ IF origin.kind="BarrierInstruction" THEN OpenBarrierInstructionInterrupt98(origin.procedure,beforeStack,afterStack,beforeContext.windowId,site,beforeContext.openingMembers,opening,usedWindows) ELSE OpenInstructionInterrupt93(beforeStack,afterStack,beforeContext.windowId,site,beforeContext.openingMembers,opening,usedWindows, origin.plan,origin.parent,origin.ruleStep) /\ afterContext=[beforeContext EXCEPT !.phase="WindowOpen",!.site=site] NoPersistentPrepared912(registry,before,after,origin,world,history,ledger,stack,site,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,ledger,authority) /\ before.phase="Prepared" /\ ExpectedContextOrigin99(before,origin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ BarrierInstructionOwnerAtTop98(before.owner,stack) /\ WouldViewCurrent99(history,before,world) /\ site.turnId=world.turn.id /\ site.active=world.turn.owner /\ before.conditionalIds={} /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(stack,site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN /\ PersistentOpeningPaidRelevant912(registry,before,world,history,proposed)={} /\ after=[before EXCEPT !.phase="Cleared",!.site=site] ClearPersistentInstruction912(registry,before,after,origin,world,history,ledger,beforeStack,afterStack,route,clearance,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,ledger,authority) /\ origin.kind="Instruction" /\ ExpectedContextOrigin99(before,origin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ WouldViewCurrent99(history,before,world) /\ route \in {"Window","NoModifiers"} /\ IF route="Window" THEN /\ CurrentInterruptWindow99(before,beforeStack) /\ clearance=ContextInstructionClearance99(before,before.windowId) /\ ReturnInstructionInterrupt93(beforeStack,afterStack,origin.plan,origin.parent,origin.ruleStep,clearance) /\ \A id \in before.conditionalIds : ledger.instances[id].status \in {"Complete","Lost"} ELSE /\ before.phase="Cleared" /\ before.conditionalIds={} /\ beforeStack=afterStack /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,before.site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN PersistentOpeningPaidRelevant912(registry,before,world,history,proposed)={} /\ clearance=ContextInstructionClearance99(before,0) /\ NoInstructionInterrupt93(origin.plan,origin.parent,origin.ruleStep,ContextNoModifiers99(before),clearance) /\ BarrierInstructionOwnerAtTop98(before.owner,afterStack) /\ after=[before EXCEPT !.phase="InstructionCleared",!.clearance=clearance] ClearPersistentBarrierInstruction912(registry,before,after,beforeOrigin,afterOrigin,world,history,ledger,beforeStack,afterStack,route, payload,prevented,clearance,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,ledger,authority) /\ beforeOrigin.kind="BarrierInstruction" /\ ExpectedContextOrigin99(before,beforeOrigin) /\ ExpectedContextWorld99(before,world) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ WouldViewCurrent99(history,before,world) /\ ExpectedBarrierInstructionProjection99(before,beforeOrigin.procedure,payload,prevented) /\ LET p == [beforeOrigin.procedure EXCEPT !.payload=payload,!.ability.instructions=payload.instructions,!.prevented=prevented] ready == [p EXCEPT !.phase="FirstTargets"] IN /\ route \in {"Window","NoModifiers"} /\ IF route="Window" THEN /\ CurrentInterruptWindow99(before,beforeStack) /\ clearance=BarrierInstructionContextClearance99(before,before.windowId,p) /\ ReturnBarrierInstructionInterrupt98(p,ready,beforeStack,afterStack,clearance) /\ \A id \in before.conditionalIds : ledger.instances[id].status \in {"Complete","Lost"} ELSE /\ before.phase="Cleared" /\ before.conditionalIds={} /\ beforeStack=afterStack /\ LET proposed == NewPriorityWindow9(before.windowId,"Interrupt",PriorityOpeningSite9(beforeStack,before.site),before.openingMembers, before.group,NoTimingRef9,before.openingRef,before.openingRef.revision+1) IN PersistentOpeningPaidRelevant912(registry,before,world,history,proposed)={} /\ clearance=BarrierInstructionContextClearance99(before,0,p) /\ NoBarrierInstructionInterrupt98(p,ready,beforeStack, [tag |-> "NoBarrierInstructionInterruptModifiers",barrierInstruction |-> BarrierInstructionWindowRef98(p),conditionalInstances |-> {},paidInterruptAbilities |-> {}],clearance) /\ afterOrigin=[beforeOrigin EXCEPT !.procedure=ready] /\ after=[before EXCEPT !.phase="Returned",!.actualEffects=ActualExpectedEffects99(before.state.effects),!.clearance=clearance] ReserveCurrentPersistentPaid912(registry,beforeStack,afterStack,p,id,d,c,context,origin,world,history,ledger,option,legality,usedInstances,cardFacts,authority) == /\ PersistentInterruptWorld912(registry,world,ledger,authority) /\ CurrentInterruptWorld99(world,ledger,cardFacts) /\ ExpectedContextWorld99(context,world) /\ ExpectedContextOrigin99(context,origin) /\ WouldViewCurrent99(history,context,world) /\ CurrentInterruptWindow99(context,beforeStack) /\ LET key == AbilityKey99(d) w == WindowTop9(beforeStack) IN /\ key \in DOMAIN world.paidDefinitions /\ world.paidDefinitions[key]=d /\ c=world.paidContexts[key] /\ c.currentEffect=PersistentCurrentEffect912(registry,context,world,history,ledger,w) /\ c.paidRelevance=PersistentCurrentPaidRelevance912(registry,context,world,history,w) /\ key \in PersistentCurrentPaidRelevant912(registry,context,world,history,w) /\ ReservePersistentPaid912(registry,beforeStack,afterStack,p,id,d,world.lexemes[key],c,option,legality,usedInstances,cardFacts,ledger,authority) PersistentWorldBound912(registry,world,ledger,authority) == PersistentInterruptWorld912(registry,world,ledger,authority) OccurrenceSpecificationShapeSupported912(spec,p) == /\ IF spec.repeat.kind="NoValue" THEN TRUE ELSE /\ spec.repeat.node \in DOMAIN p.nodes /\ p.nodes[spec.repeat.node].kind="Plain" /\ spec.repeat.kind="Fixed" => DOMAIN p.nodes \ {spec.repeat.node}#{} /\ \A selector \in DOMAIN spec.modal : LET m == spec.modal[selector] body == UNION {SubIds6(m.bodies[mode]) : mode \in DOMAIN m.bodies} IN /\ body \cap DOMAIN spec.modal={} /\ body \subseteq DOMAIN p.nodes /\ \A id \in body : p.nodes[id].kind \notin {"Choice","NestedCost"} /\ spec.repeat.kind="Fixed" => spec.repeat.node \notin body /\ \A a,b \in DOMAIN m.bodies : a#b => SubIds6(m.bodies[a]) \cap SubIds6(m.bodies[b])={} /\ \A other \in DOMAIN spec.modal \ {selector} : body \cap UNION {SubIds6(spec.modal[other].bodies[mode]) : mode \in DOMAIN spec.modal[other].bodies}={} OccurrenceSpecificationValid912(spec,p,objects,cardFacts) == /\ CompiledInstructionTechnique911(p,objects,cardFacts) /\ spec.tag="OccurrenceTechniqueSpecification" /\ spec.definition=p.definition /\ spec.source=p.source /\ spec.sourceSHA=p.sourceSHA /\ spec.card=p.card /\ spec.repeat.kind \in {"NoValue","Fixed","Unbounded"} /\ IF spec.repeat.kind="NoValue" THEN spec.repeat.node=0 ELSE spec.repeat.node \in DOMAIN p.nodes /\ DOMAIN spec.modal \subseteq DOMAIN p.nodes /\ spec.repeat.node \notin DOMAIN spec.modal /\ OccurrenceSpecificationShapeSupported912(spec,p) /\ \A selector \in DOMAIN spec.modal : LET m == spec.modal[selector] IN /\ m.selector=selector /\ m.maximum \in Nat /\ m.upTo \in BOOLEAN /\ m.allowRepeat \in BOOLEAN /\ m.quotaPolicy \in {"Fixed","Committed"} /\ IF m.quotaPolicy="Committed" THEN /\ m.commitment.tag="SourceQuotaCommitment" /\ m.commitment.source=p.source /\ m.commitment.sourceSHA=p.sourceSHA /\ m.commitment.definition=p.definition /\ m.commitment.node \in DOMAIN p.nodes \ {selector} /\ p.nodes[m.commitment.node].kind \in {"Choice","NestedCost"} /\ m.commitment.unit \in p.nodes[m.commitment.node].segments /\ m.commitment.quotaByOption=p.units[m.commitment.unit].quotaByOption /\ DOMAIN m.commitment.quotaByOption=DOMAIN p.nodes[m.commitment.node].options /\ \A option \in DOMAIN m.commitment.quotaByOption : m.commitment.quotaByOption[option].maximum \in Nat /\ m.commitment.quotaByOption[option].upTo \in BOOLEAN ELSE TRUE /\ m.chooser \in SetupPlayers /\ DOMAIN m.bodies \subseteq Nat \ {0} /\ DOMAIN m.bodies#{} /\ p.nodes[selector].options=[mode \in DOMAIN m.bodies |-> Head(m.bodies[mode])] /\ p.nodes[selector].next=m.join /\ \A mode \in DOMAIN m.bodies : /\ DeckSequenceValid4(m.bodies[mode]) /\ Len(m.bodies[mode])>0 /\ SubIds6(m.bodies[mode]) \subseteq DOMAIN p.nodes /\ \A i \in 1..Len(m.bodies[mode]) : p.nodes[m.bodies[mode][i]].next=IF i=Len(m.bodies[mode]) THEN m.join ELSE m.bodies[mode][i+1] OccurrenceOwnerMetadata912(base) == IF base.ability.kind="Conditional" THEN [kind |-> "Conditional",windowId |-> base.windowId,option |-> base.option,transaction |-> base.transaction,turnId |-> base.turnId] ELSE [kind |-> base.ability.kind,sourceEntry |-> base.sourceEntry,owner |-> base.sourceOwner] OccurrencePriorityOwner912(r) == IF r.metadata.kind="Conditional" THEN [windowId |-> r.metadata.windowId,option |-> r.metadata.option,transaction |-> r.metadata.transaction] ELSE r.metadata.owner OccurrenceModalInitial912(spec,pass) == [selector \in DOMAIN spec.modal |-> [resolved |-> <<>>,currentMode |-> 0,invocation |-> pass,maximum |-> 0,upTo |-> FALSE,latched |-> FALSE]] NewOccurrenceRuntime912(base,spec) == [id |-> base.id,technique |-> base.technique,specification |-> spec,metadata |-> OccurrenceOwnerMetadata912(base), ability |-> base.ability,phase |-> base.phase,current |-> base.pc,pc |-> base.pc,trace |-> <<>>, occurrences |-> [id \in {base.pc} |-> [id |-> id,sourceNode |-> base.pc,pass |-> 0]],usedOccurrences |-> {base.pc}, choices |-> [id \in {} |-> id],checkpoint |-> 0,pause |-> [id |-> 0],pauseKeys |-> {},boundary |-> [id \in {} |-> id], repeat |-> [pass |-> 0,requested |-> FALSE,captured |-> FALSE,total |-> 0,remaining |-> 0], modal |-> OccurrenceModalInitial912(spec,0)] OccurrenceRuntimeProfile912(r) == /\ InstructionTechniqueValid911(r.technique) /\ OccurrenceSpecificationShapeSupported912(r.specification,r.technique) /\ r.id=r.ability.id /\ r.technique.source=r.ability.source /\ r.specification.definition=r.technique.definition /\ r.ability.kind=r.technique.definition.syntax.kind /\ (r.current=0)=(r.pc=0) /\ r.metadata.kind=r.ability.kind /\ DeckSequenceValid4(r.trace) /\ DOMAIN r.occurrences=r.usedOccurrences /\ r.usedOccurrences \subseteq Nat \ {0} /\ SubIds6(r.trace) \subseteq r.usedOccurrences /\ IF r.trace# <<>> THEN Head(r.trace)=r.technique.entry ELSE r.pc=r.technique.entry /\ r.repeat.pass \in Nat /\ r.repeat.total \in Nat /\ r.repeat.remaining \in Nat /\ r.repeat.requested \in BOOLEAN /\ r.repeat.captured \in BOOLEAN /\ DOMAIN r.modal=DOMAIN r.specification.modal /\ \A selector \in DOMAIN r.modal : /\ r.modal[selector].resolved \in Seq(DOMAIN r.specification.modal[selector].bodies) /\ r.modal[selector].currentMode \in {0} \cup DOMAIN r.specification.modal[selector].bodies /\ r.modal[selector].invocation=r.repeat.pass /\ r.modal[selector].maximum \in Nat /\ r.modal[selector].upTo \in BOOLEAN /\ r.modal[selector].latched \in BOOLEAN /\ ~r.specification.modal[selector].allowRepeat => DeckSequenceValid4(r.modal[selector].resolved) /\ \A id \in DOMAIN r.occurrences : r.occurrences[id].id=id /\ r.occurrences[id].sourceNode \in DOMAIN r.technique.nodes /\ r.phase \in {"Targets","Imminent","Resolve","Paused","Checkpoint","Complete","Returned"} /\ IF r.current=0 THEN r.ability.instructions=r.trace /\ r.ability.complete /\ r.ability.lastFinished ELSE /\ r.current \in r.usedOccurrences \ SubIds6(r.trace) /\ r.pc=r.occurrences[r.current].sourceNode /\ r.ability.instructions=Append(r.trace,r.current) OccurrencePlan912(r,plan) == /\ r.current \in DOMAIN r.occurrences /\ r.pc=r.occurrences[r.current].sourceNode /\ plan.origin="Ability" /\ plan.id=r.current /\ plan.abilityInstance=r.id /\ plan.source=r.ability.source /\ plan.sourceZone=r.ability.sourceZone /\ plan.index=Len(r.trace)+1 /\ plan.steps=r.technique.nodes[r.pc].steps /\ plan.requiresTargets=r.technique.nodes[r.pc].requiresTargets OccurrenceLookOwner912(r) == ReplacementOverlay99(r,[definition |-> r.technique.definition]) OccurrenceOwnerCurrent912(r,a) == /\ r.id \in DOMAIN a.current.activity.instances /\ "owner" \in DOMAIN a.current.activity.instances[r.id] /\ LET owner == a.current.activity.instances[r.id].owner IN /\ owner.ability=r.ability /\ owner.technique=r.technique /\ owner.specification=r.specification /\ owner.metadata=r.metadata /\ owner.current=r.current /\ owner.pc=r.pc /\ owner.trace=r.trace /\ owner.occurrences=r.occurrences /\ owner.usedOccurrences=r.usedOccurrences /\ owner.choices=r.choices /\ owner.repeat=r.repeat /\ owner.modal=r.modal ConditionalOccurrenceBound912(ledger,r) == /\ OccurrenceRuntimeProfile912(r) /\ r.metadata.kind="Conditional" /\ r.id \in DOMAIN ledger.instances /\ LET i == ledger.instances[r.id] IN /\ i.definition=ConditionalKey96(r.technique.definition) /\ i.definitionCopy=r.technique.definition /\ i.member.source=r.ability.source /\ i.member.windowId=r.metadata.windowId /\ r.ability.caller=r.metadata.windowId /\ r.metadata.option.instance=r.id /\ r.metadata.option.ability=i.member.ability /\ r.metadata.transaction \in Nat \ {0} /\ r.metadata.option.source=i.member.source /\ r.metadata.option.controller=i.member.controller AdoptOccurrenceRuntime912(before,after,spec,context,origin,ledger,world,lifetimes,authority,cardFacts) == /\ LifetimeReady910(lifetimes,authority) /\ RuntimeOwnerCurrent911(before,authority) /\ OccurrenceSpecificationValid912(spec,before.technique,world.objects,cardFacts) /\ before.visited= <<>> /\ before.pc=before.technique.entry /\ before.phase="Resolve" /\ context.phase="Resolving" /\ context.currentWorld=world.id /\ world.id=authority.current.id /\ origin.kind="Instruction" /\ origin.ruleStep="NoValue" /\ ConditionalCreationInstruction96(origin.plan,origin.parent,origin.ruleStep) /\ context.currentRef=InstructionWindowRef93(origin.plan) /\ origin.parent=before.ability /\ RuntimeCurrentPlan911(before,origin.plan) /\ IF before.ability.kind="Conditional" THEN ConditionalRuntimeBound911(ledger,before) /\ ledger.instances[before.id].status="Resolving" ELSE SourceRuntimeBound911(before) /\ after=NewOccurrenceRuntime912(before,spec) EnterNextOccurrence912(before,after,plan,afterPlan,targets,entry,ledger,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(before,authority) /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Targets" /\ before.pause.id=0 /\ before.trace# <<>> /\ BarrierInstructionOwnerAtTop98(OccurrencePriorityOwner912(before),stack) /\ before.checkpoint \in Nat \ {0} /\ ConditionalCheckpointDrained96(ledger,stack,before.checkpoint) /\ entry.checkpointId=before.checkpoint /\ OccurrencePlan912(before,plan) /\ ~plan.announced /\ LET announced == [plan EXCEPT !.announced=TRUE,!.targets=targets.targets] imminent == [before.ability EXCEPT !.phase="Imminent",!.cursor=@+1] IN /\ AnnounceInstructionTargets93(plan,announced,targets,before.ability,"NoValue") /\ EnterNextAbilityInstruction93(before.ability,imminent,announced,afterPlan,entry) /\ after=[before EXCEPT !.ability=imminent,!.phase="Imminent",!.checkpoint=0] SourceOccurrenceBound912(r) == /\ OccurrenceRuntimeProfile912(r) /\ r.metadata.kind#"Conditional" /\ r.metadata.sourceEntry.kind \in {"Paid","PlayFirst","BarrierInstructionFirst","NestedBarrierInstructionFirst"} /\ r.technique.definition=SourceEntryDefinition911(r.metadata.sourceEntry) /\ r.id=r.metadata.sourceEntry.after.id /\ r.ability.source=r.metadata.sourceEntry.after.ability.source /\ r.ability.kind=r.metadata.sourceEntry.after.ability.kind /\ r.ability.caller=r.metadata.sourceEntry.after.ability.caller /\ r.ability.sourceZone=r.metadata.sourceEntry.after.ability.sourceZone /\ r.metadata.owner=SourceEntryOwner911(r.metadata.sourceEntry) /\ r.ability.detached=r.metadata.sourceEntry.after.ability.detached EnterNextConditionalOccurrence912(beforeLedger,afterLedger,stack,before,after,plan,afterPlan,targets,entry,lifetimes,authority) == /\ ConditionalOccurrenceBound912(beforeLedger,before) /\ beforeLedger.instances[before.id].status="Resolving" /\ before.trace# <<>> /\ before.ability.detached /\ EnterNextOccurrence912(before,after,plan,afterPlan,targets,entry,beforeLedger,stack,lifetimes,authority) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status="Imminent"] ActualOccurrenceEntry912(entry,origin,world,lifetimes,authority) == /\ entry.tag="ActualOccurrenceInstructionEntry" /\ entry.id \in Nat \ {0} /\ entry.snapshotId=world.id /\ entry.id \in DOMAIN world.entries /\ world.entries[entry.id]=entry /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ origin.kind="Instruction" /\ origin.ruleStep="NoValue" /\ origin.plan=entry.afterPlan /\ origin.parent=entry.after.ability /\ entry.owner=OccurrencePriorityOwner912(entry.after) /\ entry.stackBefore=entry.stackAfter /\ IF entry.before.metadata.kind="Conditional" THEN /\ ConditionalOccurrenceBound912(entry.beforeLedger,entry.before) /\ ConditionalSnapshotBound96(world.conditional,entry.afterLedger) /\ entry.afterLedger=[entry.beforeLedger EXCEPT !.instances[entry.before.id].status="Imminent"] /\ entry.beforeLedger.instances[entry.before.id].status="Resolving" /\ EnterNextOccurrence912(entry.before,entry.after,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt, entry.beforeLedger,entry.stackBefore,lifetimes,authority) ELSE /\ SourceOccurrenceBound912(entry.before) /\ EnterNextOccurrence912(entry.before,entry.after,entry.beforePlan,entry.afterPlan,entry.targets,entry.receipt, entry.ledger,entry.stackBefore,lifetimes,authority) BeginOccurrenceExpected912(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,lifetimes,authority) == /\ ExpectedWorldValid99(world) /\ ActualOccurrenceEntry912(entry,origin,world,lifetimes,authority) /\ \A prior \in DOMAIN before.contexts : InitialWouldCaptured99(before.contexts[prior],beforeWould) /\ entry.id \notin before.entryIds /\ id \in (Nat \ {0}) \ before.usedContextIds /\ ~\E prior \in DOMAIN before.contexts : WouldContextKey99(before.contexts[prior].initialRef)=WouldContextKey99(OriginReference99(origin)) /\ description.sourceNode=entry.after.pc /\ description.occurrence=entry.after.current /\ owner=entry.owner /\ InitialExpectedProjection99(origin,world,description,projection,initial) /\ LET context == NewExpectedContext99(id,entry.id,origin,world,description,initial,owner) IN /\ observation=InitialWouldObservation99(context,observation.id) /\ RecordWouldDescriptors99(beforeWould,afterWould,id,entry.id,context.initialRef,world.id,initial,context.initialWouldGroups, context.initialPeriods,InitialWouldOrder99(context),observation) /\ after=[before EXCEPT !.entryIds=@ \cup {entry.id},!.usedContextIds=@ \cup {id}, !.contexts=ReplacementOverlay99(@,[key \in {id} |-> context])] ObserveOccurrenceExpected912(before,after,r,plan,context,history) == /\ ConditionalOccurrenceBound912(before,r) /\ before.instances[r.id].status="Imminent" /\ r.phase="Imminent" /\ OccurrencePlan912(r,plan) /\ context.initialRef=InstructionWindowRef93(plan) /\ InitialWouldCaptured99(context,history) /\ plan.index \notin DOMAIN before.instances[r.id].expected /\ after=[before EXCEPT !.instances[r.id].expected=ReplacementOverlay99(@,[i \in {plan.index} |-> [instruction |-> context.initialRef,effects |-> ExpectedObservationSet99(context.initialEffects)]])] BeginOccurrenceAtomic912(before,after,plan,afterPlan,context,origin,clearance,world,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Imminent" /\ OccurrencePlan912(before,plan) /\ BarrierInstructionOwnerAtTop98(OccurrencePriorityOwner912(before),stack) /\ context.phase="InstructionCleared" /\ context.currentRef=InstructionWindowRef93(plan) /\ context.clearance=clearance /\ origin.kind="Instruction" /\ origin.ruleStep="NoValue" /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ world.traversalControl=authority.current.control /\ origin.parent=before.ability /\ origin.plan=plan /\ world.id=authority.current.id /\ ExpectedContextWorld99(context,world) /\ LET resolving == [before.ability EXCEPT !.phase="Resolving"] IN /\ BeginAbilityInstructionAtomic93(before.ability,resolving,plan,afterPlan,clearance) /\ after=[before EXCEPT !.ability=resolving,!.phase="Resolve"] OccurrenceControlBound912(r,c,ret,result) == /\ result.tag="ResolvedInstructionControl" /\ result.instance=r.id /\ result.node=r.pc /\ result.instruction=c.currentRef /\ result.contextId=c.id /\ result.actualEffects=c.actualEffects /\ result.completion=ret /\ result.mode \in {"Selected","Removed"} /\ IF result.mode="Selected" THEN /\ result.operation \in DOMAIN c.actualEffects /\ c.actualEffects[result.operation].kind \in {"InstructionChoice","NestedCostChoice","ModalChoice","AbilityRepeat"} /\ c.actualEffects[result.operation].controlNode=r.pc /\ result.chooser=c.actualEffects[result.operation].chooser /\ result.chooser \in SetupPlayers /\ IF r.pc=r.specification.repeat.node THEN /\ c.actualEffects[result.operation].kind="AbilityRepeat" /\ result.requested=c.actualEffects[result.operation].requested /\ result.requested \in BOOLEAN ELSE IF r.pc \in DOMAIN r.specification.modal THEN /\ c.actualEffects[result.operation].kind="ModalChoice" /\ result.option \in c.actualEffects[result.operation].options /\ result.option \in DOMAIN r.specification.modal[r.pc].bodies \cup {0} /\ result.maximum=c.actualEffects[result.operation].maximum /\ result.maximum \in Nat /\ result.upTo=c.actualEffects[result.operation].upTo /\ result.upTo \in BOOLEAN ELSE /\ result.option \in DOMAIN r.technique.nodes[r.pc].options /\ result.option \in c.actualEffects[result.operation].options ELSE ~\E op \in DOMAIN c.actualEffects : c.actualEffects[op].kind \in {"InstructionChoice","NestedCostChoice","ModalChoice","AbilityRepeat"} /\ c.actualEffects[op].controlNode=r.pc OccurrenceHasControl912(r) == r.pc=r.specification.repeat.node \/ r.pc \in DOMAIN r.specification.modal \/ r.technique.nodes[r.pc].kind \in {"Choice","NestedCost"} OccurrenceModalUpdate912(r,control) == IF r.pc \in DOMAIN r.specification.modal THEN LET old == r.modal[r.pc] selected == control.mode="Selected" /\ control.option#0 next == [old EXCEPT !.currentMode=IF selected THEN control.option ELSE 0, !.resolved=IF selected THEN Append(@,control.option) ELSE @, !.maximum=IF @=0 /\ ~old.latched /\ control.mode="Selected" THEN control.maximum ELSE @, !.upTo=IF ~old.latched /\ control.mode="Selected" THEN control.upTo ELSE @,!.latched=TRUE] IN [r.modal EXCEPT ![r.pc]=next] ELSE [selector \in DOMAIN r.modal |-> IF r.modal[selector].currentMode#0 /\ r.pc=r.specification.modal[selector].bodies[r.modal[selector].currentMode][Len(r.specification.modal[selector].bodies[r.modal[selector].currentMode])] THEN [r.modal[selector] EXCEPT !.currentMode=0] ELSE r.modal[selector]] OccurrenceCommittedQuota912(r,m) == LET matches == {occurrence \in SubIds6(r.trace) \cap DOMAIN r.choices : /\ r.occurrences[occurrence].sourceNode=m.commitment.node /\ r.occurrences[occurrence].pass=r.repeat.pass /\ r.choices[occurrence].tag="ResolvedInstructionControl" /\ r.choices[occurrence].instance=r.id /\ r.choices[occurrence].node=m.commitment.node /\ r.choices[occurrence].instruction.id=occurrence /\ r.choices[occurrence].instruction.source=r.ability.source /\ r.choices[occurrence].instruction.abilityInstance=r.id /\ r.choices[occurrence].mode="Selected" /\ r.choices[occurrence].option \in DOMAIN m.commitment.quotaByOption} IN IF Cardinality(matches)#1 THEN [supported |-> FALSE,maximum |-> 0,upTo |-> FALSE] ELSE LET occurrence == CHOOSE id \in matches : TRUE quota == m.commitment.quotaByOption[r.choices[occurrence].option] IN [supported |-> TRUE,maximum |-> quota.maximum,upTo |-> quota.upTo] OccurrenceModalQuotaSupported912(r,control) == IF r.pc \notin DOMAIN r.specification.modal \/ control.mode="Removed" THEN TRUE ELSE LET m == r.specification.modal[r.pc] old == r.modal[r.pc] committed == IF m.quotaPolicy="Committed" THEN OccurrenceCommittedQuota912(r,m) ELSE [supported |-> FALSE] IN IF old.latched THEN control.maximum=old.maximum /\ control.upTo=old.upTo ELSE IF m.quotaPolicy="Fixed" THEN control.maximum=m.maximum /\ control.upTo=m.upTo ELSE committed.supported /\ control.maximum=committed.maximum /\ control.upTo=committed.upTo ReadOccurrenceQuotaSupport912(r,context,actualReturn,control,registry,authority,receipt) == /\ LifetimeReady910(registry,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ OccurrenceRuntimeProfile912(r) /\ r.phase="Resolve" /\ context.phase="Resolving" /\ context.currentRef.id=r.current /\ context.currentRef.abilityInstance=r.id /\ context.currentRef.source=r.ability.source /\ context.currentRef.index=Len(r.trace)+1 /\ context.currentRef.sourceZone=r.ability.sourceZone /\ context.currentRef.origin="Ability" /\ context.currentRef.ruleStep="NoValue" /\ context.currentWorld=authority.current.id /\ actualReturn.snapshotId=authority.current.id /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=context.id /\ actualReturn.instruction=context.currentRef /\ actualReturn.effects=context.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ OccurrenceControlBound912(r,context,actualReturn,control) /\ receipt=[tag |-> "CurrentModalQuotaSupport",instance |-> r.id,contextId |-> context.id,instruction |-> context.currentRef, snapshotId |-> authority.current.id,status |-> IF OccurrenceModalQuotaSupported912(r,control) THEN "Supported" ELSE "Unsupported", policy |-> "FixedOrAlreadyCommittedQuota"] OccurrenceModalAllowed912(r,control) == IF r.pc \notin DOMAIN r.specification.modal \/ control.mode="Removed" THEN TRUE ELSE LET m == r.specification.modal[r.pc] old == r.modal[r.pc] maximum == IF old.latched THEN old.maximum ELSE control.maximum upTo == IF old.latched THEN old.upTo ELSE control.upTo IN /\ IF old.latched THEN control.maximum=old.maximum /\ control.upTo=old.upTo ELSE TRUE /\ IF control.option=0 THEN upTo ELSE /\ Len(old.resolved)=m.maximum THEN r.specification.modal[selector].join ELSE selector ELSE IF r.pc=r.specification.repeat.node THEN r.technique.nodes[r.pc].next ELSE IF r.technique.nodes[r.pc].kind \in {"Choice","NestedCost"} /\ control.mode="Selected" THEN r.technique.nodes[r.pc].options[control.option] ELSE r.technique.nodes[r.pc].next OccurrenceSkipFixedTrait912(r,node) == IF r.specification.repeat.kind="Fixed" /\ r.repeat.pass>0 /\ node=r.specification.repeat.node THEN r.technique.nodes[node].next ELSE node OccurrencePassNext912(r,control) == OccurrenceSkipFixedTrait912(r,OccurrenceWithinPassNext912(r,control)) OccurrenceCountCapture912(r,context,ret,capture) == /\ capture.tag="ResolvedRepetitionCount" /\ capture.instance=r.id /\ capture.source=r.ability.source /\ capture.definition=r.technique.definition /\ capture.directive=r.specification.repeat.node /\ capture.pass=0 /\ capture.contextId=context.id /\ capture.instruction=context.currentRef /\ capture.snapshotId=ret.snapshotId /\ capture.completion=ret /\ capture.count \in Nat OccurrenceRepeatRequested912(r,control) == IF r.pc=r.specification.repeat.node THEN control.mode="Selected" /\ control.requested ELSE r.repeat.requested OccurrenceContinuation912(r,control,capture) == LET within == OccurrencePassNext912(r,control) requested == OccurrenceRepeatRequested912(r,control) firstFixed == within=0 /\ r.specification.repeat.kind="Fixed" /\ ~r.repeat.captured /\ requested total == IF firstFixed THEN capture.count ELSE r.repeat.total available == IF firstFixed THEN total ELSE r.repeat.remaining again == within=0 /\ (IF r.specification.repeat.kind="Unbounded" THEN requested ELSE r.specification.repeat.kind="Fixed" /\ (r.repeat.captured \/ firstFixed) /\ available>0) rep == [r.repeat EXCEPT !.requested=IF again THEN FALSE ELSE requested, !.captured=@ \/ firstFixed,!.total=total,!.remaining=IF again /\ r.specification.repeat.kind="Fixed" THEN available-1 ELSE available, !.pass=IF again THEN @+1 ELSE @] IN [sourceNode |-> IF again THEN OccurrenceSkipFixedTrait912([r EXCEPT !.repeat=rep],r.technique.entry) ELSE within, repeat |-> rep,modal |-> IF again THEN OccurrenceModalInitial912(r.specification,rep.pass) ELSE OccurrenceModalUpdate912(r,control),again |-> again] OccurrenceBoundary912(r,context,causes,costTransaction) == [tag |-> "OccurrenceInstructionBoundary",instance |-> r.id,source |-> r.ability.source,instruction |-> context.currentRef, node |-> r.pc,occurrence |-> r.current,index |-> Len(r.trace)+1,pass |-> r.repeat.pass,causes |-> causes,costTransaction |-> costTransaction] OccurrenceBoundaryCaller912(boundary) == [kind |-> "OccurrenceInstructionBoundary",boundary |-> boundary] FinishOccurrenceInstruction912(before,after,plan,afterPlan,context,actualReturn,step,control,payment,boundary,nextId,capture) == /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Resolve" /\ before.pause.id=0 /\ OccurrencePlan912(before,plan) /\ plan.phase="Resolving" /\ plan.cursor=Len(plan.steps) /\ context.phase="Resolving" /\ context.currentRef=InstructionWindowRef93(plan) /\ actualReturn.tag="ExpectedEffectsProcedureReturn" /\ actualReturn.contextId=context.id /\ actualReturn.instruction=context.currentRef /\ actualReturn.effects=context.actualEffects /\ actualReturn.complete /\ actualReturn.childrenReturned /\ step.expectedReturn=actualReturn /\ IF OccurrenceHasControl912(before) THEN OccurrenceControlBound912(before,context,actualReturn,control) ELSE control=NoInstructionControl911 /\ OccurrenceModalQuotaSupported912(before,control) /\ OccurrenceModalAllowed912(before,control) /\ before.current \notin DOMAIN before.choices /\ IF OccurrencePassNext912(before,control)=0 /\ before.specification.repeat.kind="Fixed" /\ ~before.repeat.captured /\ OccurrenceRepeatRequested912(before,control) THEN OccurrenceCountCapture912(before,context,actualReturn,capture) ELSE capture=[tag |-> "NoRepetitionCount"] /\ LET continuation == OccurrenceContinuation912(before,control,capture) next == continuation.sourceNode trace == Append(before.trace,before.current) projected == [before.ability EXCEPT !.instructions=IF next=0 THEN trace ELSE Append(trace,nextId)] finished == IF next=0 THEN [projected EXCEPT !.phase="Complete",!.lastFinished=TRUE,!.complete=TRUE] ELSE [projected EXCEPT !.phase="Between",!.lastFinished=FALSE,!.complete=FALSE] paid == payment.tag="CompletedInstructionCost" IN /\ IF next=0 THEN nextId=0 ELSE nextId \in (Nat \ {0}) \ before.usedOccurrences /\ CarryAbilityInstructionStep93(projected,finished,plan,afterPlan,step) /\ afterPlan.phase="Complete" /\ (before.technique.nodes[before.pc].kind="NestedCost" /\ control.mode="Selected" /\ control.option="Pay") => paid /\ IF paid THEN /\ payment.instruction=context.currentRef /\ payment.instance=before.id /\ payment.source=before.ability.source /\ payment.transaction \in Nat \ {0} /\ payment.operation \in DOMAIN context.actualEffects /\ context.actualEffects[payment.operation].kind="NestedCostChoice" /\ context.actualEffects[payment.operation].controlNode=before.pc /\ control.mode="Selected" /\ control.operation=payment.operation /\ control.option="Pay" /\ payment.payer=context.actualEffects[payment.operation].payer /\ payment.specification=context.actualEffects[payment.operation].cost /\ payment.receipt.tag="CompletedCostTransaction" /\ payment.receipt.id=payment.transaction /\ payment.receipt.instance=before.id /\ payment.receipt.instruction=context.currentRef /\ payment.receipt.source=before.ability.source /\ payment.receipt.payer=payment.payer /\ payment.receipt.specification=payment.specification /\ payment.receipt.allCostsPaid /\ payment.paid /\ payment.lastAction /\ payment.completion=actualReturn ELSE payment=[tag |-> "NoInstructionPayment"] /\ boundary=OccurrenceBoundary912(before,context,IF paid THEN {"InstructionEnd","CostPaid"} ELSE {"InstructionEnd"},IF paid THEN payment.transaction ELSE 0) /\ after=[before EXCEPT !.ability=finished,!.trace=trace,!.pc=next,!.current=nextId, !.occurrences=IF next=0 THEN @ ELSE ReplacementOverlay99(@,[id \in {nextId} |-> [id |-> id,sourceNode |-> next,pass |-> continuation.repeat.pass]]), !.usedOccurrences=IF next=0 THEN @ ELSE @ \cup {nextId}, !.choices=IF OccurrenceHasControl912(before) THEN ReplacementOverlay99(@,[id \in {before.current} |-> control]) ELSE @, !.repeat=continuation.repeat,!.modal=continuation.modal,!.phase="Checkpoint",!.checkpoint=0,!.boundary=boundary] CompleteOccurrenceCheckpoint912(before,after,ledger,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(before,authority) /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Checkpoint" /\ receipt.tag="OccurrenceInstructionCheckpoint" /\ receipt.instance=before.id /\ receipt.source=before.ability.source /\ receipt.boundary=before.boundary /\ receipt.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[receipt.id].caller=OccurrenceBoundaryCaller912(before.boundary) /\ receipt.complete /\ receipt.allNewerChainsComplete /\ ConditionalCheckpointDrained96(ledger,stack,receipt.id) /\ after=[before EXCEPT !.checkpoint=receipt.id,!.phase=IF before.current=0 THEN "Complete" ELSE "Targets"] OccurrenceAtTop912(stack,r) == BarrierInstructionOwnerAtTop98(OccurrencePriorityOwner912(r),stack) BeginConditionalOccurrenceAtomic912(beforeLedger,afterLedger,before,after,plan,afterPlan,context,origin,clearance,world,stack,lifetimes,authority) == /\ ConditionalOccurrenceBound912(beforeLedger,before) /\ beforeLedger.instances[before.id].status="Imminent" /\ OccurrenceAtTop912(stack,before) /\ plan.index \in DOMAIN beforeLedger.instances[before.id].expected /\ beforeLedger.instances[before.id].expected[plan.index].instruction=context.initialRef /\ beforeLedger.instances[before.id].expected[plan.index].effects=ExpectedObservationSet99(context.initialEffects) /\ BeginOccurrenceAtomic912(before,after,plan,afterPlan,context,origin,clearance,world,stack,lifetimes,authority) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status="Resolving"] RecordConditionalOccurrenceUse912(before,after,r,plan,execution,beforeUses,afterUses,beforeTurnUses,afterTurnUses,useId,events,world,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ world.id=authority.current.id /\ world.objects=authority.current.objects /\ world.turn=authority.current.turn /\ ConditionalSnapshotBound96(world.conditional,before) /\ beforeTurnUses=world.turnUses /\ ConditionalOccurrenceBound912(before,r) /\ before.instances[r.id].status="Resolving" /\ r.phase="Resolve" /\ OccurrencePlan912(r,plan) /\ plan.phase="Resolving" /\ execution.tag="ConditionalEffectExecution" /\ execution.instruction=InstructionWindowRef93(plan) /\ execution.abilityInstance=r.id /\ execution.source=r.ability.source /\ execution.partIds \subseteq r.technique.definition.partsByInstruction[r.pc] /\ LET d == r.technique.definition optional == execution.partIds \cap ConditionalUseOptionalParts96(d) first == optional#{} /\ ~before.instances[r.id].used used == [tag |-> "AbilityUsed",useId |-> useId,abilityInstance |-> r.id,source |-> r.ability.source,player |-> d.syntax.controller] IN IF first THEN /\ OncePerTurnAllowed93(d.syntax,r.metadata.turnId,beforeTurnUses) /\ RecordAbilityUse9(beforeUses,afterUses,useId,r.id,r.ability.source,d.syntax.controller,TRUE,{used}) /\ RecordTurnAbilityUse93(beforeTurnUses,afterTurnUses,d.syntax,r.metadata.turnId, [id |-> r.id,ability |-> d.syntax.id,source |-> r.ability.source],used) /\ after=[before EXCEPT !.instances[r.id].used=TRUE] /\ events={used} ELSE after=before /\ afterUses=beforeUses /\ afterTurnUses=beforeTurnUses /\ events={} FinishConditionalOccurrenceCore912(beforeLedger,afterLedger,beforeStack,afterStack,before,after,plan,afterPlan,context, actualReturn,step,control,payment,boundary,nextId,capture) == /\ ConditionalOccurrenceBound912(beforeLedger,before) /\ OccurrenceAtTop912(beforeStack,before) /\ beforeLedger.instances[before.id].status="Resolving" /\ plan.index \in DOMAIN beforeLedger.instances[before.id].expected /\ FinishOccurrenceInstruction912(before,after,plan,afterPlan,context,actualReturn,step,control,payment,boundary,nextId,capture) /\ LET last == after.current=0 d == before.technique.definition expected == beforeLedger.instances[before.id].expected throttle == last /\ d.primaryKind="Static" /\ DOMAIN expected=1..Len(after.trace) /\ \A i \in DOMAIN expected : expected[i].effects={} IN /\ last => DOMAIN expected=1..Len(after.trace) /\ afterLedger=[beforeLedger EXCEPT !.instances[before.id].status=IF last THEN "Complete" ELSE "Resolving", !.throttle=IF throttle THEN ReplacementOverlay99(@,[key \in {ConditionalKey96(d)} |-> beforeLedger.stepSerial]) ELSE @] /\ SyncConditionalWindows96(beforeStack,afterStack,beforeLedger,afterLedger) ReturnConditionalOccurrence912(beforeStack,afterStack,before,after,ledger,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(before,authority) /\ before.id \in authority.current.finishedInstances /\ ConditionalOccurrenceBound912(ledger,before) /\ before.phase="Complete" /\ before.current=0 /\ ledger.instances[before.id].status="Complete" /\ OccurrenceAtTop912(beforeStack,before) /\ before.checkpoint \in Nat \ {0} /\ receipt.finalCheckpointId=before.checkpoint /\ LET returned == [before.ability EXCEPT !.returned=TRUE] IN /\ ReturnAbility9(before.ability,returned,TRUE,before.metadata.windowId) /\ CompletePriorityOption9(beforeStack,afterStack,receipt) /\ after=[before EXCEPT !.ability=returned,!.phase="Returned"] PauseOccurrenceInstruction912(before,after,plan,context,id,cause,child,point,operation,request,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Resolve" /\ before.ability.phase="Resolving" /\ before.pause.id=0 /\ OccurrencePlan912(before,plan) /\ plan.phase="Resolving" /\ id \in Nat \ {0} /\ InstructionPausePoint911(before,plan,context,cause,child,point,operation) /\ InstructionPauseKey911(context,plan,cause,child,point,operation) \notin before.pauseKeys /\ request.tag="OwnedInstructionCheckpointRequest" /\ request.id \in Nat \ {0} /\ request.caller=InstructionPauseCaller911(before,plan,cause,child,point) /\ after=[before EXCEPT !.phase="Paused",!.pauseKeys=@ \cup {InstructionPauseKey911(context,plan,cause,child,point,operation)},!.pause=[id |-> id,cause |-> cause,childId |-> child.id,point |-> point, instruction |-> InstructionWindowRef93(plan),cursor |-> plan.cursor,operation |-> operation,request |-> request]] ResumeOccurrenceInstruction912(before,after,plan,ledger,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Paused" /\ before.ability.phase="Resolving" /\ before.pause.id \in Nat \ {0} /\ before.pause.instruction=InstructionWindowRef93(plan) /\ before.pause.cursor=plan.cursor /\ plan.phase="Resolving" /\ receipt.tag="OwnedInstructionCheckpointReturn" /\ receipt.pauseId=before.pause.id /\ receipt.childId=before.pause.childId /\ receipt.instruction=before.pause.instruction /\ receipt.point=before.pause.point /\ receipt.id=before.pause.request.id /\ receipt.id \in DOMAIN ledger.checkpoints /\ ledger.checkpoints[receipt.id].caller=before.pause.request.caller /\ receipt.complete /\ receipt.allNewerChainsComplete /\ ConditionalCheckpointDrained96(ledger,stack,receipt.id) /\ after=[before EXCEPT !.phase="Resolve",!.pause=[id |-> 0]] CarryOccurrenceWorkStep912(before,after,plan,afterPlan,context,step,work) == /\ OccurrenceRuntimeProfile912(before) /\ before.phase="Resolve" /\ before.pause.id=0 /\ OccurrencePlan912(before,plan) /\ plan.cursor r.technique.definition.syntax.id,sourceObject |-> IF r.ability.source.kind="Object" THEN r.ability.source.object ELSE 0, status |-> IF r.current=0 THEN "Complete" ELSE "Resolving",owner |-> OccurrenceLookOwner912(r)])] FinishObservedConditionalOccurrenceCore912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,nextId,capture,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ OccurrenceOwnerCurrent912(before,beforeAuthority) /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ ExpectedWorldValid99(world) /\ world.id=beforeAuthority.current.id /\ world.objects=beforeAuthority.current.objects /\ world.turn=beforeAuthority.current.turn /\ world.traversalControl=beforeAuthority.current.control /\ beforeContext.phase="Resolving" /\ beforeContext.currentWorld=world.id /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.ruleStep="NoValue" /\ beforeOrigin.plan=plan /\ beforeOrigin.parent=before.ability /\ beforeContext.initialRef.source=before.ability.source /\ beforeContext.initialRef.abilityInstance=before.id /\ beforeContext.currentRef=InstructionWindowRef93(plan) /\ actualReturn.snapshotId=world.id /\ FinishConditionalOccurrenceCore912(beforeLedger,candidateLedger,beforeStack,DelayedCarryStack910(beforeStack,beforeLedger,candidateLedger), before,after,plan,afterPlan,beforeContext,actualReturn,step,control,payment,boundary,nextId,capture) /\ LET next == afterAuthority.current execution == [tag |-> "ActualObjectTransition",id |-> beforeContext.id,snapshotId |-> next.id, source |-> before.ability.source,instruction |-> beforeContext.currentRef,return |-> actualReturn] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ OccurrenceFinishWorld912(beforeAuthority.current,next,after,candidateLedger) /\ AppendLifetimeTransitionCore910(beforeAuthority,afterAuthority,LifetimeKernelTransition910(beforeAuthority.current,next,execution)) /\ ObserveLingering910(beforeRegistry,local,next) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=next.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,candidateLedger,next) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeAuthority.current) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,candidateLedger,next) /\ ObserveConditionalActivity96(beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ DelayedLifetimeBound910(afterRegistry,afterLedger) /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan,!.parent=after.ability] /\ afterContext=[beforeContext EXCEPT !.phase="Returned"] FinishObservedConditionalOccurrence912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,nextId,capture,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ OccurrenceFinishedDelayed912(after,candidateLedger)={} /\ FinishObservedConditionalOccurrenceCore912(beforeRegistry,afterRegistry,beforeLedger,candidateLedger,afterLedger,beforeStack,afterStack, before,after,plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,nextId,capture,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) FinishObservedDelayedOccurrence912(before,mid,after,call) == /\ call.before.technique.definition.delayedEffect \in Nat \ {0} /\ OccurrenceFinishedDelayed912(call.after,call.candidateLedger)={call.before.technique.definition.delayedEffect} /\ FinishObservedConditionalOccurrenceCore912(before.registry,mid.registry,before.ledger,call.candidateLedger,mid.ledger,before.stack,mid.stack, call.before,call.after,call.plan,call.afterPlan,call.context,call.afterContext,call.origin,call.afterOrigin,call.world, call.actualReturn,call.step,call.control,call.payment,call.boundary,call.nextId,call.capture,before.snapshot,mid.snapshot,before.authority,mid.authority) /\ LET next == after.authority.current acknowledgement == DelayedRuntimePublicationAck911(call.actualReturn,mid.authority.current) execution == [tag |-> "ActualDelayedReturn",id |-> call.context.id,snapshotId |-> next.id, source |-> call.before.ability.source,instruction |-> call.context.currentRef,return |-> acknowledgement] local == [after.registry EXCEPT !.frontier=mid.registry.frontier] IN /\ next=[mid.authority.current EXCEPT !.id=next.id, !.finishedDelayedEffects=@ \cup OccurrenceFinishedDelayed912(call.after,call.candidateLedger)] /\ AppendLifetimeTransitionCore910(mid.authority,after.authority,LifetimeKernelTransition910(mid.authority.current,next,execution)) /\ ObserveLingering910(mid.registry,local,next) /\ after.snapshot.id=next.id /\ LingeringConditionalWorld910(after.snapshot,mid.ledger,next) /\ after.snapshot=LingeringConditionalSnapshot910(after.snapshot,local,mid.ledger,next) /\ ObserveConditionalActivity96(mid.ledger,mid.ledger,after.ledger,mid.stack,after.stack,mid.snapshot,after.snapshot) /\ after.registry.frontier=LifetimeFrontier910(after.authority,Len(after.authority.order)) /\ DelayedLifetimeBound910(after.registry,after.ledger) FinishObservedSourceOccurrence912(beforeRegistry,afterRegistry,beforeLedger,afterLedger,beforeStack,afterStack,before,after, plan,afterPlan,beforeContext,afterContext,beforeOrigin,afterOrigin,world, actualReturn,step,control,payment,boundary,nextId,capture,beforeSnapshot,afterSnapshot,beforeAuthority,afterAuthority) == /\ LifetimeReady910(beforeRegistry,beforeAuthority) /\ OccurrenceOwnerCurrent912(before,beforeAuthority) /\ DelayedLifetimeBound910(beforeRegistry,beforeLedger) /\ SourceOccurrenceBound912(before) /\ BarrierInstructionOwnerAtTop98(before.metadata.owner,beforeStack) /\ ExpectedWorldValid99(world) /\ world.id=beforeAuthority.current.id /\ world.objects=beforeAuthority.current.objects /\ world.turn=beforeAuthority.current.turn /\ world.traversalControl=beforeAuthority.current.control /\ beforeContext.phase="Resolving" /\ beforeContext.currentWorld=world.id /\ beforeContext.currentRef=InstructionWindowRef93(plan) /\ actualReturn.snapshotId=world.id /\ beforeOrigin.kind="Instruction" /\ beforeOrigin.ruleStep="NoValue" /\ beforeOrigin.plan=plan /\ beforeOrigin.parent=before.ability /\ beforeContext.initialRef.source=before.ability.source /\ beforeContext.initialRef.abilityInstance=before.id /\ FinishOccurrenceInstruction912(before,after,plan,afterPlan,beforeContext,actualReturn,step,control,payment,boundary,nextId,capture) /\ LET next == afterAuthority.current execution == [tag |-> "ActualObjectTransition",id |-> beforeContext.id,snapshotId |-> next.id, source |-> before.ability.source,instruction |-> beforeContext.currentRef,return |-> actualReturn] local == [afterRegistry EXCEPT !.frontier=beforeRegistry.frontier] IN /\ OccurrenceFinishWorld912(beforeAuthority.current,next,after,beforeLedger) /\ AppendLifetimeTransitionCore910(beforeAuthority,afterAuthority,LifetimeKernelTransition910(beforeAuthority.current,next,execution)) /\ ObserveLingering910(beforeRegistry,local,next) /\ beforeSnapshot.id=beforeAuthority.current.id /\ afterSnapshot.id=next.id /\ LingeringConditionalWorld910(beforeSnapshot,beforeLedger,beforeAuthority.current) /\ LingeringConditionalWorld910(afterSnapshot,beforeLedger,next) /\ beforeSnapshot=LingeringConditionalSnapshot910(beforeSnapshot,beforeRegistry,beforeLedger,beforeAuthority.current) /\ afterSnapshot=LingeringConditionalSnapshot910(afterSnapshot,local,beforeLedger,next) /\ ObserveConditionalActivity96(beforeLedger,beforeLedger,afterLedger,beforeStack,afterStack,beforeSnapshot,afterSnapshot) /\ afterRegistry.frontier=LifetimeFrontier910(afterAuthority,Len(afterAuthority.order)) /\ afterOrigin=[beforeOrigin EXCEPT !.plan=afterPlan,!.parent=after.ability] /\ afterContext=[beforeContext EXCEPT !.phase="Returned"] ReturnPaidOccurrence912(beforeStack,afterStack,r,afterRuntime,afterProcedure,receipt,objects,transits,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceOccurrenceBound912(r) /\ r.metadata.sourceEntry.kind="Paid" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ LET p == [r.metadata.sourceEntry.after EXCEPT !.ability=r.ability,!.phase="Complete",!.checkpoint=r.checkpoint] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ FinishPaidProcedure95(beforeStack,afterStack,p,afterProcedure,receipt) /\ afterRuntime=[r EXCEPT !.ability=afterProcedure.ability,!.phase="Returned"] ReturnPlayOccurrence912(r,afterRuntime,beforeCohort,afterCohort,f,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceOccurrenceBound912(r) /\ r.metadata.sourceEntry.kind="PlayFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ ~r.ability.detached /\ beforeCohort=r.metadata.sourceEntry.after /\ CurrentPlayDefinition97(beforeCohort)=r.technique.definition /\ PlayOwnerAtTop97(beforeCohort,f,stack) /\ BarrierInstructionOwnerAtTop98(r.metadata.owner,stack) /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,beforeCohort.playId) /\ afterCohort=PlayAdvanceDisposition97([beforeCohort EXCEPT !.ability=r.ability],"Resolved",r.id) /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] ReturnEncounterBarrierInstructionOccurrence912(r,afterRuntime,beforeLoop,afterLoop,e,afterEncounter,stack,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceOccurrenceBound912(r) /\ r.metadata.sourceEntry.kind="BarrierInstructionFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ LET p == r.metadata.sourceEntry.after IN /\ BarrierInstructionLoopMatches98(beforeLoop,e) /\ p.origin="Encounter" /\ beforeLoop.current=r.id /\ e.id=p.encounter /\ e.barrierCard=p.barrierCard /\ beforeLoop.owner=r.metadata.owner /\ BarrierInstructionOwnerAtTop98(r.metadata.owner,stack) /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,p.caller) /\ afterEncounter=[e EXCEPT !.resolved=@ \cup {p.barrierInstruction}] /\ afterLoop=[beforeLoop EXCEPT !.current=0,!.handled=@ \cup {p.barrierInstruction},!.resolved=@ \cup {p.barrierInstruction}, !.history=Append(@,[barrierInstruction |-> p.barrierInstruction,instance |-> r.id,disposition |-> "Resolved",source |-> r.ability.source])] /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] ReturnNestedBarrierInstructionOccurrence912(r,afterRuntime,beforeCalls,afterCalls,parentPlan,parent,ruleStep,stack,receipt,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceOccurrenceBound912(r) /\ r.metadata.sourceEntry.kind="NestedBarrierInstructionFirst" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ BarrierInstructionOwnerAtTop98(r.metadata.owner,stack) /\ LET p == r.metadata.sourceEntry.after IN /\ NestedBarrierInstructionInvocation98(p,parentPlan,parent,ruleStep,p.invocation) /\ p.invocation.id \in DOMAIN beforeCalls /\ beforeCalls[p.invocation.id]=[instruction |-> InstructionWindowRef93(parentPlan),instance |-> r.id,status |-> "Active", source |-> r.ability.source,encounter |-> p.encounter,barrierInstruction |-> p.barrierInstruction,disposition |-> "NoValue"] /\ receipt=[tag |-> "NestedBarrierInstructionReturn",instruction |-> InstructionWindowRef93(parentPlan),invocation |-> p.invocation.id, instance |-> r.id,source |-> r.ability.source,barrierInstruction |-> p.barrierInstruction,complete |-> TRUE, disposition |-> "Resolved",finalCheckpoint |-> r.checkpoint] /\ ReturnAbility9(r.ability,[r.ability EXCEPT !.returned=TRUE],TRUE,p.caller) /\ afterCalls=[beforeCalls EXCEPT ![p.invocation.id].status="Returned",![p.invocation.id].disposition="Resolved"] /\ afterRuntime=[r EXCEPT !.ability.returned=TRUE,!.phase="Returned"] ReturnMidItemInspectionOccurrence912(beforeStack,afterStack,r,afterRuntime,afterProcedure,receipt,objects,transits,a,afterItemInspection,lifetimes,authority) == /\ LifetimeReady910(lifetimes,authority) /\ OccurrenceOwnerCurrent912(r,authority) /\ r.id \in authority.current.finishedInstances /\ SourceOccurrenceBound912(r) /\ r.metadata.sourceEntry.kind="Paid" /\ r.phase="Complete" /\ r.pc=0 /\ r.checkpoint \in Nat \ {0} /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ LET p == [r.metadata.sourceEntry.after EXCEPT !.ability=r.ability,!.phase="Complete",!.checkpoint=r.checkpoint] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ FinishPaidMidItemInspection95(beforeStack,afterStack,p,afterProcedure,receipt,a,afterItemInspection) /\ afterRuntime=[r EXCEPT !.ability=afterProcedure.ability,!.phase="Returned"] PublishOccurrenceAdoption912(beforeRegistry,afterRegistry,beforeAuthority,afterAuthority,beforeRuntime,afterRuntime,spec, beforeContext,afterContext,origin,ledger,world,cardFacts) == /\ AdoptOccurrenceRuntime912(beforeRuntime,afterRuntime,spec,beforeContext,origin,ledger,world,beforeRegistry,beforeAuthority,cardFacts) /\ LET next == afterAuthority.current execution == [tag |-> "CurrentCharacteristicsEvaluation",id |-> beforeContext.id,snapshotId |-> next.id,source |-> RuleAbilitySource9("ProcedureCode29f759d7ea55")] IN /\ next=[beforeAuthority.current EXCEPT !.id=next.id, !.activity.instances[beforeRuntime.id].owner=OccurrenceLookOwner912(afterRuntime)] /\ CommitLifetimeKernelCore910(beforeAuthority,afterAuthority,next,execution) /\ PublishNextLifetime910(beforeRegistry,afterRegistry,afterAuthority) /\ ObserveResolvingLifetimeContext910(beforeContext,afterContext,afterRegistry,afterAuthority,origin) GrantOccurrenceInstructionLook912(before,after,id,r,plan,objects,deck,execution,lifetimes,authority) == /\ OccurrenceRuntimeProfile912(r) /\ r.phase="Resolve" /\ r.pause.id=0 /\ OccurrencePlan912(r,plan) /\ GrantCurrentInstructionLook911(before,after,id,OccurrenceLookOwner912(r),plan,objects,deck,execution,authority.current.cardFacts,lifetimes,authority) CompletePaidOccurrenceCheckpoint912(before,after,ledger,stack,receipt,objects,transits,lifetimes,authority) == /\ SourceOccurrenceBound912(before) /\ before.metadata.sourceEntry.kind="Paid" /\ objects=authority.current.objects /\ SetAsideTrackingValid4(objects,transits) /\ OccurrenceAtTop912(stack,before) /\ LET p == [before.metadata.sourceEntry.after EXCEPT !.ability=before.ability] IN /\ PaidConvertedAsideIds95(p,objects,transits)={} /\ before.current=0 => PaidCleanupIds95(p,objects,transits,"ProcedureCode76ca53ad9dd0") \cup PaidCleanupIds95(p,objects,transits,"ProcedureCode96bfa1b6a970")={} /\ CompleteOccurrenceCheckpoint912(before,after,ledger,stack,receipt,lifetimes,authority) OpenChapterRegistry912(authority,registry) == LET base == ReplacementOverlay99(NewLingeringRegistry910,[frontier |-> LifetimeFrontier910(authority,1)]) IN /\ OpenObservedLingering910(authority,base) /\ registry=NewPersistentRegistry912(base) /\ PersistentRegistryWorldBound912(registry,authority.current) ChapterExpectedWorld912(registry,world,ledger,authority,cardFacts) == /\ PersistentWorldBound912(registry,world,ledger,authority) /\ cardFacts=authority.current.cardFacts /\ CurrentInterruptWorld99(world,ledger,cardFacts) BeginChapterExpected912(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,ledger,registry,authority) == /\ ChapterExpectedWorld912(registry,world,ledger,authority,cardFacts) /\ CASE entry.tag="ActualOccurrenceInstructionEntry" -> BeginOccurrenceExpected912(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,registry,authority) [] entry.tag="ActualGraphInstructionEntry" -> BeginRuntimeExpectedContext911(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation,registry,authority) [] OTHER -> BeginExpectedContext99(before,after,id,origin,world,entry,description,projection,initial,owner,cardFacts, beforeWould,afterWould,observation) PublishChapterOccurrenceAdoption912(beforeRegistry,afterRegistry,beforeAuthority,afterAuthority,beforeRuntime,afterRuntime,spec, beforeContext,afterContext,origin,ledger,world,cardFacts) == /\ ChapterExpectedWorld912(beforeRegistry,world,ledger,beforeAuthority,cardFacts) /\ PublishOccurrenceAdoption912(beforeRegistry,afterRegistry,beforeAuthority,afterAuthority,beforeRuntime,afterRuntime,spec, beforeContext,afterContext,origin,ledger,world,cardFacts) =============================================================================