Skip to content

ShreyaCodes176/TicTacToe-With-Computer

Repository files navigation

🎮 Tic Tac Toe AI (Java Swing)

A desktop-based Tic Tac Toe game with AI built using Java Swing, featuring a modern GUI and an intelligent CPU opponent powered by the Minimax algorithm.

✨ Features

  • 🧠 AI-powered opponent using the Minimax algorithm
  • 🎨 Custom GUI design
  • 🔄 Restart/New Game button
  • 🏆 Game status (Win / Lose / Tie)
  • 🖥️ Fully offline desktop application
  • 📦 Clean, single-file Java implementation (easy to extend)

🧠 AI Logic (Overview)

The CPU uses the Minimax algorithm to:

  • Evaluate all possible game states
  • Maximize its winning chances
  • Minimize the player's chances

This makes the AI strategic and competitive, ensuring meaningful gameplay rather than random moves.


🛠️ Technologies Used

  • Java
  • Java Swing (GUI)
  • AWT Graphics2D (custom painting & gradients)

▶️ How to Run

Prerequisites

  • Java JDK 8 or above

Steps (for Windows)

javac TicTacToeAI.java

java TicTacToeAI

The game window will open automatically.


🎯 Controls

  • Click on a tile to place your move (O)
  • The AI plays as X
  • Click the “new” button (top-right) to restart the game

📁 Project Structure

TicTacToe-AI

----TicTacToeAI.java

----README.md

----.gitignore


🚀 Future Enhancements

  • Difficulty levels (Easy / Medium / Hard)
  • Beatable AI with adaptive difficulty
  • Sound effects & animations
  • Web version (HTML/CSS/JS or Spring Boot backend)

📌 Why This Project?

This project demonstrates:

  • Strong Java fundamentals
  • Understanding of game AI concepts
  • GUI design beyond basic Swing components
  • Ability to build user-focused applications

📄 License

This project is open for learning and personal use.


About

A simple yet effective Java program to simulate playing Tic Tac Toe with your computer.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages