1. 1

Have 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…

2. 2

For 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 […] . Before starting to …

3. 3

An 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 […] or for player …

4. 4

We 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…

5. 5

One 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…

6. 6

We’re now ready to dive in and write our […] function. The result of this function will be the “value” of the best possible move. In other words, if the function returns a […] , that means a…

7. 7

Nice work! We’re halfway through writing our […] function — it’s time to make the recursive call. We have our variable called […] . We’ve made a hypothetical board where we’ve made o…

8. 8

Right now our […] function is returning the value of the best possible move. So if our final answer is a […] , we know that […] should be able to win the game. But that doesn’t really he…

9. 9

Amazing! Our […] function is now returning a list of […] . […] gives you the number you should pick to play an optimal game of Tic-Tac-Toe for any given game state. This line of code in…

10. 10

Nice work! You implemented the minimax algorithm to create an unbeatable Tic Tac Toe AI! Here are some major takeaways from this lesson. * A game can be represented as a tree. The current state of …

1. 1

In our first lesson on the minimax algorithm, we wrote a program that could play the perfect game of Tic-Tac-Toe. Our AI looked at all possible future moves and chose the one that would be most ben…

2. 2

The first strategy we’ll use to handle these enormous trees is stopping the recursion early. There’s no need to go all the way to the leaves! We’ll just look a few moves ahead. Being able to stop …

3. 3

By adding the […] parameter to our function, we’ve prevented it from spending days trying to reach the end of the tree. But we still have a problem: our evaluation function doesn’t know what to…

4. 4

By writing an evaluation function that works on non-leaf game states, we can stop the recursion early. But in a perfect world, we’d still want to reach the leaves of the tree. In order to traverse …

5. 5

Alpha-beta pruning is accomplished by keeping track of two variables for each node — […] and […] . […] keeps track of the minimum score the maximizing player can possibly get. It s…

6. 6

Great work! We’ve now edited our […] function to work with games that are more complicated than Tic Tac Toe. The core of the algorithm is identical, but we’ve added two major improvements: * We…

## 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