This project started as a traditional chess game. The codebase had several issues that needed to be addressed. Here, we document the refactoring process, techniques used, and how we transformed the chess game into Onitama.
The initial code had several code smells, including:
- Long Methods: Functions that were too long and did too many things.
- Duplicated Code: Similar code blocks scattered throughout the codebase.
- Poor Naming Conventions: Variables and functions with non-descriptive names.
- Lack of Abstraction: Hardcoded values and lack of modularity.
- Guard Clause: We simplify conditional expression for a method (fcd9705)
- Remove Duplicated Code: We identified and consolidated duplicated code into reusable functions (eacb1af)
- Moving Feature: We extrapolate the offset movement feature for all pieces (299e894)
- Many Other techniques (see in git history refactor keyword)
To make the game logic more modular and reusable, we abstracted the core components:
- Game Class: Represents the game board and handles piece placement and movement.
- Piece Class: Represents individual pieces and their movement rules.
With a clean and modular codebase, we extended the game to support Onitama:
- Movement Cards: Introduced a new class to handle the dynamic movement cards unique to Onitama.
- Customizable Boards: Added support for different board sizes and configurations.
Chess (branch: main) | Onitama (branch: onitama-variant) |
---|---|