It looks like you can get rid of the best
parameter to minimax
, thereby eliminating the need for garbage
, and then replace best
with this.bestFound
. Only set bestFound
's attributes if depth = 0.
You can get the principal variation by making this.bestFound
an initially empty list. Before the moves
loop, create a new move. In the if (score > alpha)
part, set its attributes the same as you do now. Push the move to the list right after the loop. The principal variation will then be the reverse of the list.
If it's important, here are some changes you can make to improve the multi-threadability of your class:
- Instead of storing the
bestFound
list as an instance variable, make it a local variable inrun
and add it as a parameter tominimax
- Make
Board.makeMove
not modify the board, but instead return a new instance of the board with the move applied. You can implement that by cloning the board and applying your move code to the clone instead of mutatingthis
. Then, pass the cloned board to the next invocation of minimax.