I'm writing a board game and using Negamax for the AI. I'm applying an undo function instead of copying the board state, in order to speed up the search.
The evaluation function needs to consider the players' number of pieces that are on the board, those that still have to be placed and those that have been removed from the game. I can get this information every time but this means that I have to loop through the whole board and that would slow down search.
If I add variables and these are increased in makemove and decreased in undomove, it still doesn't work because of the recursive nature of the AI search.
So what is the best way to set these variables and sync them with the negmax search and the actual moves being done?