This is a two-digit question. I put together a simple chess engine that does an alpha beta search, and then a Quiescence search at the end. Finding peace affects performance. The question is, is this effect acceptable? If not, what needs to be done to fix this problem?
The performance impact is shown in the figures below.
Please note that these statistics were taken into account in the middle of the game. FEN:
r3k2r / pb2qpbp / 1pn1pnp1 / 2PpP3 / 2B2B2 / 2N2N2 / PPPQ1PPP / R3K2R w KQkq - 0 1
Without rest:
- 6 layers in 82 069 ms (~ 82 sec)
- 5 layers in 5,298 ms (~ 5.3 sec)
In rest mode:
- 5 layers in 83 502 ms (~ 83 sec)
I did not make statistics for 6 layers using the search in the rest mode, but I would not want to calculate if necessary.
The main thing to note is that adding a rest search is equivalent to finding an additional layer. This is normal?
The following are the Alpha-Beta and Quiescence procedures in C #. They are based on the wiki chess program .
public static int AlphaBeta(Board board, int alpha, int beta, int depthLeft, int side) { if (depthLeft == 0) { return Quiescence(board, side, alpha, beta); } List<Move> moves = board.GenerateMoves(side); //nodesCount += moves.Count; BoardState state; int score; int oppositeSide = -1 * side; for (int i = 0; i < moves.Count; i++) { state = board.GetCurrentBoardState(); if (!board.MakeMove(moves[i])) { continue; } score = -AlphaBeta(board, -beta, -alpha, depthLeft - 1, oppositeSide); board.RestoreState(state); if (score >= beta) { return beta; } if (score > alpha) { alpha = score; } } return alpha; }
Peace
private static int Quiescence(Board board, int side, int alpha, int beta) { int standingPat = Evaluation.EvaluateFromPerspectiveOf(board, side); if (standingPat >= beta) { return beta; } if (alpha < standingPat) { alpha = standingPat; } int oppositeSide = -1 * side; List<Move> moves = board.GenerateMoves(side); int score; BoardState state; for (int i = 0; i < moves.Count; i++) { if (!board.IsCaptureMove(moves[i])) { continue; } //nodesCount++; state = board.GetCurrentBoardState(); if (!board.MakeMove(moves[i])) { continue; } score = -Quiescence(board, oppositeSide, -beta, -alpha); board.RestoreState(state); if (score >= beta) { return beta; } if (score > alpha) { alpha = score; } } return alpha; }
performance search tree chess
bytefire
source share