From the course: AI Algorithms for Gaming

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

The negamax algorithm

The negamax algorithm - Python Tutorial

From the course: AI Algorithms for Gaming

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 three and 10. Notice the opposite functions in lines five 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…

Contents