Пример #1
0
        /// <summary>
        /// Removes castling possibility if needed.
        /// </summary>
        /// <param name="bitboard">The bitboard.</param>
        private void CalculateCastling(Bitboard bitboard)
        {
            switch (Piece)
            {
            case PieceType.King:
            {
                var shortCastlingIndex = FastArray.GetCastlingIndex(Color, CastlingType.Short);
                var longCastlingIndex  = FastArray.GetCastlingIndex(Color, CastlingType.Long);

                IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Short, bitboard);
                IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Long, bitboard);

                bitboard.CastlingPossibility[shortCastlingIndex] = false;
                bitboard.CastlingPossibility[longCastlingIndex]  = false;

                break;
            }

            case PieceType.Rook:
            {
                if (From == new Position(1, 1) || From == new Position(1, 8))
                {
                    IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Long, bitboard);
                    bitboard.CastlingPossibility[FastArray.GetCastlingIndex(Color, CastlingType.Long)] = false;
                }
                else if (From == new Position(8, 1) || From == new Position(8, 8))
                {
                    IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Short, bitboard);
                    bitboard.CastlingPossibility[FastArray.GetCastlingIndex(Color, CastlingType.Short)] = false;
                }

                break;
            }
            }
        }
        /// <summary>
        /// Removes castling possibility Zobrist hash.
        /// </summary>
        /// <param name="color">The piece color.</param>
        /// <param name="castlingType">The castling type.</param>
        /// <param name="bitboard">The bitboard.</param>
        public static void RemoveCastlingPossibility(Color color, CastlingType castlingType, Bitboard bitboard)
        {
            var castlingIndex = FastArray.GetCastlingIndex(color, castlingType);

            if (bitboard.CastlingPossibility[castlingIndex])
            {
                bitboard.Hash ^= ZobristContainer.Castling[castlingIndex];
            }
        }
Пример #3
0
        /// <summary>
        /// Removes castling possibility from the specified bitboard.
        /// </summary>
        /// <param name="bitboard">The bitboard.</param>
        private void RemoveCastlingPossibility(Bitboard bitboard)
        {
            IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Short, bitboard);
            IncrementalZobrist.RemoveCastlingPossibility(Color, CastlingType.Long, bitboard);

            bitboard.CastlingPossibility[FastArray.GetCastlingIndex(Color, CastlingType.Short)] = false;
            bitboard.CastlingPossibility[FastArray.GetCastlingIndex(Color, CastlingType.Long)]  = false;
            IncrementalCastling.SetCastlingDone(bitboard, Color);

            bitboard.CastlingDone[(int)Color] = true;
        }
Пример #4
0
 /// <summary>
 /// Checks if castling with the specified type is possible.
 /// </summary>
 /// <param name="type">The castling type.</param>
 /// <param name="opt">The generator parameters.</param>
 /// <returns>True if castling is possible, otherwise false.</returns>
 private static bool IsCastlingPossible(CastlingType type, GeneratorParameters opt)
 {
     return(opt.Bitboard.CastlingPossibility[FastArray.GetCastlingIndex(opt.FriendlyColor, type)]);
 }