Skip to content

pdrzxzz/tic-tac-toe-minimax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tic-Tac-Toe with AI (Minimax Algorithm)

A simple terminal-based Tic-Tac-Toe game in Python where a human player competes against an AI.

๐Ÿง  About the AI

  • โœ… Unbeatable AI using Minimax with Alpha-Beta Pruning
  • ๐ŸŽฏ Prioritizes quick wins and avoids losses
  • โ™ป๏ธ Backtracking logic to simulate all possible game outcomes

๏ฟฝ How to Play

Clone this repository:

git clone https://github.com/yourusername/tic-tac-toe-ai.git  

Run the game:

python game.py  
  1. Choose to play as X or O
  2. X always moves first
  3. Enter your moves using row and column indices (0 to 2), for example:
Your move (row and column, from 0 to 2): 0 1  

๐Ÿงพ Code Structure

  • play() โ€“ Starts and manages the game loop
  • minimax() โ€“ Main recursive algorithm for optimal decision-making
  • best_move() โ€“ Finds the best move for the AI using Minimax
  • isGameOver() โ€“ Checks for a win or draw
  • possible_moves() โ€“ Returns available moves on the board
  • show_board() โ€“ Displays the board in the console

๐Ÿ›  Requirements

  • Python 3.6 or higher
  • No external libraries required

๐Ÿ“ท Sample Output

AI is thinking...  
 X | O | O  
-----------  
   | O | X  
-----------  
 O | X | X  
-----------  
O wins!  

๐Ÿ“„ License

This project is open-source and free to use.

Made by pdrzxzz | Computer Science Student ๐ŸŽ“

MuaKissGIF (2)

Releases

No releases published

Packages

No packages published

Languages