From the course: AI Algorithms for Game Design with Python
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
The negamax algorithm - Python Tutorial
From the course: AI Algorithms for Game Design with Python
The negamax algorithm
- [Instructor] It's time to talk about further optimizations and improvements you can apply to your algorithms. Here's the first one. Let's take a minute to look at the original functions that implement the max nodes and min nodes in minimax. Notice how these two functions are almost the same thing, and their differences are all summarized by flipping the sign of the values and functions that change. For example, notice the opposite signs in the initial value of V in lines 3 and 10. Notice the opposite functions in lines 5 and 12. Whatever we maximize in a function, the other one minimizes. So if you are an experienced programmer, you might be thinking that there must be a way to summarize these two functions into a single function. Well, there is, it's called the negamax algorithm. As the name hints, it consists on alternating or negating the sign of a parameter between function calls. Thus negamax is short for negated minimax. This implementation is based on the nature of the games…