A sophisticated tic-tac-toe game with AI solver capabilities, supporting customizable board sizes, win conditions, and both regular and misère game modes. Features both a modern web interface and command-line interface.
-
Customizable Game Settings
- Variable board dimensions (3x3 to 10x10)
- Adjustable win condition (3 to 10 in a row)
- Regular and Misère game modes
-
AI Solver
- Minimax algorithm with alpha-beta pruning
- Configurable search depth
- Specialized misère mode strategy
- Optimal play for standard 3x3 boards
-
Dual Interface
- Modern responsive web UI
- Command-line interface for terminal use
-
Game Features
- Move history with undo functionality
- Game restart capability
- Real-time game state updates
- Clone the repository:
git clone <repository-url>
cd tic-tac-toe-solver- Install dependencies:
pip install -r requirements.txt- Start the web server:
uvicorn app:app --reload-
Open your browser and navigate to
http://localhost:8000 -
Configure your game settings:
- Height/Width: Board dimensions (3-10)
- Win: Number in a row needed to win (3-10)
- Misère Mode: Check to enable misère rules (lose by getting a line)
-
Click "Start New Game" and begin playing!
- Click cells to make moves
- Computer Move: Let the AI make the next move
- Undo: Revert the last move
- Restart: Start over with same settings
- Depth: Adjust AI thinking depth (1-10)
Run the command-line version:
python main.pyFollow the interactive prompts to:
- Choose between regular and misère modes
- Set board dimensions and win conditions
- Make moves or request AI moves
- Undo moves and restart games
Standard tic-tac-toe rules - first player to get the required number in a row (horizontally, vertically, or diagonally) wins.
Reverse tic-tac-toe - the player who is forced to complete a line loses. This creates a completely different strategic game where you want to avoid winning lines while forcing your opponent into them.
- Uses minimax with alpha-beta pruning
- Evaluates positions based on potential winning lines
- Prioritizes center control on 3x3 boards
- Searches to full depth on 3x3 for perfect play
- Specialized evaluation function that avoids creating wins
- Strategic opening play (center control for X on 3x3)
- Mirror strategy implementation
- Careful endgame analysis to force opponent losses
- Backend: FastAPI web framework
- Frontend: Vanilla JavaScript with modern CSS
- Game Logic: Pure Python implementation
- AI: Minimax algorithm with alpha-beta pruning
main.py: Core game logic and CLI interfaceapp.py: FastAPI web server and API endpointsindex.html: Web interface structurestyles.css: Modern responsive stylingscript.js: Frontend game interaction logicrequirements.txt: Python dependencies
GET /: Serve web interfacePOST /start: Initialize new gamePOST /move: Make a movePOST /undo: Undo last movePOST /restart: Restart current gameGET /get_ai_move: Get AI move for regular modeGET /get_misere_ai_move: Get AI move for misère modeGET /state: Get current game state
- 3x3 Regular: AI plays optimally (searches full game tree)
- Larger Boards: Configurable depth limiting for reasonable response times
- Misère Mode: Additional strategic considerations may require deeper search
Feel free to submit issues and enhancement requests! Areas for potential improvement:
- Additional AI difficulty levels
- Tournament mode for multiple games
- Move suggestion highlighting
- Game analysis and statistics
- Network multiplayer support
This project is open source and available under the MIT License.
Enjoy playing and exploring the strategic depths of tic-tac-toe and its misère variant!