feat(admin): add hex grid controls and block same-AI match creation

AiMatchPage:
- Add Grid Type dropdown (Square / Hexagon) and HexSides input (shown
  only when Hexagon selected) to the Board section, wired to GridType
  and HexSides in GameRules.
- Add SameAi computed property: true when both players share the same
  difficulty + strategy (i.e. resolve to the same account GUID).
- Show a warning banner and disable the Create button when SameAi,
  preventing the broken game state that occurs when a player is matched
  against itself.

AiMatchService:
- Server-side guard: throw ArgumentException if id1 == id2 so the
  broken state is impossible even if the UI check is bypassed.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-04-14 20:39:31 -04:00
co-authored by Claude Happy
parent a814d2bdb9
commit affd251b10
2 changed files with 33 additions and 1 deletions
@@ -58,6 +58,12 @@
</div>
</div>
</div>
@if (SameAi)
{
<div class="alert alert-warning mt-3 mb-0">
Both players resolve to the same AI account. Change the difficulty or strategy for one player.
</div>
}
</div>
</div>
@@ -132,6 +138,20 @@
<input type="number" class="form-control" min="2" max="32" @bind="_rules.BoardHeight" />
</div>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Grid Type</label>
<select class="form-select" @bind="_rules.GridType">
<option value="Square">Square</option>
<option value="Hexagon">Hexagon</option>
</select>
</div>
@if (_rules.GridType == "Hexagon")
{
<div class="mb-3">
<label class="form-label fw-semibold">Hex Sides <span class="text-muted small">(4 or 6)</span></label>
<input type="number" class="form-control" min="4" max="6" step="2" @bind="_rules.HexSides" />
</div>
}
<div class="mb-3">
<label class="form-label fw-semibold">Board Shape</label>
<select class="form-select" @bind="_rules.BoardShape">
@@ -201,7 +221,7 @@
<!-- Create button -->
<div class="d-flex gap-2 mb-5">
<button class="btn btn-primary" @onclick="CreateAsync" disabled="@_busy">
<button class="btn btn-primary" @onclick="CreateAsync" disabled="@(_busy || SameAi)">
@if (_busy) { <span class="spinner-border spinner-border-sm me-1"></span> }
Create Match
</button>
@@ -265,6 +285,9 @@
9 => "Legend", 10 => "Mythic", _ => d.ToString(),
};
// True when both players map to the same AI account (identical difficulty + strategy).
private bool SameAi => _diff1 == _diff2 && _strategy1 == _strategy2;
private void ResetRules() => _rules = new();
private async Task CreateAsync()
@@ -293,6 +316,8 @@
MpBuff = _rules.MpBuff,
StartingRandomTilePct = _rules.StartingRandomTilePct,
BoardShape = _rules.BoardShape,
GridType = _rules.GridType,
HexSides = _rules.GridType == "Hexagon" ? _rules.HexSides : 0,
};
var (sessionId, p1Name, p2Name) = await MatchService.CreateMatchAsync(
@@ -337,6 +362,8 @@
public int MpBuff { get; set; } = 0;
public int StartingRandomTilePct { get; set; } = 0;
public string BoardShape { get; set; } = "Default";
public string GridType { get; set; } = "Square";
public int HexSides { get; set; } = 6;
}
private sealed record MatchRecord(
@@ -62,6 +62,11 @@ public sealed class AiMatchService
var id1 = AiAccountSeeder.AccountId(difficulty1, strategy1);
var id2 = AiAccountSeeder.AccountId(difficulty2, strategy2);
if (id1 == id2)
throw new ArgumentException(
"Both players resolve to the same AI account. " +
"Change the difficulty or strategy for one of the players.");
var deckId1 = await _deckResolver.ResolveAsync(id1, difficulty1, ct);
var deckId2 = await _deckResolver.ResolveAsync(id2, difficulty2, ct);