Closed alex-hunter3 closed 5 days ago
This is how I do it:
func negamax(depth int, alpha float64, beta float64, position *chess.Position) float64 {
depth = int(math.Max(float64(depth), 0))
if depth == 0 {
return evaluate(position)
}
moves := position.ValidMoves()
for _, move := range moves {
new_position := position.Update(move)
evaluation := -negamax(
depth-1,
-beta,
-alpha,
new_position,
)
if evaluation >= beta {
return beta
}
alpha = math.Max(evaluation, alpha)
}
return alpha
}
I think this is what you are looking for: https://pkg.go.dev/github.com/notnil/chess#Position.Update
It skips redundant move validation and I follow a similar pattern to @LouieMartin
I'm trying to implement a bot with this library powering the game. However, instead of deep copying the board while constructing the tree there should be a method to pop the last move off the MoveHistory as it would be a lot faster than copying the board for each node of the minimax tree.
Is there a function that exists currently?