示例#1
0
        private static int EvaluateForWhite(Board board)
        {
            int score = 0;

            // pawns
            byte[] pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhitePawnNumber + 6]);
            int opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackPawnNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, PawnValue, WhitePawnSquareTable);

            // rooks
            pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhiteRookNumber + 6]);
            opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackRookNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, RookValue, WhiteRookSquareTable);

            // knights
            pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhiteKnightNumber + 6]);
            opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackKnightNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, KnightValue, WhiteKnightSquareTable);

            // bishops
            pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhiteBishopNumber + 6]);
            opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackBishopNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, BishopValue, WhiteBishopSquareTable);

            // queens
            pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhiteQueenNumber + 6]);
            opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackQueenNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, QueenValue, WhiteQueenSquareTable);

            // king
            int[] kingSquareTable = (board.GetGameStage() == Constants.GameStage_Middle) ? WhiteKingMiddleGameSquareTable :
                WhiteKingEndGameSquareTable;
            pieceIndices = BitHelper.GetSetBitIndexes2(board.PieceToBitboard[Constants.WhiteKingNumber + 6]);
            opponentPiecesCount = BitHelper.GetNumberOfSetBits(board.PieceToBitboard[Constants.BlackKingNumber + 6]);
            score += CalculateScore(pieceIndices, opponentPiecesCount, KingValue, kingSquareTable);

            return score;
        }