Skip to content

Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4)#313

Merged
christiannagel merged 7 commits intomainfrom
copilot/fix-312
Sep 17, 2025
Merged

Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4)#313
christiannagel merged 7 commits intomainfrom
copilot/fix-312

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 16, 2025

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

  • Game8x5: 8 possible colors, 5 fields
  • Game5x5x4: 5 colors × 5 shapes (25 combinations), 4 fields

Key Changes

API Enhancement

The bot creation endpoint now accepts an optional gameType parameter:

# New Game8x5 support
POST /bot/bots?gameType=Game8x5&count=3&delay=10&thinkTime=3

# New Game5x5x4 support  
POST /bot/bots?gameType=Game5x5x4&count=1&delay=15&thinkTime=5

# Original Game6x4 (backward compatible - no gameType needed)
POST /bot/bots?count=3&delay=10&thinkTime=3

Algorithm Updates

Extended the core bit manipulation algorithm to handle:

  • Variable field counts (4 or 5 fields)
  • Different color counts (6 or 8 colors)
  • Shape+color combinations for Game5x5x4
  • Game result types: Added support for blue results specific to Game5x5x4

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:

  • Game6x4 & Game8x5: Black (exact match), White (color match, wrong position)
  • Game5x5x4: Black (exact match), White (shape+color match, wrong position), Blue (partial match - either correct color OR shape)

Backward Compatibility

All existing API calls continue to work unchanged. The gameType parameter defaults to Game6x4, ensuring no breaking changes for existing integrations.

Testing

Added comprehensive unit tests covering:

  • Bit manipulation for all game types
  • Field selection algorithms
  • Black/white/blue match detection
  • Color/combination conversion functions

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.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 16, 2025

@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.

Copilot AI and others added 2 commits September 16, 2025 14:16
Co-authored-by: christiannagel <1908285+christiannagel@users.noreply.github.com>
Co-authored-by: christiannagel <1908285+christiannagel@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4) Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4) Sep 16, 2025
@christiannagel
Copy link
Copy Markdown
Contributor

@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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 16, 2025

@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.

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:

  • Black: Exact match (correct shape and color in correct position)
  • White: Shape+color combination match but wrong position
  • Blue: Partial match (either correct shape OR correct color, but not both)

Added HandleBlueMatches algorithm and updated the result processing logic to detect and handle blue results properly. The changes only apply to Game5x5x4 - other game types continue to work with just black and white results.

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.
@christiannagel christiannagel marked this pull request as ready for review September 17, 2025 08:32
@christiannagel christiannagel merged commit bba18b3 into main Sep 17, 2025
3 checks passed
@christiannagel christiannagel deleted the copilot/fix-312 branch September 17, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Codebreaker.Bot to Support Additional Game Types (Game8x5, Game5x5x4)

2 participants