Skip to content

Mihir-A/Chess-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Chess Ai

A chess game implemented using C++ and SDL2, with an optional AI

Screenshot

Usage

  • Select if you want to play an AI or a 2 player game
  • Moves can be done by dragging a piece or clicking on a piece and then clicking the new square
  • Press R to resset game or D to undo a move
  • Toggle AI with A
  • Play online at https://mihirdev.com/chess

Features

  • Support for castling and auto promotion to queen
  • AI by default looks 4 moves into the future
  • AI uses minimax with alpha-beta prunning
  • Ai uses piece value and piece position to rank moves

Building from scratch

Prerequisites

  • C++ compiler with C++23 support (VS 2022+ or modern gcc/clang recommended)

Installation

  1. Clone the repo
    git clone https://github.com/Mihir-A/Chess-AI.git
    cd Chess-AI
    SDL2 is fetched automatically by CMake (no separate install needed).
  2. Build with CMake (recommended):
    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
    cmake --build build
    The binary will be at build/release/chess on macOS/Linux or build\\release\\chess.exe on Windows.
  3. Run the binary, making sure the assets folder is in the same directory.

WebAssembly (Emscripten)

Use Emscripten to produce a browser build. Outputs go to build/wasm.

  1. Configure with emcmake:
    emcmake cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
  2. Build:
    cmake --build build
  3. Open build/wasm/chess.html in a local web server.

If you previously configured build/ with a native toolchain, clear it before switching:

rm -rf build/CMakeCache.txt build/CMakeFiles

Running

Make sure the assets folder sits next to the executable.

macOS (Gatekeeper warning)

If macOS blocks the app (“not opened”), you can:

  1. Right‑click the chess binary → Open → Open.
  2. Or System Settings → Privacy & Security → “chess was blocked” → Open Anyway.
  3. Or clear quarantine in Terminal:
    xattr -d com.apple.quarantine /path/to/chess

Windows

Run chess.exe from the build output folder. If SmartScreen warns, choose “More info” → “Run anyway”.

Linux

Run the chess binary from the build output folder. If needed, chmod +x chess first.

Screenshots

Screenshot Screenshot

License

Distributed under the MIT License. See LICENSE.md for more information.

Contact

mihiranan@gmail.com

Project Link: https://github.com/Mihir-A/Chess-AI

Acknowledgments

(back to top)

About

A chess game implemented using C++ and SFML with an optional AI with the option to compile to Web Assembly.

Resources

License

Stars

Watchers

Forks

Contributors