Exemple #1
0
        /// <summary>
        /// Calculates a position evaluation result for the specified parameters.
        /// </summary>
        /// <param name="bitboard">The bitboard.</param>
        /// <param name="color">The player color.</param>
        /// <param name="pieceType">The piece type.</param>
        /// <param name="piecesToParse">The pieces to parse.</param>
        /// <returns>The position evaluation result.</returns>
        private int GetPositionValue(Bitboard bitboard, Color color, PieceType pieceType, ulong piecesToParse)
        {
            var position = 0;
            var array    = PositionValues.GetValues(color, bitboard.GamePhase, pieceType);

            while (piecesToParse != 0)
            {
                var pieceLSB = BitOperations.GetLSB(piecesToParse);
                piecesToParse = BitOperations.PopLSB(piecesToParse);

                var pieceIndex = BitOperations.GetBitIndex(pieceLSB);

                position += array[pieceIndex];
            }

            return(position);
        }
        /// <summary>
        /// Calculates a new position evaluation result based on the value of the removed piece and its position.
        /// </summary>
        /// <param name="bitboard">The bitboard.</param>
        /// <param name="color">The piece color.</param>
        /// <param name="pieceType">The piece type.</param>
        /// <param name="piece">The piece bit.</param>
        public static void RemovePiece(Bitboard bitboard, Color color, PieceType pieceType, ulong piece)
        {
            var pieceIndex = BitOperations.GetBitIndex(piece);
            var array      = PositionValues.GetValues(color, bitboard.GamePhase, pieceType);
            var delta      = array[pieceIndex];

            switch (color)
            {
            case Color.White:
            {
                bitboard.IncEvaluation.Position -= delta;
                break;
            }

            case Color.Black:
            {
                bitboard.IncEvaluation.Position += delta;
                break;
            }
            }
        }