예제 #1
0
        // a depth limited quiescence to prevent this from going on and on...
        private static int Quiescence_Limited(Board board, sbyte side, int alpha, int beta, int depthLeft)
        {
            int standingPat = Evaluation2.EvaluateFromPerspectiveOf(board, side);

            if (depthLeft == 0)
            {
                return(standingPat);
            }

            if (standingPat >= beta)
            {
                return(beta);
            }

            if (alpha < standingPat)
            {
                alpha = standingPat;
            }

            sbyte oppositeSide = (sbyte)(-1 * side);

            int movesCount;

            UInt16[]   moves = board.GenerateCaptureMoves(out movesCount);
            int        score;
            BoardState state;

            for (int i = 0; i < movesCount; i++)
            {
                state = board.GetBoardState();
                if (!board.MakeMove(moves[i]))
                {
                    continue;
                }
                score = -Quiescence_Limited(board, oppositeSide, -beta, -alpha, depthLeft - 1);
                board.RestoreState(state);

                if (score >= beta)
                {
                    return(beta);
                }
                if (score > alpha)
                {
                    alpha = score;
                }
            }
            return(alpha);
        }
예제 #2
0
        private static int Quiescence(Board board, sbyte side, int alpha, int beta)
        {
            // from: http://chessprogramming.wikispaces.com/Quiescence+Search
            int standingPat = Evaluation2.EvaluateFromPerspectiveOf(board, side);

            if (standingPat >= beta)
            {
                return(beta);
            }

            if (alpha < standingPat)
            {
                alpha = standingPat;
            }

            sbyte oppositeSide = (sbyte)(-1 * side);

            int movesCount;

            UInt16[]   moves = board.GenerateCaptureMoves(out movesCount);
            int        score;
            BoardState state;

            for (int i = 0; i < movesCount; i++)
            {
                state = board.GetBoardState();
                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);
        }