
2024-04-18
TrebleCross: C# Game
A deep dive into building a strategic game engine using C# and .NET 8, featuring advanced design patterns and strategic gameplay logic.
🎮 Advanced Game Engine: TrebleCross & Reversi Implementation
This project is a sophisticated console-based game engine built with .NET 8. It supports TrebleCross, a linear single-row strategy game, implementing a reusable architecture through abstract base classes and robust design patterns.
🔗 Project Links
- GitHub Repository: gyuripk/treblecross-game-csharp
📸 System Previews
| Gameplay Session | In-Game Help System |
|---|---|
![]() | ![]() |
🛠Architecture & Design Patterns
The project is built on the Single Responsibility Principle, ensuring each class (Board, Player, Game) has a distinct role within the system.
1. Class Hierarchy & Commonalities
I extracted core logic into an abstract Game base class to support both TrebleCross and Reversi efficiently. The player system is built on a Player superclass with specialized HumanPlayer and ComputerPlayer implementations to maximize code reusability.
2. Applied Design Patterns
- Factory Method Pattern: Implemented in
CreatePlayers,CreateBoard, andCreateHelpSysto encapsulate object creation. - Template Method Pattern: The
Gameclass defines the high-level algorithm, while subclasses likeTrebleCrossGameprovide specific logic forMove()andInitializeGame(). - Command & Strategy Patterns: Encapsulates player commands (Place, Undo, Redo) and allows flexible switching between play modes (Human vs. Human or Human vs. Computer).
3. Object & Sequence Diagrams
The following diagrams illustrate state transitions and the Undo/Redo logic. The Undo/Redo functionality specifically reverts two moves at once (the current player and the opponent) to maintain a consistent turn-based flow.


🚀 Key Features
- Undo/Redo Functionality: Uses a Stack-based structure to revert or reapply the last two moves (self and opponent) simultaneously.
- Save/Restore: Utilizes
System.Text.Jsonto serialize the game state into a JSON file, allowing players to resume games at any time. - Computer AI: Features an automated player that calculates valid positions and places moves using a random selection algorithm.
- Real-time Validation: For human players, the system identifies valid move ranges and positions before every turn to ensure game integrity.
📈 Performance & Big O Analysis
The system is optimized for quick response times and efficient state management.
| Feature | Pattern/Algorithm | Complexity | Achievement Justification |
|---|---|---|---|
| Move Validation | Search Algorithm | Scans the board to identify all valid indices for the next move. | |
| State Persistence | JSON Serialization | Serializes the GameState and MoveHistory linearly based on total moves. | |
| Undo/Redo | Stack Operations | Employs moveHistory and redoStack for instantaneous state recovery. |
🎮 How to Get Started
System Requirements
- .NET SDK 8.0 or newer
Execution
# Clone the repository git clone [https://github.com/gyuripk/treblecross-game-csharp](https://github.com/gyuripk/treblecross-game-csharp) # Run the application dotnet run

Data Exploration
Advanced EDA and strategic preprocessing on a global medical dataset to optimize predictive risk classification.

Mobile ML: Fungi Classifier
87.5% accuracy classifier using DINOv2, optimized for CPU with <200ms latency.

