1

Thanks to information provided by a previous answer I added a quiescence search to the end of my negamax search to ensure I am not left with a piece hanging. I think it works however it takes a very long time, how can I change the code to speed it up? Here is my code: (C#)

private float quiescenceSearch(Board board,float alpha, float beta)
{
    qCount++;
    //Evaluation without captures
    float stand_pat = Evaluate(board);
    if (stand_pat >= beta) return beta;
    if (stand_pat > alpha) alpha = stand_pat;
    Move[] legalMoves = board.GetLegalMoves();
    foreach (Move move in legalMoves)
    {
        board.MakeMove(move);
        if (move.IsCapture||board.IsInCheck())
        {
            float eval = -quiescenceSearch(board, -beta, -alpha);
            board.UndoMove(move);
            if (eval >= beta) return eval;
            if (eval < alpha) alpha = eval;
        }
        else    board.UndoMove(move);
    }
    return alpha;
}
3
  • Hi George. If you don't get good answers on here, maybe the Code Review site could be of help to improve your performance. Jul 25 at 14:05
  • My first thought is that making all legal moves looks slow. You would want to only make the moves in the qsearch that are actually captures or checks. So ideally only generate those using a special generateForcingMoves function, or at least check whether move is a capture or checking move before making the "expensive" makeMove call. For captures this shouldn't be too hard, if it is difficult for checking moves you can also exclude those from qsearch.
    – koedem
    Aug 15 at 19:01
  • Take care of perpetual check. Usually Quiescent Search does not search up to 3 checks. Aug 25 at 14:55

1 Answer 1

1

One thing you can do if your quiescence search is taking too long (more than 90% of your total search time) is limit the maximum depth of the quiescence search. This can be done the same way you would limit a normal search. Another unrelated tip that doesn't make much of a difference: for your eval function you can return a result in centipawns or millipawns so you can use an int for eval instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.