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:
gamer147
2026-06-03 18:45:17 -04:00
parent c360d639f2
commit e98bd10dbe
4 changed files with 29 additions and 15 deletions

View File

@@ -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) };
}