protected override Bitboard AdditionalMoveProcessing(Bitboard movesForCurrentPosition)
    {
        if (this.side == Side.Black)
        {
            movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(Side.White), this.GetCurrentPosition(), true);
        }
        else
        {
            movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(Side.Black), this.GetCurrentPosition(), true);
        }
        movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(this.side), this.GetCurrentPosition(), false);

        // The current moving side check is needed since we don't want to compute castling as a move when we're trying to see if the king is checked
        // Castling
        if (this.chessBoard.CurrentMovingSide() == this.side &&
            this.canCastle &&
            !this.chessBoard.IsKingInCheck(this.side)
            )
        {
            // King side castling
            if (this.chessBoard.GetPieceAtPosition(new Position(1, this.GetCurrentPosition().GetRow())) != null &&
                this.chessBoard.GetPieceAtPosition(new Position(1, this.GetCurrentPosition().GetRow())).GetType().Name == Constants.PieceClassNames.Rook)
            {
                Rook kingSideRook = (Rook)this.chessBoard.GetPieceAtPosition(new Position(1, this.GetCurrentPosition().GetRow()));
                // If both move positions are unoccupied
                if (kingSideRook.canCastle &&
                    this.chessBoard.GetPieceAtPosition(new Position(2, this.GetCurrentPosition().GetRow())) == null &&
                    this.chessBoard.GetPieceAtPosition(new Position(3, this.GetCurrentPosition().GetRow())) == null
                    )
                {
                    // The final move will be filtered if the King's target position leaves it in check, so the last check here should be the intermediate position, or where the Rook will be after the move
                    if (this.IsMoveSafe(new Position(3, this.GetCurrentPosition().GetRow())))
                    {
                        movesForCurrentPosition.FlipPosition(new Position(2, this.GetCurrentPosition().GetRow()));
                    }
                }
            }

            // Queen side castling
            if (this.chessBoard.GetPieceAtPosition(new Position(8, this.GetCurrentPosition().GetRow())) != null &&
                this.chessBoard.GetPieceAtPosition(new Position(8, this.GetCurrentPosition().GetRow())).GetType().Name == Constants.PieceClassNames.Rook)
            {
                Rook queenSideRook = (Rook)this.chessBoard.GetPieceAtPosition(new Position(8, this.GetCurrentPosition().GetRow()));
                if (queenSideRook.canCastle &&
                    this.chessBoard.GetPieceAtPosition(new Position(5, this.GetCurrentPosition().GetRow())) == null &&
                    this.chessBoard.GetPieceAtPosition(new Position(6, this.GetCurrentPosition().GetRow())) == null
                    )
                {
                    // The final move will be filtered if the King's target position leaves it in check, so the last check here should be the intermediate position, or where the Rook will be after the move
                    if (this.IsMoveSafe(new Position(5, this.GetCurrentPosition().GetRow())))
                    {
                        movesForCurrentPosition.FlipPosition(new Position(6, this.GetCurrentPosition().GetRow()));
                    }
                }
            }
        }

        return(movesForCurrentPosition);
    }
Beispiel #2
0
    protected override Bitboard AdditionalMoveProcessing(Bitboard movesForCurrentPosition)
    {
        if (this.side == Side.Black)
        {
            movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(Side.White), this.GetCurrentPosition(), true);
        }
        else
        {
            movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(Side.Black), this.GetCurrentPosition(), true);
        }
        movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(this.chessBoard.GetPieceLocations(this.side), this.GetCurrentPosition(), false);

        return(movesForCurrentPosition);
    }
Beispiel #3
0
    protected override Bitboard AdditionalMoveProcessing(Bitboard movesForCurrentPosition)
    {
        // For pawns, extra moves would constitute:
        // 1. Normal attack
        // 2. En passant

        // Normal attack
        // Check the row ahead for opponent locations
        int  rowToCheck;
        Side sideToCheck;

        if (this.side == Side.Black)
        {
            rowToCheck  = this.GetCurrentPosition().GetRow() - 1;
            sideToCheck = Side.White;
        }
        else
        {
            rowToCheck  = this.GetCurrentPosition().GetRow() + 1;
            sideToCheck = Side.Black;
        }

        Bitboard friendlyLocations = this.chessBoard.GetPieceLocations(this.side);
        Bitboard opponentLocations = this.chessBoard.GetPieceLocations(sideToCheck);

        // First, remove any moves that go through friendly or opponent
        movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(friendlyLocations, this.GetCurrentPosition(), false);
        movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(opponentLocations, this.GetCurrentPosition(), false);

        if (this.GetCurrentPosition().GetColumn() > Position.min)
        {
            if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)) > 0)
            {
                movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck));
            }
        }
        if (this.GetCurrentPosition().GetColumn() < Position.max)
        {
            if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)) > 0)
            {
                movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck));
            }
        }

        // En passant
        rowToCheck = this.GetCurrentPosition().GetRow();

        if (this.GetCurrentPosition().GetColumn() > Position.min)
        {
            if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)) > 0)
            {
                // Also check if the piece at this location is a pawn which has just performed a double jump
                AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck));
                if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture)
                {
                    int attackPoint = rowToCheck;
                    if (this.side == Side.Black)
                    {
                        attackPoint--;
                    }
                    else
                    {
                        attackPoint++;
                    }
                    movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, attackPoint));
                }
            }
        }
        if (this.GetCurrentPosition().GetColumn() < Position.max)
        {
            if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)) > 0)
            {
                AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck));
                if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture)
                {
                    int attackPoint = rowToCheck;
                    if (this.side == Side.Black)
                    {
                        attackPoint--;
                    }
                    else
                    {
                        attackPoint++;
                    }
                    movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, attackPoint));
                }
            }
        }

        return(movesForCurrentPosition);
    }