Skip to content

DEADSAW/CHESSGAME

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Chess Master Pro โ™Ÿ๏ธ

A premium-quality, industry-grade chess game built from scratch with React, TypeScript, and HTML5 Canvas. Features a custom-built chess engine with no external chess libraries.

Chess Master Pro TypeScript React License

โœจ Features

Game Modes

  • Pass & Play: Play against a friend on the same device
  • vs Computer: Challenge the AI with 5 difficulty levels

AI Engine

  • Custom-built chess engine - No external chess libraries
  • Alpha-Beta pruning with iterative deepening
  • Transposition tables with Zobrist hashing
  • Move ordering with MVV-LVA, killer moves, and history heuristic
  • Quiescence search to avoid horizon effect
  • Human-like behavior with configurable mistake probability

Difficulty Levels

Level Description Depth Time
๐ŸŒฑ Beginner Learning the basics 2 500ms
๐ŸŽฎ Easy Casual play 3 1s
โšก Medium Moderate challenge 4 2s
๐Ÿ”ฅ Hard Strong opponent 5 4s
๐Ÿ‘‘ Expert Maximum strength 6 6s

User Interface

  • Canvas-based board with smooth rendering
  • Drag-and-drop and click-to-move piece movement
  • Legal move highlighting
  • Last move indicator
  • Check highlighting
  • Move history with navigation
  • AI analysis panel with evaluation bar
  • Dark/Light theme toggle
  • Board flip option
  • Responsive design - works on desktop and mobile

Technical Features

  • Web Worker - Engine runs in separate thread for smooth UI
  • TypeScript with strict mode
  • Zero external chess dependencies
  • Perft-verified move generation
  • FEN support for position import/export

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone the repository
git clone <repository-url>
cd CHESSGAME

# Install dependencies
npm install

# Start development server
npm run dev

Open http://localhost:5173 to play!

Build for Production

# Build optimized production bundle
npm run build

# Preview production build
npm run preview

๐ŸŽฎ How to Play

  1. Start a game: Choose your game mode and settings, then click "Start Game"
  2. Move pieces: Click on a piece to select it, then click on a highlighted square to move
  3. Drag & Drop: Alternatively, drag pieces to their destination
  4. Undo/Redo: Use the toolbar buttons or Ctrl+Z / Ctrl+Y
  5. Flip board: Press F or use the flip button to change perspective

Keyboard Shortcuts

Key Action
F Flip board
Ctrl+Z Undo move
Ctrl+Y Redo move
Ctrl+N New game

๐Ÿ—๏ธ Project Structure

CHESSGAME/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ engine/                 # Chess engine core
โ”‚   โ”‚   โ”œโ”€โ”€ board/              # Board representation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ constants.ts    # Board constants, square utilities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ utils.ts        # Board manipulation functions
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ fen.ts          # FEN parsing and generation
โ”‚   โ”‚   โ”œโ”€โ”€ moves/              # Move generation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ generator.ts    # Legal move generation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ notation.ts     # SAN/coordinate notation
โ”‚   โ”‚   โ”œโ”€โ”€ evaluation/         # Position evaluation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ evaluate.ts     # Piece-square tables, scoring
โ”‚   โ”‚   โ”œโ”€โ”€ search/             # Search algorithms
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ zobrist.ts      # Zobrist hashing
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ transposition.ts# Transposition table
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ordering.ts     # Move ordering heuristics
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ search.ts       # Alpha-beta search
โ”‚   โ”‚   โ””โ”€โ”€ ai/                 # AI personality
โ”‚   โ”‚       โ””โ”€โ”€ difficulty.ts   # Difficulty levels
โ”‚   โ”œโ”€โ”€ game/                   # Game state management
โ”‚   โ”‚   โ””โ”€โ”€ GameController.ts   # Central game controller
โ”‚   โ”œโ”€โ”€ worker/                 # Web Worker integration
โ”‚   โ”‚   โ”œโ”€โ”€ engine.worker.ts    # Worker entry point
โ”‚   โ”‚   โ””โ”€โ”€ engineWrapper.ts    # Promise-based wrapper
โ”‚   โ”œโ”€โ”€ ui/                     # React UI components
โ”‚   โ”‚   โ”œโ”€โ”€ components/         # React components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ChessBoard.tsx  # Canvas board component
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ StatusBar.tsx   # Game status display
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ MoveHistory.tsx # Move list with navigation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AIAnalysis.tsx  # Engine analysis panel
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Settings.tsx    # Game settings panel
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/              # React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ styles/             # CSS styles
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx             # Main application
โ”‚   โ”œโ”€โ”€ types/                  # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ tests/                  # Test files
โ”‚   โ””โ”€โ”€ main.tsx                # Application entry point
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ vite.config.ts
โ””โ”€โ”€ README.md

๐Ÿงช Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Test Coverage

  • Move generation tests - All piece movements, special moves
  • Perft tests - Verify move generation accuracy
  • FEN tests - Parsing and generation
  • Evaluation tests - Material and positional scoring
  • Search tests - Tactical positions, mate finding

๐Ÿ”ง Technical Details

Chess Engine Architecture

Board Representation

  • 64-element array (a1=0, h8=63)
  • Null for empty squares, Piece objects for occupied
  • Full position state including castling, en passant, clocks

Move Generation

  • Pseudo-legal move generation with legality filtering
  • Special move handling: castling, en passant, promotion
  • Attack detection for check/checkmate

Search Algorithm

Alpha-Beta with Iterative Deepening
โ”œโ”€โ”€ Transposition Table (Zobrist hashing)
โ”œโ”€โ”€ Move Ordering
โ”‚   โ”œโ”€โ”€ Hash move (from TT)
โ”‚   โ”œโ”€โ”€ Captures (MVV-LVA)
โ”‚   โ”œโ”€โ”€ Killer moves
โ”‚   โ””โ”€โ”€ History heuristic
โ”œโ”€โ”€ Quiescence Search
โ””โ”€โ”€ Time Management

Evaluation Function

  • Material counting (standard piece values)
  • Piece-square tables (position-based bonuses)
  • Mobility scoring
  • King safety
  • Pawn structure analysis
  • Center control

Performance Optimizations

  • Zobrist hashing for fast position comparison
  • Transposition table with replacement strategy
  • Move ordering to maximize alpha-beta cutoffs
  • Iterative deepening for time management
  • Web Worker for non-blocking UI

๐Ÿ“ API Reference

GameController

const controller = new GameController();

// Start a new game
controller.startNewGame(GameMode.VS_COMPUTER, DifficultyLevel.MEDIUM, Color.WHITE);

// Make a move
controller.makeMove(move);

// Undo/Redo
controller.undo();
controller.redo();

// Subscribe to state changes
controller.subscribe(callback);

Position Format (FEN)

import { parseFEN, positionToFEN } from './engine/board/fen';

const position = parseFEN('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1');
const fen = positionToFEN(position);

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Chess piece SVG designs inspired by standard Staunton pieces
  • Perft test positions from the chess programming wiki
  • Piece-square table values adapted from Tomasz Michniewski's work

Built with โค๏ธ using React + TypeScript + HTML5 Canvas

About

GAME OF CHESS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages