Skip to content
Notifications You must be signed in to change notification settings

bel1312/TicTacToe

Repository files navigation

Unbeatable Tic Tac Toe

A simple web-based Tic Tac Toe game where the player can never win against the computer.

How to Play

  1. Open index.html in your web browser
  2. You play as X, and the computer plays as O
  3. Click on any empty cell to make your move
  4. Try to win against the computer (spoiler: you can't!)
  5. Click the "Restart Game" button to start a new game

Game Features

  • Clean, responsive design
  • Computer AI that prevents the player from winning
  • The computer will either win or force a draw
  • Visual feedback for player and computer moves

How It Works

The computer AI uses a strategy that ensures the player can never win:

  1. If the computer can win in the next move, it will make that move
  2. If the player could win in the next move, the computer will block that move
  3. If the center is available, the computer will take it
  4. If a corner is available, the computer will take it
  5. Otherwise, the computer will take any available side

This implementation uses the minimax algorithm principles without the full recursive search, as tic-tac-toe is a simple enough game that can be solved with a few prioritized rules.

Technologies Used

  • HTML5
  • CSS3
  • JavaScript (ES6+)

License

Feel free to use and modify this code for your own projects.

Sound Effects

To enable sound when a mark is placed:

  • Add two audio files in the project directory:
    • x.mp3 (sound for X)
    • o.mp3 (sound for O)

You can use any short click or pop sound for these files. The game will play the corresponding sound each time a mark is placed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published