ahmed-hamza-eita / Tic-Tac-Toe-AI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tic-tac-toe-minimax

An implementation of Minimax AI Algorithm on Tic-Tac-Toe

What is Minimax?

Minimax algorithm is a decision rule used in artificial intelligence, decision theory, game theory, statistics, and philosophy for minimizing the possible loss for a worst-case (maximum loss) scenario1. It is a kind of backtracking algorithm that is used in decision making and game theory to find the optimal move for a player, assuming that your opponent also plays optimally2. It is widely used in two-player turn-based games such as Tic-Tac-Toe, Backgammon, Mancala, Chess, etc.

How does it works?

  • The algorithm starts by creating a game tree that shows all possible moves and outcomes for both players.
  • Each node in the game tree represents a possible state of the game, with edges representing the possible moves from that state.
  • At the bottom of the tree, the algorithm assigns a score to each possible end state (win, loss, or draw) based on who wins the game.
  • The algorithm then works its way back up the tree, evaluating each node's score based on whether it's a player's turn or the opponent's turn.
  • The algorithm assumes that both players are playing optimally, so it alternates between maximizing the score for itself and minimizing the score for its opponent.
  • Finally, the algorithm chooses the move that leads to the highest score for itself.

In summary, minimax in Tic Tac Toe works by recursively evaluating all possible moves and outcomes in a game tree and choosing the move that leads to the best possible outcome for the player using the algorithm

Game Tree

About


Languages

Language:Kotlin 100.0%