Play Tic-Tac-Toe here link
A fully playable Tic-Tac-Toe game that runs in any modern web browser. The game features a clean, responsive UI and an unbeatable AI opponent. The core game logic and the Minimax AI are written entirely in C++ and compiled to WebAssembly (Wasm) using Emscripten.
- C++ Core Engine: All game logic, state management, and AI are written in modern C++.
- Unbeatable AI: The AI opponent uses the recursive Minimax algorithm to find the optimal move, making it impossible to defeat.
- WebAssembly Powered: The C++ engine is compiled to a highly efficient WebAssembly module, allowing it to run in the browser at near-native speed.
- Responsive UI: The HTML/CSS frontend is fully responsive and provides a clean, playable experience on both desktop and mobile devices.
- Player Symbol Choice: Players can choose to play as 'X' or 'O' at the start of each game.
- Core: C++17
- Compiler/Toolchain: Emscripten (Clang/LLVM)
- Target: WebAssembly (Wasm)
- Frontend: HTML5, CSS3, Vanilla JavaScript
To build and run this project yourself, you will need Git and the Emscripten SDK.
git clone https://github.com/KrishSingaria/Tic-Tac-Toe-Ai.git
cd https://github.com/KrishSingaria/Tic-Tac-Toe-Ai.gitThis project uses a batch file (build.bat) to automate compilation. You will need to edit this file to point to your local Emscripten SDK installation.
- Open
build.batin a text editor. - Find the following line:
call C:\Users\krish\emsdk\emsdk_env.bat - IMPORTANT: Change
C:\Users\krish\emsdkto the correct path where you installed theemsdk.
Run the build script from your terminal.
build.batThis will compile the C++ source files (main.cpp, game.cpp) into game.js and game.wasm in the project's root directory.
Modern browsers do not allow web pages to load Wasm modules directly from the local file system due to security policies (CORS). You must use a local web server. This project is configured to work well with Python's built-in server.
- In your terminal, run:
python -m http.server
- Open your web browser and navigate to:
http://localhost:8000
