Skip to content

Unbeatable Tic-Tac-Toe AI built with Python and Pygame – a clean graphical game where the computer uses the Minimax algorithm to play perfectly, guaranteeing a win or draw against any human opponent.

Notifications You must be signed in to change notification settings

eyoab-t/tictactoe-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Tic-Tac-Toe AI with Pygame

A classic Tic-Tac-Toe game where the computer plays perfectly using the Minimax algorithm.
Challenge it if you dare—you can only draw or lose!


✨ Features

  • Perfect Play: Implements a full Minimax search.
  • Clean GUI: Built with Pygame.
  • Modular Code: AI logic completely isolated in tictactoe.py for easy testing.
  • Replay Anytime: Instant reset to play again.

🧠 How the AI Works

  1. Game-Tree Search: Explores every possible sequence of moves until a terminal board state is reached.
  2. Utility Scoring:
    • +1 if X wins
    • -1 if O wins
    • 0 if draw
  3. Optimal Decision:
    • max_value chooses moves that maximise X’s outcome.
    • min_value chooses moves that minimise it for O.

Because Tic-Tac-Toe has a small search space, the AI can look at all possibilities and never miss the best move.


🚀 Quick Start

  1. Clone the repository
    git clone https://github.com/eyoab-t/tictactoe-ai.git
    cd tictactoe-ai
    
  2. Install Dependencies
    python3 -m venv venv
    source venv/bin/activate   # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    
  3. Run the game
     python runner.py
    

About This Project

This was my first AI project, originally built in 2023 and uploaded here in 2025. — Eyoab

About

Unbeatable Tic-Tac-Toe AI built with Python and Pygame – a clean graphical game where the computer uses the Minimax algorithm to play perfectly, guaranteeing a win or draw against any human opponent.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages