Skip to content

Python Tic Tac Toe Evolution: From Basic Random AI To Unbeatable Minimax Strategy - Player vs AI With 3 Difficulties, Player vs Player Mode, Smart Hint System, Undo Moves, Dynamic Sound Effects, And Persistent Score Tracking - Complete AI Gaming Experience ❌⭕

Notifications You must be signed in to change notification settings

hexbido/Tic-Tac-Toe-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Tic Tac Toe Game Cross Mark Hollow Red Circle

A Professional Strategy Gaming Experience: From Simple Random AI To Advanced Minimax Algorithm, Multi-Level Difficulty, Sound Effects, Score Persistence, And Smart Hint System.

AboutTech StackGalleryEvolutionHow To RunWarnings


separator

About The Project Memo

This Repository Represents The Eighth Major Milestone In My Front-End Diploma (Programming Fundamentals Track).

It's More Than Just A Game, It's A Documentation Of My Journey In Artificial Intelligence & Algorithm Design - The Project Chronicles The Evolution From Simple Random AI Using Basic Game Logic To A Sophisticated Gaming System Powered By Minimax Algorithm With Unbeatable AI Strategy.

The Final Version Is An Intelligent Gaming Platform That Offers Two Game Modes (Player vs AI And Player vs Player), Features Three AI Difficulty Levels (Easy, Medium, Hard), Implements The Minimax Algorithm For Perfect Play, Includes Smart Hint System That Suggests Optimal Moves, Supports Undo Functionality, Plays Dynamic Sound Effects (Click, Win, Lose, Tie), And Saves Score History With JSON Persistence Across Sessions.


separator

Tech Stack & Tools Tools

Python CustomTkinter Minimax AI VS Code Miro

Python (3.10+): The Core Language Driving All Game Logic, AI Algorithms, And User Interface Management.
CustomTkinter Framework: Powers The Modern Visual Interface With Custom Widgets, Dark/Light Theme Support, And Smooth Animations.
Minimax Algorithm: Implements The Perfect Strategy AI That Evaluates All Possible Game States To Find Optimal Moves (Unbeatable On Hard Mode).
Random Module: Provides Controlled Randomness For Easy/Medium AI Difficulty Levels And Initial Game Setup.
Threading Module: Handles Background Sound Processing To Prevent UI Freezing During Audio Playback Operations.
Winsound Module: Manages Audio Effects Including Click Sounds, Victory Fanfare, Defeat Tones, And Tie Notifications (Windows Only).
JSON Module: Handles Data Persistence By Saving And Loading Score History, Theme Preferences, And Player Statistics.
OS Module: Manages File System Operations For Sound File Loading And Game Data Storage/Retrieval.
Miro: Used For Planning And Designing The Game Architecture, AI Decision Trees, And Feature Flow Before Development.


separator
The Project Followed A Structured "Plan-Then-Code" Approach - Below Is The Comparison Between The Planning Phase And The Final Execution For Both Versions.

Basic Version Advanced Version
Planning (Logic)

Basic Flowchart
Planning (Logic)

Advanced Flowchart
Execution (Main Result)

Basic Output
Execution (Main Result)

Advanced Output
UI Design

Basic UI
UI Design

Advanced UI

View More Screenshots (Click Here) Search

Basic Version - Extra Shots

Basic Shot 2 Basic Shot 3

Basic Shot 4





Advanced Version - Extra Shots

Advanced Shot 2 Advanced Shot 3

Advanced Shot 4 Advanced Shot 5

Advanced Shot 6 Advanced Shot 7

Advanced Shot 8

Live Demo Video

Watch The Game In Action: AI Strategy, Multi-Mode Gameplay, And Smart Hint System Demonstration.

Watch Video
Click To Watch Video ▷

separator

Features & Evolution Rocket

The Transition From The Basic Random AI To The Advanced Minimax-Powered System Highlights A Significant Leap In Intelligence And User Experience.

Feature Basic Version Advanced Version (AI-Powered)
AI Algorithm Random Selection Minimax (Perfect Play)
Difficulty Levels Single Level 3 Levels (Easy/Medium/Hard)
Game Modes PvE Only PvE + PvP (2 Modes)
UI Framework Standard CustomTkinter Enhanced UI + Sidebar
Smart Features Basic Restart Hint + Undo System
Audio System No Sound 4 Sound Effects
Data Persistence Session Only JSON Storage
Theme Support Dark Only Dark/Light Toggle

Key Features In Advanced Version Star

