refactor(battlenode): engine-first token identity (cardId); keep wire-mining fallback (M-HC-4f, partial)

Source the played card's opponent-facing knownList[].cardId off the shadow engine
(SessionBattleEngine.PlayedCardId -> BattleCardBase.CardId), engine-first with the
wire-mined idx->cardId map as the fallback. PROVEN engine-resolved (each backed by a
HeadlessConductorTests PlayedCardId_* test): deck cards and receive-path substituted/
revealed tokens (engine seats the wire id at the wire idx).

PARTIAL retirement: the wire-mining bookkeeping (MineAddOps/MineChoicePicks/MineCopyTokens
+ Record*From) is KEPT as the load-bearing fallback. The choice/Discover, copy/clone and
cross-side (isSelf:0) token cases are NOT proven to resolve at a wire idx headless — the
autonomous token_draw path seats a chosen token at engine Index 0 (would collide with the
leader), and copy/cross-side aren't cheaply fixturable. Deleting their mining on faith
would silently corrupt opponent reveals, so it stays behind a TODO(M-HC-4f) gate.

- SessionBattleEngine.PlayedCardId: new accessor mirroring PlayedCardClan/Tribe.
- BuildPlayedCard: signature deckMap->explicit cardId; null on cardId==0 (no engine id AND
  no mined/deck-map fallback).
- PlayActionsHandler: cardId = engine.PlayedCardId(seat, idx, fallback: mapped) ; mining retained.
- Tests: PlayedCardId_* (deck/substituted/degrade pass; choice-gap [Explicit] documents the
  Index-0 finding). KnownListBuilder + CaptureConformance call-sites updated to new signature.

Full BattleNode suite 263/263 green; HeadlessConductorTests 27/27; drift clean; no Engine edits.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-07 00:36:49 -04:00
parent d3508d7bd4
commit a30a496265
8 changed files with 219 additions and 52 deletions

View File

@@ -3,13 +3,16 @@ using SVSim.BattleNode.Protocol.Bodies;
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
/// <summary>PvP PlayActions translator. Synthesizes the opponent-facing knownList from the sender's
/// idx->cardId map + the orderList move op, renames targetList -> oppoTargetList, drops orderList,
/// and forwards a stripped keyAction for choice/Discover plays ({type,cardId}; selectCard dropped
/// for a hidden open:0 pick). Token plays resolve their cardId from add ops (concrete tokens),
/// keyAction.selectCard (choice picks), or a baseIdx copy resolved against the side's map — all mined
/// on earlier (or the same) frames; an un-generated token idx still degrades to {playIdx,type}
/// (no knownList). Bot drop (no rule).</summary>
/// <summary>PvP PlayActions translator. Synthesizes the opponent-facing knownList from the engine-resolved
/// played card + the orderList move op, renames targetList -> oppoTargetList, drops orderList, and forwards a
/// stripped keyAction for choice/Discover plays ({type,cardId}; selectCard dropped for a hidden open:0 pick).
/// The played card's IDENTITY (cardId), cost, spellboost, clan and tribe are all ENGINE-sourced (M-HC-3/4);
/// the identity is engine-first with a wire-mined idx->cardId fallback (deck card or recorded token). The
/// fallback still covers the token cases the engine doesn't headlessly resolve at a wire idx — choice/Discover
/// picks (keyAction.selectCard), baseIdx copies, and cross-side (isSelf:0) gifts — all WIRE-MINED on earlier
/// (or the same) frames via the Record*From calls below (TODO(M-HC-4f): retire once engine-proven at a wire
/// idx). An un-resolvable token idx (no engine id, no mined entry) degrades to {playIdx,type} (no knownList).
/// Bot drop (no rule).</summary>
internal sealed class PlayActionsHandler : IFrameHandler
{
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
@@ -39,6 +42,10 @@ internal sealed class PlayActionsHandler : IFrameHandler
ctx.State.RecordCopyTokensFrom(ctx.From, ctx.Other, orderList);
var deckMap = ctx.State.GetOrSeedDeckMap(ctx.From);
// The wire-mined idx->cardId fallback identity (deck card, or a token recorded into the map above by
// the Record*From calls). Used ONLY as the engine-read's fallback below — 0 when the idx isn't in the map.
long mappedCardId = deckMap.TryGetValue(playIdx, out var mid) ? mid : 0L;
// The ENGINE-RESOLVED play-time cost (M-HC-3a). The conductor's ShadowIngest already ran
// engine.Receive for THIS frame before this handler runs, so the engine has resolved the play and
// PlayedCardCost reads the discounted cost it actually charged (spellboost + board modifiers folded
@@ -63,8 +70,22 @@ internal sealed class PlayActionsHandler : IFrameHandler
int playedClan = ctx.Engine.PlayedCardClan(senderSeat, playIdx, fallback: 0);
string playedTribe = ctx.Engine.PlayedCardTribe(senderSeat, playIdx, fallback: "0");
// The card IDENTITY is now ALSO engine-sourced (M-HC-4f): read the engine-resolved CardId off the played
// card, falling back to the wire-mined idx->cardId map when the engine doesn't resolve it. PROVEN
// engine-resolved (each backed by a HeadlessConductorTests PlayedCardId_* test): a DECK card and a
// receive-path SUBSTITUTED/revealed token (the engine seats the wire id at the wire idx). The fallback
// is LOAD-BEARING, not vestigial: it still supplies the identity for (a) a non-engine session (gate not
// acquired) and (b) the token cases the engine doesn't headlessly resolve AT A WIRE IDX — choice/Discover
// tokens (autonomous token_draw seats them at engine Index 0 headless), copy/clone tokens, and cross-side
// (isSelf:0) gifts. Those remain WIRE-MINED via the Record*From calls above; retiring that mining is gated
// on proving the engine seats them at a wire idx, which the current headless harness can't fixture cheaply.
// TODO(M-HC-4f): once a node-native (or full wire add-op/replace) fixture proves the engine resolves a
// choice token, a copy token and a cross-side gift at their WIRE idx, retire MineChoicePicks/MineCopyTokens/
// the cross-side MineAddOps branch + the matching Record* bookkeeping and drop this fallback to deck-only.
long playedCardId = ctx.Engine.PlayedCardId(senderSeat, playIdx, fallback: mappedCardId);
var played = KnownListBuilder.BuildPlayedCard(
deckMap, playIdx, orderList, cost: playedCost, spellboost: playedSpellboost,
playIdx, playedCardId, orderList, cost: playedCost, spellboost: playedSpellboost,
clan: playedClan, tribe: playedTribe);
var oppoTargets = KnownListBuilder.RenameTargets(entries.GetValueOrDefault(WireKeys.TargetList));