Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No method to pop a move from MoveHistory #116

Open
alex-hunter3 opened this issue Oct 14, 2022 · 1 comment
Open

No method to pop a move from MoveHistory #116

alex-hunter3 opened this issue Oct 14, 2022 · 1 comment

Comments

@alex-hunter3
Copy link

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?

@LouieMartin
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants