Great work! We’ve now edited our
minimax() 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 wrote an evaluation function specific to our understanding of the game (in this case, Connect Four). This evaluation function allows us to stop the recursion before reaching the leaves of the game tree.
- We implemented alpha-beta pruning. By cleverly detecting useless sections of the game tree, we’re able to ignore those sections and therefore look farther down the tree.
Now’s our chance to put it all together. We’ve written most of the function
two_ai_game() which sets up a game of Connect Four played by two AIs. For each player, you need to call fill in the third parameter of their
Remember, right now our evaluation function is using a pretty bad strategy. An AI using the evaluation function we wrote will prioritize making sure its pieces are the top pieces of each column.
Do you think you could write an evaluation function that uses a better strategy? In the project for this course, you can try to write an evaluation function that can beat our AI!
Fill in the third parameter of both
minimax() function calls. This parameter is the
depth of the recursive call. The higher the number, the
“smarter” the AI will be.
What happens if they have equal intelligence? What happens if one is significantly smarter than the other?
We suggest keeping these parameters under
7. Anything higher and the program will take a while to complete!