Archicise
Exercise

Design a Chess Game Engine

Apply object-oriented design patterns to model a fully functional chess game engine, covering piece behaviour, move validation, game state, and extensibility.

Functional Requirements

  • Represent a chess board and all piece types
  • Validate legal moves for each piece
  • Detect check, checkmate, and stalemate
  • Support special moves: castling, en passant, pawn promotion
  • Maintain full move history
  • Support different game modes (human vs human, human vs AI)

Design Challenges

  • Use polymorphism to handle different piece movement rules
  • Apply the Command pattern for moves (supports undo/redo)
  • Separate game rules from rendering

Questions to Consider

  • How do you validate a move without coupling Piece to the Board?
  • How do you implement undo without storing full board snapshots?
  • How do you plug in an AI player without modifying game logic?
Your Solution

Piece Hierarchy & Move Generation

Design the Piece abstract class and concrete subclasses (King, Queen, Rook, Bishop, Knight, Pawn). Each piece exposes getPseudoLegalMoves(board): Move[]. Apply polymorphism so the game engine calls pieces uniformly. Define Position as a value object.