fix(battle-node): reflect PvP Judge back to its sender (turn handover)
Live two-client run (data_dumps/captures/battle_test) exposed a turn-handover
stall: ending a turn on client A made BOTH clients show A's turn again; the
opponent never got a turn. Root cause: JudgeHandler routed the {spin:0} Judge to
ctx.Other. The client rule is 'receive opponent TurnEnd -> SendJudge', so the
PASSIVE player (the one taking over the turn) is the Judge sender, and 'receive
Judge -> ControlTurnStartPlayer' starts the RECEIVER's turn. Routing to ctx.Other
delivered the Judge to the player who had just ended their turn, restarting it in
a closed loop while the taker-over sat on 'Opponent's Turn'.
Fix: the PvP Judge {spin} reflects back to ctx.From (the sender / turn taker-over),
matching the Bot arm's existing 'Judge to sender only' handover. The sender then
emits TurnStart, which relays to the opponent as {spin}. Updated the dispatch unit
test and the PvpHandshakeAndGameplay integration test to the real handover order
(passive sends Judge -> receives it back -> sends TurnStart -> opponent sees it).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,12 +11,17 @@ internal sealed class JudgeHandler : IFrameHandler
|
||||
if (ctx.IsScriptedBot(ctx.From))
|
||||
return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) };
|
||||
|
||||
// PvP: active player's Judge{battleCode} -> opponent {spin} (RNG catch-up; spin=0 for the
|
||||
// deterministic-turn slice). Receiving Judge starts the opponent's own turn.
|
||||
// PvP: Judge is the handover gate. The player who sends Judge is the one TAKING OVER the
|
||||
// turn (the client rule is: receive opponent TurnEnd -> SendJudge). Receiving Judge{spin}
|
||||
// fires ControlTurnStartPlayer ("start MY turn"), so the {spin} must REFLECT BACK to the
|
||||
// sender — NOT go to the opponent (that would make the player who just ended their turn
|
||||
// start another one, stalling the loop; confirmed by the 2026-06-03 two-client capture).
|
||||
// The sender then emits TurnStart, which TurnStartHandler relays to the opponent as {spin}.
|
||||
// battleCode is dropped; spin=0 for the deterministic-turn slice.
|
||||
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
|
||||
{
|
||||
var frame = ctx.Env with { Body = new JudgeBody(Spin: 0) };
|
||||
return new[] { new DispatchRoute(ctx.Other, frame, false) };
|
||||
return new[] { new DispatchRoute(ctx.From, frame, false) };
|
||||
}
|
||||
|
||||
return Array.Empty<DispatchRoute>();
|
||||
|
||||
@@ -17,9 +17,9 @@ internal sealed class TurnEndHandler : IFrameHandler
|
||||
{
|
||||
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
|
||||
{
|
||||
// Opponent sees {turnState}; receiving TurnEnd drives its SendJudge (handover gate).
|
||||
// battleCode/actionSeq/cemetery are dropped. The paired Judge{spin} is emitted by
|
||||
// JudgeHandler when the active player sends its own Judge frame.
|
||||
// Opponent sees {turnState}; receiving TurnEnd drives ITS SendJudge (handover gate):
|
||||
// the opponent (the turn taker-over) then sends a Judge, which JudgeHandler reflects
|
||||
// back to it to start its turn. battleCode/actionSeq/cemetery are dropped.
|
||||
var te = ctx.Env with { Body = new TurnEndBody(TurnState: 0) };
|
||||
return new[] { new DispatchRoute(ctx.Other, te, false) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user