コード例 #1
0
        /// <summary>
        /// Adds or removes piece from Zobrist hash.
        /// </summary>
        /// <param name="color">The piece color.</param>
        /// <param name="pieceType">The piece type.</param>
        /// <param name="field">The field bitboard.</param>
        /// <param name="bitboard">The bitboard.</param>
        public static void AddOrRemovePiece(Color color, PieceType pieceType, ulong field, Bitboard bitboard)
        {
            var fieldIndex = BitOperations.GetBitIndex(field);
            var index      = FastArray.GetZobristPieceIndex(color, pieceType, fieldIndex);

            bitboard.Hash ^= ZobristContainer.Pieces[index];
        }
コード例 #2
0
        /// <summary>
        /// Calculates Zobrist hash for pieces.
        /// </summary>
        /// <param name="hash">The current hash.</param>
        /// <param name="pieces">The array of pieces.</param>
        /// <returns>The updated Zobrist hash.</returns>
        private static ulong CalculatePieces(ulong hash, ulong[] pieces)
        {
            for (var colorIndex = 0; colorIndex < 2; colorIndex++)
            {
                var color = (Color)colorIndex;
                for (var pieceIndex = 0; pieceIndex < 6; pieceIndex++)
                {
                    var piece       = (PieceType)pieceIndex;
                    var piecesArray = pieces[FastArray.GetPieceIndex(color, piece)];

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

                        var fieldIndex = BitOperations.GetBitIndex(pieceLSB);

                        hash ^= ZobristContainer.Pieces[FastArray.GetZobristPieceIndex(color, piece, fieldIndex)];
                    }
                }
            }

            return(hash);
        }