diff --git a/SVSim.BattleEngine.Tests/SVSim.BattleEngine.Tests.csproj b/SVSim.BattleEngine.Tests/SVSim.BattleEngine.Tests.csproj index 83a312d..b8073e2 100644 --- a/SVSim.BattleEngine.Tests/SVSim.BattleEngine.Tests.csproj +++ b/SVSim.BattleEngine.Tests/SVSim.BattleEngine.Tests.csproj @@ -18,6 +18,7 @@ + diff --git a/SVSim.BattleEngine.Tests/SessionEngine/SessionEngineConstructionTests.cs b/SVSim.BattleEngine.Tests/SessionEngine/SessionEngineConstructionTests.cs new file mode 100644 index 0000000..402efb7 --- /dev/null +++ b/SVSim.BattleEngine.Tests/SessionEngine/SessionEngineConstructionTests.cs @@ -0,0 +1,17 @@ +using System.Linq; +using NUnit.Framework; +using SVSim.BattleNode.Sessions.Engine; + +namespace SVSim.BattleEngine.Tests.SessionEngine +{ + [TestFixture] + public class SessionEngineConstructionTests + { + [Test] + public void SessionBattleEngine_instantiates_and_is_not_ready_before_setup() + { + var engine = new SessionBattleEngine(); + Assert.That(engine.IsReady, Is.False); + } + } +} diff --git a/SVSim.BattleNode/Sessions/Engine/EngineIngestResult.cs b/SVSim.BattleNode/Sessions/Engine/EngineIngestResult.cs new file mode 100644 index 0000000..a275713 --- /dev/null +++ b/SVSim.BattleNode/Sessions/Engine/EngineIngestResult.cs @@ -0,0 +1,9 @@ +namespace SVSim.BattleNode.Sessions.Engine; + +/// 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. +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); +} diff --git a/SVSim.BattleNode/Sessions/Engine/SessionBattleEngine.cs b/SVSim.BattleNode/Sessions/Engine/SessionBattleEngine.cs new file mode 100644 index 0000000..f3dbf2c --- /dev/null +++ b/SVSim.BattleNode/Sessions/Engine/SessionBattleEngine.cs @@ -0,0 +1,28 @@ +extern alias engine; +using engine::SVSim.BattleEngine.Rng; +using SVSim.BattleNode.Protocol; + +namespace SVSim.BattleNode.Sessions.Engine; + +/// 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). +internal sealed class SessionBattleEngine +{ + private HeadlessNetworkBattleMgr? _mgr; + + /// True once Setup has built the two-seat battle. + public bool IsReady => _mgr is not null; + + /// Construct the two-seat network battle from both decks + the master seed (design F-N-5). + /// / are the per-side deck orders the node + /// already computed (BattleSessionState.GetShuffledDeck) and handed each client. + public void Setup(int masterSeed, + IReadOnlyList seatADeck, IReadOnlyList seatBDeck) + => throw new NotImplementedException("Filled by Task 3 (construction probe)."); + + /// Ingest one client frame into the engine for the given seat. + /// maps the sender to the engine's player(true)/opponent(false) seat (F-N-2). + public EngineIngestResult Receive(MsgEnvelope env, bool isPlayerSeat) + => throw new NotImplementedException("Filled by Task 4 (ingest probe)."); +} diff --git a/SVSim.BattleNode/Sessions/Engine/SessionContentsCreator.cs b/SVSim.BattleNode/Sessions/Engine/SessionContentsCreator.cs new file mode 100644 index 0000000..900f46a --- /dev/null +++ b/SVSim.BattleNode/Sessions/Engine/SessionContentsCreator.cs @@ -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; + +/// 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. +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); +} + +/// Node analogue of the test HeadlessPhaseCreator / the engine's SingleBattlePhaseCreator +/// (cut from the M1 copy set as an entry-point ctor): inherits PhaseCreatorBase wholesale. +internal sealed class SessionPhaseCreator : PhaseCreatorBase +{ + public SessionPhaseCreator(engine::BattleManagerBase battleMgr) : base(battleMgr) { } +}