Design a Chess Game
Problem Statement
Design the Low-Level Design (LLD) of an online/offline Chess game between two players.
The system should simulate a standard 8×8 chessboard, enforce chess rules, and manage turns, moves, and game status.
You must focus on object-oriented modeling — identifying key classes, their relationships, and responsibilities — not on UI or network gameplay (that would be HLD).
🧠 Functional Requirements
Game Setup
Moves
Check / Checkmate / Stalemate
Game Flow
Special Rules (Optional Enhancements)
Castling
Pawn Promotion
En Passant
Draw by repetition or 50-move rule
Game Result
🚫 Non-Functional Requirements
🧱 Suggested Classes
ClassResponsibility
ChessGame
Manages overall game flow, players, board, turns, and game status.
Board
Represents the 8×8 chessboard with squares and pieces.
Square
Represents a single cell on the board (row, column, piece reference).
Piece
Abstract base class for all chess pieces with color and position.
Pawn, Rook, Knight, Bishop, Queen, King
Concrete classes implementing specific movement rules.
Player
Represents a player (id, name, color).
Move
Represents a move (from-square, to-square, piece, captured piece if any).
GameStatus (Enum)
Enum values like IN_PROGRESS, WHITE_WIN, BLACK_WIN, DRAW.
MoveValidator
Responsible for validating moves according to piece rules and game state.
🔄 Example Flow
1
2ChessGame.startGame()
3→ Initialize board and players
4→ White moves first1
2Player(White): Move pawn from e2 → e4
3→ Validate move (legal pawn move)
4→ Update board1
2Player(Black): Move pawn from e7 → e5Check / Checkmate
4. Game End
1
2Result: White wins by checkmate.🧪 Example Input / Output
Input:
1
2Move 1: e2 → e4
3Move 2: e7 → e5
4Move 3: Qd1 → h5
5Move 4: Nb8 → c6
6Move 5: Bf1 → c4
7Move 6: Ng8 → f6
8Move 7: Qh5 → f7Output:
1
2Checkmate! White wins.⚙️ Constraints
🎯 Goals
Your design should: