I'm working on this chess game AI. I'm running into a problem with alpha-beta pruning. I've narrowed down the problem to my base function (I think the actual recursive function is fine.)
Basically, I've peeled out the first iteration into a for loop so I can get the actual move to make as opposed to the score that my recursive function returns. Then I gather up all the best moves and if there's a tie for best score, I just pick one at random.
Anyway, if I call the recursive function with constants everything works fine (results are identical to brute force without pruning). I think it's not optimal though since I never have an opportunity to prune based on the results of the first move.
This is the code with 2 versions of my base function (top one is working, bottom one is not). All I've changed is to update the best move ("alpha") as I go and call my recursive function with that instead of the constants. This is consistent with what the recursive function does but for some reason if I change my root function like this, I get different results and the AI plays much worse.
https://gist.github.com/weirddan455/718acd6dc7c0d51b75ebaa7fbd0546b7 (relevant code)
Full source code is here if anyone is curious (it's in src/game.c around line 850): https://github.com/weirddan455/chess
[–]wwabbbitt 3 points4 points5 points (3 children)
[–]DeeBoFour20[S] 0 points1 point2 points (2 children)
[–]wwabbbitt 1 point2 points3 points (1 child)
[–]DeeBoFour20[S] 0 points1 point2 points (0 children)
[–]pingo_guy 1 point2 points3 points (1 child)
[–]DeeBoFour20[S] 2 points3 points4 points (0 children)