1. Domain Modeling: Board, Cells & Pieces
A chess board is an 8x8 grid of `Cell` objects. Each cell optionally holds a `Piece`. An abstract `Piece` class encapsulates piece color (WHITE/BLACK) and defines an abstract method: `canMove(board: Board, start: Cell, end: Cell): boolean`.
2. Polymorphic Piece Movement Rules
Concrete subclasses (`King`, `Queen`, `Rook`, `Bishop`, `Knight`, `Pawn`) implement their specific movement logic. Knights can jump over pieces; Pawns move forward but capture diagonally; Rooks move horizontally/vertically with path clearance checks.
3. Command Pattern for Move Execution & Undo
Every player turn is encapsulated in a `MoveCommand` object holding the start cell, destination cell, piece moved, and any piece captured. This makes supporting Undo, Redo, and move history trivial by maintaining a command stack.
enum Color { WHITE, BLACK }
abstract class Piece {
constructor(public color: Color) {}
abstract canMove(start: [number, number], end: [number, number], board: Piece[][]): boolean;
}
class Knight extends Piece {
canMove(start: [number, number], end: [number, number]): boolean {
const dx = Math.abs(start[0] - end[0]);
const dy = Math.abs(start[1] - end[1]);
return (dx === 1 && dy === 2) || (dx === 2 && dy === 1);
}
}Model this architecture on the HLDForge Canvas
Turn static box diagrams into living, collaborative systems. Drag and drop microservices, Kafka clusters, and cache tiers. Run automated SPOF detection and STRIDE threat modeling in real time.
Written by HLDForge Architecture Team
Lead Machine Coding Specialist
The HLDForge Architecture Team publishes practical engineering guides, real-world case studies, and high-concurrency blueprints to help engineers build scalable and fault-tolerant software.