feat(battle-node): derive Matched.seed + Ready.idxChangeSeed from master seed
InitBattle now emits Stable(master) as the shared effect seed and the master- shuffled deck as selfDeck; Swap emits each recipient's per-side IdxChange seed. BattleSession exposes + logs the master seed per battle for future replay. Updated lifecycle/dispatch/integration tests (deck assertions now permutation- based since selfDeck is shuffled). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,10 @@ public sealed class BattleSession
|
||||
|
||||
private readonly BattleSessionState _state = new();
|
||||
|
||||
/// <summary>The per-battle master seed (see <see cref="BattleSessionState.MasterSeed"/>).
|
||||
/// Exposed for logging + future replay persistence.</summary>
|
||||
public int MasterSeed => _state.MasterSeed;
|
||||
|
||||
public string BattleId { get; }
|
||||
public BattleType Type { get; }
|
||||
public IBattleParticipant A { get; }
|
||||
@@ -71,6 +75,8 @@ public sealed class BattleSession
|
||||
B = b;
|
||||
_log = log;
|
||||
|
||||
_log.LogInformation("BattleSession {Bid}: master seed {Seed}", BattleId, _state.MasterSeed);
|
||||
|
||||
// Subscribe to both participants' emissions.
|
||||
A.FrameEmitted += OnFrameFromA;
|
||||
B.FrameEmitted += OnFrameFromB;
|
||||
|
||||
@@ -25,7 +25,8 @@ internal sealed class InitBattleHandler : IFrameHandler
|
||||
{
|
||||
new(ctx.From, ServerBattleFrames.BuildMatched(
|
||||
ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, ctx.Other.ViewerId,
|
||||
ctx.BattleId, BattleFrameDefaults.BattleSeed), false),
|
||||
ctx.BattleId, BattleSeeds.Stable(ctx.State.MasterSeed),
|
||||
ctx.State.GetShuffledDeck(ctx.From)), false),
|
||||
};
|
||||
ctx.SenderPhase = BattleSessionPhase.AwaitingLoaded;
|
||||
return r;
|
||||
|
||||
@@ -27,10 +27,11 @@ internal sealed class SwapHandler : IFrameHandler
|
||||
foreach (var p in swappers)
|
||||
{
|
||||
var opponent = ReferenceEquals(p, ctx.A) ? ctx.B : ctx.A;
|
||||
var idxSeed = BattleSeeds.IdxChange(ctx.State.MasterSeed, p.ViewerId);
|
||||
var ready = opponent is IHasHandshakePhase
|
||||
&& ctx.State.PostSwapHands.TryGetValue(opponent, out var oppoHand)
|
||||
? ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p], oppoHand)
|
||||
: ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p]);
|
||||
? ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p], oppoHand, idxSeed)
|
||||
: ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p], idxSeed);
|
||||
routes.Add(new DispatchRoute(p, ready, false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user