Implement SOR.Ai Phase 1: project scaffold, transport, seeding, lobby handlers, session manager

- New SOR.Ai project with AI account/deck seeding (50 accounts: 10 difficulty × 5 strategy)
- AiNoOpClientConnection + AiClientMessage: AI invokes game handlers in-process
- AiPlayerSessionManager: BackgroundService subscribing to GameStarted/AiTurnStarted/GameEnded
- AiPlayerSession: sends game.ready and executes turns (Phase 1 stub: pass immediately)
- Lobby handlers: game.ai.add, game.ai.remove, game.ai.configure
- IAiAccountRegistry in SOR.Shared to break circular dependency with SOR.Game
- GameEndTurnHandler + GameReadyHandler publish AiTurnStarted event when AI is active player
- Account entity: IsAi, AiDifficulty, AiStrategy columns
- CustomLobby entity: AiSlotsJson column

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-12 15:13:38 -04:00
co-authored by Claude Happy
parent c3a39fd7a1
commit 139ba5fbf0
28 changed files with 1738 additions and 2 deletions
@@ -0,0 +1,54 @@
namespace SOR.Ai.Seeding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SOR.Ai.Core;
using SOR.Database.Contexts;
/// <summary>
/// One-shot IHostedService that runs at startup before the server accepts traffic.
/// Seeds AI accounts and decks, then loads the AiAccountRegistry so other services
/// can check IsAi without hitting the database on every turn.
/// </summary>
internal sealed class AiSeedStartupService : IHostedService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly AiAccountRegistry _registry;
private readonly ILogger<AiSeedStartupService> _logger;
public AiSeedStartupService(
IServiceScopeFactory scopeFactory,
AiAccountRegistry registry,
ILogger<AiSeedStartupService> logger)
{
_scopeFactory = scopeFactory;
_registry = registry;
_logger = logger;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
await using var scope = _scopeFactory.CreateAsyncScope();
var sp = scope.ServiceProvider;
var identityDb = sp.GetRequiredService<SorIdentityDbContext>();
var collectionDb = sp.GetRequiredService<CollectionDbContext>();
var catalogDb = sp.GetRequiredService<CatalogDbContext>();
// 1. Seed AI accounts (idempotent).
await AiAccountSeeder.SeedAsync(identityDb, _logger, cancellationToken);
// 2. Seed AI decks (idempotent; skips gracefully if catalog cards missing).
await AiDeckSeeder.SeedAsync(identityDb, collectionDb, catalogDb, _logger, cancellationToken);
// 3. Populate in-memory registry for O(1) IsAi checks.
_registry.Load(identityDb);
_logger.LogInformation(
"SOR.Ai: startup seed complete. {Count} AI accounts registered.",
_registry.Count);
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}