fix(ranked-ai): randomize bot selection and seed for AI fallback matches
Bot roster pick was hashing (UserName, ClassId) — same player always faced the same bot class. Now hashes battleId so different matches get different opponents while retries of the same pending battle stay consistent. AI start response hardcoded Seed=0 for both sides, so the client's deck shuffle/mulligan/draw RNG was deterministic every match. The BattleNode's per-battle MasterSeed (Random.Shared) was never sent to bot-mode clients because InitBattleHandler skips the Matched frame. Now populates Seed with Random.Shared.Next() on the HTTP response. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -162,7 +162,8 @@ public sealed class RankBattleController : ControllerBase
|
||||
}
|
||||
var selfCtx = pending.P1.Context;
|
||||
|
||||
var bot = await _botRoster.PickAsync(selfCtx, ct);
|
||||
var bot = await _botRoster.PickAsync(selfCtx, pending.BattleId, ct);
|
||||
var seed = Random.Shared.Next();
|
||||
|
||||
// Per spec, ai-start.md TODO: turnState semantics unclear. Default 0 (player first).
|
||||
return Ok(new AiBattleStartResponseDto
|
||||
@@ -179,7 +180,7 @@ public sealed class RankBattleController : ControllerBase
|
||||
FieldId = selfCtx.FieldId,
|
||||
IsOfficial = selfCtx.IsOfficial,
|
||||
OppoId = bot.AiId,
|
||||
Seed = 0,
|
||||
Seed = seed,
|
||||
Rank = 0,
|
||||
BattlePoint = 0,
|
||||
ClassId = int.TryParse(selfCtx.ClassId, out var cId) ? cId : -1,
|
||||
@@ -197,7 +198,7 @@ public sealed class RankBattleController : ControllerBase
|
||||
FieldId = bot.FieldId,
|
||||
IsOfficial = bot.IsOfficial,
|
||||
OppoId = (int)vid,
|
||||
Seed = 0,
|
||||
Seed = seed,
|
||||
Rank = bot.Rank,
|
||||
BattlePoint = bot.BattlePoint,
|
||||
ClassId = bot.ClassId,
|
||||
|
||||
Reference in New Issue
Block a user