This repository contains a robust, extensible implementation of the classic "Pig" dice game and its popular variations. The project was developed as part of a technical assessment, prioritizing clean code, domain-driven design (DDD), and architectural flexibility.
To accommodate four distinct rule sets (Standard 1-Dice, Standard 2-Dice, Big Pig, and Hog) without creating a "God Object," I implemented the Strategy Pattern.
IPigVariationInterface: Defines the contract for turn logic and scoring.- Rule Agnosticism: The core game engine doesn't know which version it is playing; it simply processes the
RollResultprovided by the strategy.
I utilized C# Records for PlayerState and GameState. This ensures:
- Immutability: State cannot be modified unexpectedly; instead, a new state is returned via a "transformer" logic.
- Value-Based Equality: Simplifies testing and debugging by comparing data rather than object references.
The solution is divided into four distinct layers:
- Pig.Core: The "Brain." Contains domain records and the state transition logic.
- Pig.Variations: The "Rules." Encapsulates specific game mechanics.
- Pig.Console: The "Skin." Handles I/O, user interaction, and the game loop.
- Pig.Tests: The "Safety Net." xUnit tests covering all edge cases.
Rather than relying on System.Random in unit tests—which leads to flaky results—the test suite uses Deterministic Unit Testing. I inject specific dice arrays into the state transformer to verify that the game reacts correctly to specific outcomes (e.g., rolling double 1s in Big Pig).
- Language: C# 14
- Runtime: .NET 10 (Current preview/latest support)
- Test Framework: xUnit