/// <summary> /// Calculates a castling. /// </summary> /// <param name="bitboard">The bitboard.</param> public override void CalculateMove(Bitboard bitboard) { var from = BitPositionConverter.ToULong(From); var to = BitPositionConverter.ToULong(To); var rookFrom = 0ul; var rookTo = 0ul; switch (CastlingType) { case CastlingType.Short: { rookFrom = Color == Color.White ? CastlingConstants.InitialRightRookBitboard : CastlingConstants.InitialRightRookBitboard << 56; rookTo = rookFrom << 2; break; } case CastlingType.Long: { rookFrom = Color == Color.White ? CastlingConstants.InitialLeftRookBitboard : CastlingConstants.InitialLeftRookBitboard << 56; rookTo = rookFrom >> 3; break; } } CalculatePieceMove(bitboard, from, to); CalculatePieceMove(bitboard, PieceType.Rook, rookFrom, rookTo); RemoveCastlingPossibility(bitboard); bitboard.ReversibleMoves = 0; }
/// <summary> /// Calculates a quiet move. /// </summary> /// <param name="bitboard">The bitboard.</param> public override void CalculateMove(Bitboard bitboard) { var from = BitPositionConverter.ToULong(From); var to = BitPositionConverter.ToULong(To); CalculatePieceMove(bitboard, from, to); CalculateEnPassant(bitboard); }
/// <summary> /// Calculates en passant move. /// </summary> /// <param name="bitboard">The bitboard.</param> public override void CalculateMove(Bitboard bitboard) { var from = BitPositionConverter.ToULong(From); var to = BitPositionConverter.ToULong(To); var enemyColor = ColorOperations.Invert(Color); RemoveEnPassantPiece(bitboard, enemyColor, to); CalculatePieceMove(bitboard, from, to); }
/// <summary> /// Gets a pieces array (for bitboards). /// </summary> /// <returns>The pieces array.</returns> public ulong[] GetPiecesArray() { var pieces = new ulong[12]; foreach (var piece in Pieces) { var bitPosition = BitPositionConverter.ToULong(piece.Position); pieces[FastArray.GetPieceIndex(piece.Color, piece.Type)] |= bitPosition; } return(pieces); }
/// <summary> /// Calculates en passant fields if current piece type is pawn. /// </summary> /// <param name="bitboard">The bitboard.</param> private void CalculateEnPassant(Bitboard bitboard) { if (Piece == PieceType.Pawn) { var enPassantPosition = GetEnPassantPosition(); if (enPassantPosition.HasValue) { var enPassantLSB = BitPositionConverter.ToULong(enPassantPosition.Value); bitboard.EnPassant[(int)Color] |= enPassantLSB; IncrementalZobrist.AddEnPassant(Color, enPassantLSB, bitboard); } } }
/// <summary> /// Calculates a promotion move. /// </summary> /// <param name="bitboard">The bitboard.</param> public override void CalculateMove(Bitboard bitboard) { var from = BitPositionConverter.ToULong(From); var to = BitPositionConverter.ToULong(To); if (KillMove) { CalculateKill(bitboard, ColorOperations.Invert(Color), to); } CalculatePieceMove(bitboard, Piece, from, PromotionPiece, to); IncrementalMaterial.RemovePiece(bitboard, Color, Piece); IncrementalMaterial.AddPiece(bitboard, Color, PromotionPiece); }
/// <summary> /// Gets a en passant array (for bitboards). /// </summary> /// <returns>The en passant array.</returns> public ulong[] GetEnPassantArray() { var enPassant = new ulong[2]; if (EnPassant.WhiteEnPassant != null) { enPassant[(int)Color.White] = BitPositionConverter.ToULong(EnPassant.WhiteEnPassant.Value); } if (EnPassant.BlackEnPassant != null) { enPassant[(int)Color.Black] = BitPositionConverter.ToULong(EnPassant.BlackEnPassant.Value); } return(enPassant); }