Skip to content

WaltsonZh/TicTacToe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe

Description

This is a simple Tic-Tac-Toe web game implemented using vanilla JavaScript. The game board is represented using HTML table cells, and the player symbols are drawn on canvas elements within each cell.

How to Play

  • Visit my site to play.
  • Choose your move of "X" or "O" ("X" always starts first, choose "O" to let AI go first).

AI Algorithm

The AI opponent uses a simple algorithm to make its moves. It follows a set of rules to prioritize certain moves based on the current game state:

  1. If it's the AI's first move, it will place its symbol in the center cell if it's available. Otherwise, it will place it in any corner cell.
  2. If it's the AI's second move, it will block the player if the player has a winning move or place its symbol in an optimal position to create two in a row.
  3. On subsequent moves, the AI will try to win the game if it has two in a row or block the player if the player has two in a row.
  4. If there are no immediate winning moves or blocking moves, the AI will place its symbol in an empty cell based on a predetermined priority order.

References

  • Comments and README.md generated by ChatGPT.
  • AI algorithm referenced from google Tic-Tac-Toe game.

About

This is a simple Tic-Tac-Toe web game implemented in plain JavaScript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published