Minimax AI Algorithm: Implements Perfect Strategy That Evaluates All Possible Game States To Find Optimal Moves - Unbeatable On Hard Difficulty.
Three Difficulty Levels: Choose Between Easy (Random + 30% Smart), Medium (70% Optimal), Or Hard (100% Minimax) For Varied Challenge.
Dual Game Modes: Play Against AI Terminator (PvE) With Adjustable Difficulty Or Challenge A Friend (PvP) On The Same Device.
Smart Hint System: Request Strategic Advice That Highlights The Best Move Using Minimax Evaluation (Golden Border Indicator).
Undo Functionality: Revert Your Last Move (Or Last 2 Moves In PvE) To Try Different Strategies Without Restarting The Game.
Dynamic Sound Effects: Enjoy Audio Feedback For Every Action - Click Sounds, Victory Fanfare, Defeat Tones, And Tie Notifications.
Score Persistence: Game Automatically Saves Your Win/Loss Record To JSON File, Tracking Performance Across Multiple Sessions.
Professional UI: Features Sidebar Controls, Custom Color Themes, Win Highlighting, Keyboard Shortcuts (1-9 Keys), And Smooth Animations.


separator

Installation & Usage Download

Follow The Steps Below To Run The Project Locally On Your Machine - Ensure You Have Python 3.10+ Installed.

1️⃣ Clone The Repository

Open Your Terminal And Run The Following Command To Download The Project Files:
git clone https://github.com/hexbido/Tic-Tac-Toe-Game.git
cd Tic-Tac-Toe-Game

2️⃣ Install Required Dependencies

Install The Necessary Python Packages Using Pip:
# For Windows Users:
pip install customtkinter  # Both Versions

# For macOS/Linux Users:
pip3 install customtkinter  # Both Versions

3️⃣ Run The Basic Version

Navigate To The Basic Version Folder And Execute The Simple Tic Tac Toe Game:
# For Windows:
cd Basic-Version
python Tic_Tac_Toe.py

# For macOS/Linux:
cd Basic-Version
python3 Tic_Tac_Toe.py

4️⃣ Run The Advanced Version (AI-Powered)

To Launch The Full Application With All Advanced Features:
# For Windows:
cd Advanced-Version
python Tic_Tac_Toe_AI.py

# For macOS/Linux:
cd Advanced-Version
python3 Tic_Tac_Toe_AI.py

5️⃣ Using The Application

Follow These Simple Steps To Play And Master The Game:

Starting A Game: Enter Your Name, Select Game Mode (Vs Computer Or Vs Friend), Choose Difficulty (If PvE), Then Click "Start Battle 🚀".
Making Moves: Click Any Empty Cell To Place Your Symbol (X) - Or Use Keyboard Numbers 1-9 For Quick Selection.
Getting Hints: Click "Get Hint 💡" In The Sidebar To See The Best Move Highlighted With A Golden Border.
Undoing Moves: Click "Undo Move ↩️" To Revert Your Last Decision (Reverts 2 Moves In PvE Mode).
Restarting Round: Click "Reset Board 🔄" To Clear The Grid While Keeping Scores Intact.
Resetting Scores: Click "Reset Score 🗑️" To Clear All Win/Loss Statistics And Start Fresh.
Switching Themes: Toggle Dark/Light Mode Switch In The Top-Right Corner Of The Lobby Screen.
Audio Effects: Enjoy Click Sounds, Victory Fanfare, Defeat Tones, And Tie Notifications During Gameplay (Advanced Version Only).


separator

Warnings & Troubleshooting Warning

Please Review The Following Notes To Ensure Smooth Operation And Avoid Common Issues:

CustomTkinter Installation: Both Versions Require customtkinter Package - Install With: pip install customtkinter (Windows) Or pip3 install customtkinter (macOS/Linux).

Python Version: Ensure You Have Python 3.10+ Installed - Earlier Versions May Cause Compatibility Issues With CustomTkinter.

Sound Effects (Windows Only): Audio Features Use winsound Module Which Only Works On Windows - macOS/Linux Users Will Not Hear Sound Effects.

Sound Files Optional: The App Can Play .wav Files If Present In The Same Folder, But Falls Back To Beep Sounds If Files Are Missing.

Hard Difficulty Warning: The AI On Hard Mode Uses Perfect Minimax Strategy - It Is Mathematically Unbeatable When Playing Optimally.

Data Persistence: Scores Are Saved To xo_bido_data.json In The Game Folder - Deleting This File Will Reset All Statistics.

Input Lock During AI Turn: You Cannot Make Moves While The AI Is Thinking - Wait For The AI's Move To Complete Before Clicking.

Undo Limitation: Undo Works Only For Moves In Progress - You Cannot Undo After A Game Has Ended (Win/Lose/Tie).

Keyboard Shortcuts: Number Keys 1-9 Correspond To Grid Positions (Top-Left To Bottom-Right) For Fast Gameplay.

Theme Persistence: Your Theme Preference (Dark/Light) Is Saved And Automatically Restored On Next Launch.


Made With Red Heart By B I D O

About

Python Tic Tac Toe Evolution: From Basic Random AI To Unbeatable Minimax Strategy - Player vs AI With 3 Difficulties, Player vs Player Mode, Smart Hint System, Undo Moves, Dynamic Sound Effects, And Persistent Score Tracking - Complete AI Gaming Experience ❌⭕

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages