Skip to content

This undefeatable AI is build using MiniMax search. It search for all the possible moves from the current state and plays the optimal move.

Notifications You must be signed in to change notification settings

iamvigneshwars/tic-tac-toe-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

How does it work?

This project is built using vanilla JavaScript. The AI uses a minimax algorithm to search all the possible game states and chooses the optimal move assuming that the opponent also plays optimally. The minimax function is recursive in which the maximizer tries to get the highest score possible while the minimizer tries to get the lowest score possible. The scores are calculated at the terminal game states (player win : -10, AI win : 10 or tie : 0). In this case, AI is the maximizing player that tries to maximize the score. The number of empty cells at terminal conditions are multiplied with the score, this makes algorithm to search for terminal states with minimal moves.

Demo

animated

Play the Game

Future Improvements

  • Limit the depth of MiniMax Search.
  • Add Aplha Beta pruning to prune unwanted branches.

About

This undefeatable AI is build using MiniMax search. It search for all the possible moves from the current state and plays the optimal move.

Topics

Resources

Stars

Watchers

Forks