lauriet wrote:Hi Martin,
Whats so hard about negamax.......maybe Im not too clever but when you start to draw out a sample tree and have to swap alpha and beta and negate scores I kind of loose track of what all the variables mean. Maybe if you just except it on faith that it works and dont think too hard about it, but being my first try I really wanted to understand the basic ideas, which I found easier with the mutual recursive version of the code. Its not as though the finally exe size is a problem.
The point is that you get much simpler code (much more readable and less error prone, easier to maintain), size of binary is not the problem here but complexity of code.
It's that you are always maximizing for the side to move, that's why you have to negate and swap bounds. I don't think it's rocket science.
Just don't forget to negate eval when it's black's turn.
Code: Select all
a = 10, b = 50
white's turn
do move
recurse (black's turn)
a = 10, b = 50, minimize (black's turn)
best a = 20 (say it comes from eval, from white's POV, qs depth 0, quiet position)
return, we get 20
raise alpha to 20, continue with next move
now negamax:
a = 10, b = 50
white's turn
do move
recurse (black's turn)
a = -50, b = -10, maximize (independent of side to move)
best a = -20 (from eval from side to move POV [=black now])
return
negate, we get 20
raise alpha to 20, continue with next move
now for black to move:
Code: Select all
a = -10, b = 20
black's turn
do move
recurse (white's turn)
a = -10, b = 20, maximize (white's turn)
best a = 13 (comes from eval, from white's POV, qs depth 0, quiet position)
return, we get 13
lower beta to 13, continue with next move
window is now -10, 13
now negamax:
a = -20, b = 10
black's turn
do move
recurse (white's turn)
a = -10, b = 20, maximize (independent of side to move)
best a = 13 (from eval from side to move POV [=white now])
return
negate, we get -13
raise alpha to -13, continue with next move
window is now -13, 10
This shows that these are equivalent but the latter doesn't require special code for white/black (unless there's a typo somewhere).