Demo
There are two algorithms,
It checks for each winning condition possible in the game (horizontal, vertical, digonal). It returns the score for winning, losing and tie conditons.
Checks all the blank spaces(available spaces) in the grid.
In simple terms, it checks for each condition in the game. There are two parts, first part is maximizing player (Human) and other is minimizing player (AI).In both types, we first check for the blank spaces available. Based on this, they check the score for each condition. The minimiser and maximizer play one after other.
In alpha beta pruning, we pass two extra parameters (alpha and beta). These parameters store the best value at that particular depth in the tree. Alpha stores best value for maximizer and beta stores best value for minimiser. In each case, we don't have to solve the entire tree. If the value at that depth is not useful for the minimiser/maximizer that branch of tree never gets played and hence saves the computational cost.
- MIT Opencourseware: Search: Games, Minimax, and Alpha-Beta
- The Coding train: Coding Challenge 154: Tic Tac Toe AI with Minimax Algorithm
- Geeks for Geeks: Minimax Algorithm in Game Theory
- Stack abuse:Minimax with Alpha-Beta Pruning in Python
- Run tictactoe_minmax.py for Minmax
- Run tic_tac_toe_minmax.py for Minmax with Alpha-Beta Pruning