feat(battlenode): SessionBattleEngine skeleton + types (Phase 2 N0)
SessionContentsCreator mirrors the test HeadlessContentsCreator fully (all IBattleMgrContentsCreator members) so it compiles; Setup/Receive throw pending the Task 3/4 probes. New files use the 'engine' extern alias. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
9
SVSim.BattleNode/Sessions/Engine/EngineIngestResult.cs
Normal file
9
SVSim.BattleNode/Sessions/Engine/EngineIngestResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace SVSim.BattleNode.Sessions.Engine;
|
||||
|
||||
/// <summary>Outcome of feeding one client frame to the engine (design ND6). A divergence/reject is a
|
||||
/// DETECTED-DESYNC EVENT surfaced to the caller — never silently absorbed. Phase-2 policy: log.</summary>
|
||||
internal sealed record EngineIngestResult(bool Accepted, bool Diverged, string? RejectReason)
|
||||
{
|
||||
public static EngineIngestResult Ok() => new(Accepted: true, Diverged: false, RejectReason: null);
|
||||
public static EngineIngestResult Reject(string reason) => new(Accepted: false, Diverged: true, RejectReason: reason);
|
||||
}
|
||||
28
SVSim.BattleNode/Sessions/Engine/SessionBattleEngine.cs
Normal file
28
SVSim.BattleNode/Sessions/Engine/SessionBattleEngine.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
extern alias engine;
|
||||
using engine::SVSim.BattleEngine.Rng;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Engine;
|
||||
|
||||
/// <summary>One authoritative engine per BattleSession, seated as both players (design ND2). A faithful
|
||||
/// SHADOW: it mirrors each client's resolved play, never overrides/rejects/originates (ND1). Ingest is
|
||||
/// the engine's own NetworkBattleReceiver.ReceivedMessage (ND4); isPlayer selects the seat (F-N-2).</summary>
|
||||
internal sealed class SessionBattleEngine
|
||||
{
|
||||
private HeadlessNetworkBattleMgr? _mgr;
|
||||
|
||||
/// <summary>True once Setup has built the two-seat battle.</summary>
|
||||
public bool IsReady => _mgr is not null;
|
||||
|
||||
/// <summary>Construct the two-seat network battle from both decks + the master seed (design F-N-5).
|
||||
/// <paramref name="seatADeck"/>/<paramref name="seatBDeck"/> are the per-side deck orders the node
|
||||
/// already computed (BattleSessionState.GetShuffledDeck) and handed each client.</summary>
|
||||
public void Setup(int masterSeed,
|
||||
IReadOnlyList<long> seatADeck, IReadOnlyList<long> seatBDeck)
|
||||
=> throw new NotImplementedException("Filled by Task 3 (construction probe).");
|
||||
|
||||
/// <summary>Ingest one client frame into the engine for the given seat. <paramref name="isPlayerSeat"/>
|
||||
/// maps the sender to the engine's player(true)/opponent(false) seat (F-N-2).</summary>
|
||||
public EngineIngestResult Receive(MsgEnvelope env, bool isPlayerSeat)
|
||||
=> throw new NotImplementedException("Filled by Task 4 (ingest probe).");
|
||||
}
|
||||
40
SVSim.BattleNode/Sessions/Engine/SessionContentsCreator.cs
Normal file
40
SVSim.BattleNode/Sessions/Engine/SessionContentsCreator.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
extern alias engine;
|
||||
using engine::Wizard.BattleMgr;
|
||||
using engine::Wizard.Battle.Phase;
|
||||
using engine::Wizard.Battle.Recovery;
|
||||
using engine::Wizard.Battle.Replay;
|
||||
using engine::Wizard.Battle.Resource;
|
||||
using engine::Wizard.Battle.View.Vfx;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Engine;
|
||||
|
||||
/// <summary>The node's production IBattleMgrContentsCreator. Mirrors the test-side
|
||||
/// HeadlessContentsCreator (HeadlessFixture.cs) but carries the per-battle master seed so the
|
||||
/// engine's RNG stream is born aligned with the seed the node handed both clients (design F-N-5).
|
||||
/// The non-RandomSeed members are the no-op recovery/replay/resource/vfx/phase creators the
|
||||
/// NetworkStandardBattleMgr ctor dereferences — the engine's own Null* implementations, same set the
|
||||
/// headless test harness uses.</summary>
|
||||
internal sealed class SessionContentsCreator : IBattleMgrContentsCreator
|
||||
{
|
||||
public SessionContentsCreator(int masterSeed) => RandomSeed = masterSeed;
|
||||
|
||||
public int RandomSeed { get; }
|
||||
|
||||
// No-op managers: the ctor's FirstRecoverySetting/FirstReplaySetting dereference these; recovery/
|
||||
// replay recording is irrelevant to a shadow engine, so use the engine's own null implementations.
|
||||
public IRecoveryManager RecoveryManager { get; } = new NullRecoveryManager();
|
||||
public IRecoveryRecordManager RecoveryRecordManager { get; } = new NullRecoveryRecordManager();
|
||||
public IReplayRecordManager ReplayRecordManager { get; } = new NullReplayRecordManager();
|
||||
|
||||
public IBattleResourceMgr CreateResourceMgr() => new BattleResourceMgr();
|
||||
public VfxMgr CreateVfxMgr() => new VfxMgr();
|
||||
public IPhaseCreator CreatePhaseCreator(engine::BattleManagerBase battleMgr) =>
|
||||
new SessionPhaseCreator(battleMgr);
|
||||
}
|
||||
|
||||
/// <summary>Node analogue of the test HeadlessPhaseCreator / the engine's SingleBattlePhaseCreator
|
||||
/// (cut from the M1 copy set as an entry-point ctor): inherits PhaseCreatorBase wholesale.</summary>
|
||||
internal sealed class SessionPhaseCreator : PhaseCreatorBase
|
||||
{
|
||||
public SessionPhaseCreator(engine::BattleManagerBase battleMgr) : base(battleMgr) { }
|
||||
}
|
||||
Reference in New Issue
Block a user