Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4)#313
Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4)#313christiannagel merged 7 commits intomainfrom
Conversation
|
@christiannagel 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: christiannagel <1908285+christiannagel@users.noreply.github.com>
Co-authored-by: christiannagel <1908285+christiannagel@users.noreply.github.com>
|
@copilot with the Game5x5x4 game, the result returned after a move can be black, white, and blue. One more option than for the other game types. |
Co-authored-by: christiannagel <1908285+christiannagel@users.noreply.github.com>
You're absolutely right! I've now added support for the blue result type that's specific to Game5x5x4. The bot now correctly handles all three result types:
Added Commit: 653ac56 |
Updated Cosmos DB connection strings to use "codebreaker" key. Removed inline database creation logic, delegating it to AppHost. Refactored Event Hub setup for clarity and added a new Cosmos container "GamesV3". Introduced new projects `CodeBreaker_Bot` and `Codebreaker_BotQ` with appropriate references and settings. Removed `CodeBreaker_Blazor` project configuration. Commented out RankingsContext database creation logic. Added TODOs for future updates and performed general cleanup.
A new test method, `HandleBlueMatches_ShouldHandleNoMatches`, was added to the `CodeBreakerAlgorithmsTests` class. This test validates the behavior of the system when no matches occur by using a `List<int>` with binary values representing "miss" cases. This improves test coverage and ensures robustness of the `HandleBlueMatches` functionality.
Refactored the `ApplicationServices` class to simplify Cosmos DB context configuration by replacing `AddDbContext` with `AddCosmosDbContext` and introducing a scoped service registration for `IGamesRepository` using `DataContextProxy<GamesCosmosContext>`. Removed `EnrichCosmosDbContext` and commented out old configuration code for reference. Added a new `DataContextProxy<TContext>` class to act as a proxy for `IGamesRepository`, delegating repository operations to the underlying `DbContext`. This improves flexibility and decouples the repository interface from specific database context implementations.
The Codebreaker.Bot API service previously only supported Game6x4 (6 possible colors, 4 fields). This PR extends the bot algorithm and API to support two additional game types while maintaining full backward compatibility.
New Game Types Supported
Key Changes
API Enhancement
The bot creation endpoint now accepts an optional
gameTypeparameter:Algorithm Updates
Extended the core bit manipulation algorithm to handle:
The algorithm maintains the original 6-bit field representation and XOR-based approach while adapting to different game configurations.
Shape+Color Combination Handling
For Game5x5x4, the bot properly handles shape and color field values by creating combination strings in the format
"{shape};{color}"and mapping them to the algorithm's bit patterns.Game Result Processing
Enhanced result processing to handle different result types by game:
Backward Compatibility
All existing API calls continue to work unchanged. The
gameTypeparameter defaults toGame6x4, ensuring no breaking changes for existing integrations.Testing
Added comprehensive unit tests covering:
The bot can now play against itself in all three game types and return correct results, enabling broader testing and demonstration of the Codebreaker system's capabilities.
Fixes #312.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.