Unbeatable Tic Tac Toe AI

Welcome to the repository for an unbeatable Tic Tac Toe AI created using Python! This project implements the classic Tic Tac Toe game with an AI player that uses the minimax algorithm to make optimal moves. The project includes a graphical interface using the pygame library.

Table of Contents

Introduction

The project consists of a Python script that uses the minimax algorithm to create an AI player that is unbeatable in the game of Tic Tac Toe. The AI can play against a human player, providing a challenging experience for those who wish to test their skills.

How to Run

To run the Tic Tac Toe AI game:

  1. Clone the repository:

    git clone  https://github.com/priyankeshh/TicTacToe-AI.git
  2. Navigate to the project directory:

    cd unbeatable-tic-tac-toe-ai
  3. Make sure you have Python 3 and Pygame library.

  4. Run the game using:

    python main.py

Features

  • Unbeatable AI: The AI uses the minimax algorithm to make optimal moves, ensuring it does not lose the game.
  • Graphical Interface: The game features a graphical user interface using the pygame library.
  • Play Modes: Play against the AI in 'ai' mode or against another human in 'pvp' mode.
  • Reset: Restart the game at any time using the 'r' key.
  • Toggle Game Mode: Toggle between AI and PvP modes using the 'g' key.

Files

  • ai.py: Contains the implementation of the AI player using the minimax algorithm.
  • board.py: Contains the implementation of the game board and game logic.
  • constants.py: Contains constants for the game, such as window size, colors, and other settings.
  • main.py: The main file that initializes the game, handles events, and runs the game loop.

Contributing

If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.

  2. Create a new branch:

    git checkout -b feature-branch
  3. Make your changes and commit them:

    git commit -m "Add your changes here"
  4. Push your changes:

    git push origin feature-branch
  5. Submit a pull request.