OOD / Game• Patterns: Factory Method, Command
Chess
Hard
Problem Summary
Design a chess engine supporting pieces behavior, move validations, board states, checkmate rules, and move rollbacks.
Functional Scope
- White and Black players execute turn-based moves.
- Pieces (King, Queen, Pawn) validate their legal trajectories.
- Checkmate/stalemate validation algorithms.
- Support transaction history/undo moves.
Entity-Relationship (ER) Schema
Game [1] <---> [1] Board Game [1] <---> [2] Player Board [1] <---> [64] Cell Cell [1] <---> [0..1] Piece Game [1] <---> [*] Move
Design Approach
Model Chess pieces by subclassing a base Piece class with custom canMove rules. Use the Command pattern for Move objects to support action validation, turn logs, and undo actions.
Core Classes & Models
Board (8x8 grid of Cells)Cell (Tracks Row, Column, and current Piece)Piece (Base class defining getLegalMoves)Move (Tracks start and end Cells, capturing history)Game (Manages turn history, game status)
Code Blueprint
public abstract class Piece {
public abstract boolean canMove(Board b, Cell start, Cell end);
}