Question

I have been steadily working on a chess program and have a minimax search, iterative deepening and transposition tables soon to come. At the moment, however, I have a bug which I have isolated to be in my quiescence search. I am frustrated because I copied a pseudo-code implementation directly and still it does not seem to be working for me. Other implementations I have found online gave me similar results.

The bug seems to incorrectly calculate the opponents "best" capture when multiple recaptures are available and as a result returns a value usually favoring the side calling the search.

The engine is written in C#

public static double Quiet(Game game, double alpha, double beta, int depth)
    {           
        double eval = Evaluation.evaluate(game);
        if(depth == 0)
        {
            return eval;
        }

        // Pseudo-legal sorted moves (Captures first)
        List<SerializedMove> moves = MoveGenerator.ListAllMoves(game, false);

        foreach(SerializedMove move in moves)
        {
            // If the move is not a capture
            if(move.taken_type == SerializedMove.NONE)
            {
                // Because of move ordering break if not a capture (Captures are first)
                break;
            }

            // Make move and alternate side to move 
            game.MakeMove(move);
            if(game.whiteMoves)
            {
                double score = Quiet(game, alpha, beta, depth - 1);
                if(score > alpha)
                {
                    alpha = score;
                }
            }
            else
            {
                double score = Quiet(game, alpha, beta, depth - 1);
                if(score < beta)
                {
                    beta = score;
                }
            }
            game.UnmakeMove(move);
            if(beta <= alpha)
            {
                break;
            }
        }

        if(game.whiteMoves)
        {
            if(beta == Evaluation.KING)
            {
                return eval;
            }
            else
            {
                return beta;
            }
        }
        else
        {
            if(alpha == -Evaluation.KING)
            {
                return eval;
            }
            else
            {
                return alpha;
            }
        }
    }

My evaluation function returns +/- values in favor of white or black, respectively.

Was it helpful?

Solution

After your Quiet() function loops through the list of moves, it is returning the wrong values for white and black moves. If white is moving, alpha should be returned since that's where you're keeping track of the score of white's best move. Similarly, beta should be returned if black is moving.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top