Skip to content

Modern React-based chess application showcasing the "@rumenx/chess" npm package.

License

Notifications You must be signed in to change notification settings

RumenDamyanov/react-chess

♟️ React Chess

CI CodeQL Dependabot TypeScript

Modern, fully client-side chess application built with React + TypeScript + Vite, powered by the custom engine @rumenx/chess.


✨ Features

  • Legal move generation & game state via `@rumenx/chess`
  • Move history with time-travel (jump to any ply)
  • AI opponent with multiple difficulty tiers (random → depth 5 minimax w/ alpha-beta & capture ordering)
  • Hint system (on-demand best move preview)
  • Under-promotion support (choose promotion piece)
  • Board orientation flip & side selection
  • Time controls (e.g. 3+2, 5+0, 10+5, unlimited) with increments & flag detection
  • Player naming (persistent) and configurable vs AI / local 2-player mode
  • Persistent UI preferences (orientation, difficulty, coordinates, debug flags)
  • Debug overlays (piece color & mapping diagnostics) via collapsible Developer panel
  • Copy FEN / PGN export
  • Responsive board sizing with CSS `clamp()`
  • Modular SCSS design system

🧠 AI Difficulty Mapping

Label Strategy Nominal Depth
Harmless random legal move 0
Easy minimax 1
Medium minimax + ordering 2
Hard minimax + ordering 3
Expert alpha-beta + capture ordering 4
Godlike optimized alpha-beta (throttled) 5

The engine dynamically reduces depth in pathological or large branching scenarios to keep UI responsive.

⏱ Time Controls

Time format is `M+I` (minutes base + seconds increment). Unlimited mode disables the clocks. When a side reaches 0 the opponent wins on time; result string (`1-0` / `0-1`) reflects the flag event.

🚀 Quick Start

```bash git clone https://github.com/RumenDamyanov/react-chess.git cd react-chess npm install npm run dev ```

Then open: http://localhost:5173

🧩 Project Structure

```text src/ App.tsx # Composition + settings + clocks hooks/ useChessGame.ts # Core game + clocks + history logic ... (future: useGameArchive.ts) services/ChessAI.ts # AI difficulty + search components/ChessBoard/ # Board + Square rendering components/MoveHistory # Move list & navigation utils/ # PGN, persistence helpers styles/ # SCSS tokens & theming tests/ # Jest tests (planned) ```

🔧 Development Scripts

Script Purpose
`npm run dev` Start Vite dev server (HMR)
`npm run build` Production build
`npm run preview` Preview production build
`npm run format` Format code with Prettier
`npm run format:check` Check code formatting
`npm run lint` ESLint checks
`npm run type-check` Run TypeScript in isolated mode
`npm test` Run Jest test suite
`npm run test:watch` Run tests in watch mode
`npm run test:coverage` Generate coverage report

🧪 Testing

Comprehensive test coverage for core functionality:

  • 61 passing tests covering services and utilities
  • 85%+ coverage on ChessAI service (difficulty levels, move selection, minimax)
  • 77%+ coverage on ChessEngine wrapper (initialization, moves, game state)
  • 50%+ coverage on chess notation utilities (SAN formatting, move chunking)

Run tests locally:

npm test              # Run all tests
npm run test:watch    # Watch mode
npm run test:coverage # Generate coverage report

Test Coverage Summary

Module Statements Branches Functions Lines
ChessAI 93% 73% 90% 93%
ChessEngine 77% 77% 68% 77%
chessNotation 51% 51% 33% 57%

🤝 Contributing

PRs welcome! Before submitting:

  1. Run npm run format:check - ensure code is properly formatted
  2. Run npm run lint - pass all linting checks
  3. Run npm run type-check - no TypeScript errors
  4. Run npm test - all tests must pass with coverage
  5. Keep UI changes accessible (labels, aria-live where needed)

See the full Contributing Guide for detailed guidelines.

📦 Future Enhancements

  • Opening explorer / book weighting
  • Engine benchmarking panel
  • Dark theme toggle
  • Cloud sync (optional)

🛠 Tech Stack

  • React + TypeScript + Vite
  • Custom chess engine: `@rumenx/chess`
  • SCSS modules (design tokens & utilities)

🔗 Related Projects

Explore other libraries and tools from the same developer:

NPM Packages

PHP Libraries

Go Modules

📚 Documentation & Governance

📄 License

MIT © Rumen Damyanov

📞 Support & Community


Have an idea or spot a bug? Open an issue or propose a PR!

About

Modern React-based chess application showcasing the "@rumenx/chess" npm package.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Contributors 3

  •  
  •  
  •