Design a Chess Validator (Move Validator Only)
MediumGamesValidationBoard GamesOOPBitboardRule Engine
Problem Statement
Design a chess move validator that, given a board state and a proposed move, determines if the move is legal according to standard chess rules — without building a full game engine.
Requirements
Functional Requirements
- Represent board state as a 2D grid with piece information
isValidMove(board, move)→ boolean- Validate piece-specific movement rules for all 6 piece types
- Check path clearance for sliding pieces (rook, bishop, queen)
- Validate that the move does not leave the moving player's king in check
- Support special moves: castling (both sides), en passant, pawn promotion
getValidMoves(board, position)→ List<Move> for a given pieceisInCheck(board, color)→ booleanisCheckmate(board, color)→ boolean
Non-Functional Requirements
- Stateless validator — does not maintain game state
- Extensible for chess variants (Chess960 etc.)
Key Entities
- Board: 8×8 Cell grid + castling rights flags + en passant target square
- Cell: row, col, piece (nullable)
- Piece: type (KING/QUEEN/ROOK/BISHOP/KNIGHT/PAWN), color
- Move: fromCell, toCell, promotionPiece (optional), isCastling, isEnPassant
- ChessValidator: stateless; all methods are pure functions taking Board and Move
Constraints
- Validation must be stateless — board and move are the only inputs
- isCheckmate requires generating all possible moves (expensive but correct)
- Castling requires: king and rook have not moved, no pieces between them, king not in check, king does not pass through check
- En passant: only valid on the move immediately following a two-square pawn advance
!Constraints
- Validator is stateless — no internal state, only inputs
- All 6 piece types must have correct movement validation
- Castling: neither king nor rook may have moved previously
- En passant: only valid immediately after the triggering pawn double-advance
- Move is invalid if it leaves moving player's king in check
Output
Run or submit your code to see output here.