I used an algorithm that allows the AIPlayer to always win the game or at least make lose the human player. This algorithm is based on recursion in mathematics and allows the AI to choose each time the best move option to beat the opponent.
You did not believe me, so try it maybe you could win!
Game Modele base on https://www.freecodecamp.com
- Bassic Setup
- Determine Winner
- Implementation of Ai and Winner notification
- Minimax Algorithm logic (hard part)
A Minimax algorithm can be best defined as a recursive function that does the following things:
- Return a value if a terminal state is found (+10, 0, -10)
- Go through available spots on the board
- Call the minimax function on each available spot (recursion)
- Evaluate returning values from function calls
- And return the best value
