# Artificial Intelligence Decision Making: Minimax

In this course, you'll learn how to create a game playing AI that can play Tic Tac Toe and Connect Four.

Start## Key Concepts

Review core concepts you need to learn to master this subject

Minimax algorithm game representation

Minimax algorithm state value

Minimax algorithm problem specification

Minimax algorithm assumption

Minimax algorithm state evaluation

Minimax algorithm size restriction

Minimax algorithm with alpha-beta pruning

Alpha-beta pruning variables

Minimax algorithm game representation

Minimax algorithm game representation

When writing the minimax algorithm, a game is modeled as a tree. Different elements of the game (as the current state and all possible moves) are represented as different parts of the tree. This visual representation of the game is a great aid in order to implement the minimax algorithm.

- 1Have you ever played a game against someone and felt like they were always two steps ahead? No matter what clever move you tried, they had somehow envisioned it and had the perfect counterattack. T…
- 2For the rest of this exercise, we’re going to be writing the minimax algorithm to be used on a game of Tic-Tac-Toe. We’ve imported a Tic-Tac-Toe game engine in the file tic_tac_toe.py. Before start…
- 3An essential step in the minimax function is
*evaluating*the strength of a leaf. If the game gets to a certain leaf, we want to know if that was a better outcome for player “X” or for player “O”. … - 4We now know that we can evaluate the leaves of a game tree, but how does that help us? How are we going to use those values to find the best possible move for a game state that isn’t a leaf? Let’s…
- 5One of the central ideas behind the minimax algorithm is the idea of exploring future hypothetical board states. Essentially, we’re saying if we
*were to*make this move, what would happen. As a re… - 6We’re now ready to dive in and write our minimax() function. The result of this function will be the “value” of the best possible move. In other words, if the function returns a 1, that means a mov…
- 7Nice work! We’re halfway through writing our minimax() function — it’s time to make the recursive call. We have our variable called best_value . We’ve made a hypothetical board where we’ve m…
- 8Right now our minimax() function is returning the value of the best possible move. So if our final answer is a 1, we know that “X” should be able to win the game. But that doesn’t really help us &m…
- 9Amazing! Our minimax() function is now returning a list of [value, move]. move gives you the number you should pick to play an optimal game of Tic-Tac-Toe for any given game state. This line of co…

## What you'll create

Portfolio projects that showcase your new skills

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory