This is a simple Chess game implemented in TypeScript, featuring a 2D graphical interface, animation for piece movements, and rules enforcement.
- Turn-based system where players take turns playing as White.
- Animation for piece movements.
- Legal move highlights: When a piece is selected, all legal moves are highlighted.
- Check indicator: The board highlights when the King is in check.
- Enforced Chess rules for piece movements.
- Timer for each turn.
- Capture of pieces with visual updates.
- Castling, En Passant, and Pawn Promotion supported.
- Stalemate and Checkmate detection.
- Node.js (version 20)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/antoinegreuzard/chess-game.git cd chess-game
-
Install the dependencies:
npm install
-
Build the project:
npm run build
-
Start the development server:
npm run start
-
Open your browser and navigate to
http://localhost:5173
to play the game.
- src/: Contains the TypeScript source code.
- index.ts: The main entry point of the application. Includes game logic and initialization.
- canvas-renderer.ts: Manages the rendering of the board and pieces, as well as user interactions.
- piece.ts: Defines the base class for different chess pieces and their movement rules.
- board.ts: Contains the board setup and logic for move validation.
- game.ts: Handles the main game logic, including rules and turn management.
- timer.ts: Manages the timer for each player's turn.
- pieces/: Folder containing individual TypeScript files for each chess piece type:
- bishop.ts: Defines the movement rules for the bishop.
- king.ts: Defines the movement rules for the king.
- knight.ts: Defines the movement rules for the knight.
- pawn.ts: Defines the movement rules for the pawn.
- queen.ts: Defines the movement rules for the queen.
- rook.ts: Defines the movement rules for the rook.
- utils/: Contains utility files:
- pieceFactory.ts: Factory for creating instances of chess pieces.
- utils.ts: Other helper functions used across the project.
To implement the capture of pieces:
- The game validates moves and allows capturing of opponent's pieces if the move is legal.
- Captured pieces are removed from the board and displayed in the "Captured Pieces" sidebar.
To implement castling:
- Conditions for castling have been added in the King’s move validation.
- The King and the Rook involved must not have moved before.
- There must be no pieces between the King and the Rook.
- The King must not be in check before, during, or after castling.
- En Passant: This special pawn capture move is implemented, allowing pawns to capture opponents in specific conditions.
- Pawn Promotion: When a pawn reaches the opponent's back rank, it can be promoted to another piece (Queen by default, with options to choose another piece).
- Stalemate: The game correctly identifies situations of stalemate, leading to a draw.
- 50-Move Rule: The game can end in a draw if 50 moves are made without a pawn move or a capture.
- Check Indicator: When the King is in check, the board visually highlights the King’s position.
npm run build
: Compiles the TypeScript code.npm run dev
: Starts the development server using a local server.
- Insufficient Material: The game detects situations where a checkmate is impossible due to insufficient material ( e.g., King vs. King).
Feel free to fork this repository and submit pull requests. Contributions are always welcome!
This project is licensed under the MIT License.