Skip to content

gallottino/chess-and-onitama

Repository files navigation

Refactoring Chess to Onitama

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.

Initial Code Smells

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.

Refactoring Techniques Used

  1. Guard Clause: We simplify conditional expression for a method (fcd9705)
  2. Remove Duplicated Code: We identified and consolidated duplicated code into reusable functions (eacb1af)
  3. Moving Feature: We extrapolate the offset movement feature for all pieces (299e894)
  4. Many Other techniques (see in git history refactor keyword)

Abstracting the Game Logic

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.

Building Onitama

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.

Preview

Chess (branch: main) Onitama (branch: onitama-variant)
Screenshot 2024-09-19 alle 12 22 21 Screenshot 2024-09-19 alle 12 18 47

Resources

Books

  1. Refactoring: Improving the Design of Existing Code
  2. Refactoring to Patterns
  3. Clean Code: A Handbook of Agile Software Craftsmanship
  4. Clean Architecture: A Craftsman's Guide to Software Structure and Design

Video

  1. Three Ideas on Refactoring by Martin Fowler (Christopher Okhravi)

Web

  1. Chess Rules
  2. Onitama Rules
  3. Onitama Board Game Geek
  4. What are mixin in Dart (Romain Rastel)

About

Collections of refactoring techniques using chess

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published