Exemple #1
0
        public override List <Move> getLegalMoves(Board board)
        {
            List <Move> legalMoves = new List <Move>();

            foreach (int argument in Knight.legalMoveArguments)
            {
                int unCheckedPosition = this.piecePosition + argument;
                if (!BoardUtils.checkedForLegalPosition(unCheckedPosition) ||
                    Knight.firstColumnViolation(this.piecePosition, argument) ||
                    Knight.secondColumnViolation(this.piecePosition, argument) ||
                    Knight.seventhColumnViolation(this.piecePosition, argument) ||
                    Knight.eightColumnViolation(this.piecePosition, argument))
                {
                    continue;
                }
                else
                {
                    Cell currentCell = board.getCell(unCheckedPosition);
                    if (!currentCell.isCellOccupied())
                    {
                        legalMoves.Add(new NormalMove(board, this, unCheckedPosition));
                    }
                    else
                    {
                        if (this.pieceSide != currentCell.getPiece().getSide())
                        {
                            legalMoves.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece()));
                        }
                    }
                }
            }
            return(legalMoves);
        }
Exemple #2
0
        public override List <Move> getLegalMoves(Board board)
        {
            List <Move> legalMove = new List <Move>();

            foreach (int argument in King.legalMoveArguments)
            {
                int unCheckedPosition = this.piecePosition + argument;
                if (!BoardUtils.checkedForLegalPosition(unCheckedPosition) ||
                    King.firstColumnViolation(this.piecePosition, argument) ||
                    King.eightColumnViolation(this.piecePosition, argument))
                {
                    continue;
                }

                else
                {
                    Cell currentCell = board.getCell(unCheckedPosition);
                    if (!currentCell.isCellOccupied())
                    {
                        legalMove.Add(new NormalMove(board, this, unCheckedPosition));
                    }
                    else
                    {
                        if (this.pieceSide != currentCell.getPiece().getSide())
                        {
                            legalMove.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece()));
                        }
                    }
                }
            }
            if (board.CurrentPlayer != null)
            {
                List <Move> currentPlayerMove  = board.CurrentPlayer.getLegalMoves();
                List <Move> opponentPlayerMove = board.CurrentPlayer.getOpponent().getLegalMoves();
                legalMove.AddRange(board.CurrentPlayer.calculateKingCastles(currentPlayerMove, opponentPlayerMove));
            }
            return(legalMove);
        }
Exemple #3
0
        public override List <Move> getLegalMoves(Board board)
        {
            List <Move> legalMoves = new List <Move>();

            foreach (int argument in Bishop.legalMovesArguments)
            {
                int unCheckedPosition = this.piecePosition;

                while (BoardUtils.checkedForLegalPosition(unCheckedPosition))
                {
                    if (firstColumnViolation(unCheckedPosition, argument) ||
                        eightColumnViolation(unCheckedPosition, argument))
                    {
                        break;
                    }

                    unCheckedPosition += argument;
                    if (BoardUtils.checkedForLegalPosition(unCheckedPosition))
                    {
                        Cell currentCell = board.getCell(unCheckedPosition);
                        if (!currentCell.isCellOccupied())
                        {
                            legalMoves.Add(new NormalMove(board, this, unCheckedPosition));
                        }
                        else
                        {
                            if (this.pieceSide != currentCell.getPiece().getSide())
                            {
                                legalMoves.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece()));
                            }
                            break;
                        }
                    }
                }
            }
            return(legalMoves);
        }
Exemple #4
0
        public override List <Move> getLegalMoves(Board board)
        {
            List <Move> legalMoves = new List <Move>();

            foreach (int argument in legalMoveArguments)
            {
                int unCheckedPosition = this.piecePosition + (this.direction * argument);

                if (!BoardUtils.checkedForLegalPosition(unCheckedPosition))
                {
                    continue;
                }

                if (argument == 8 && !board.getCell(unCheckedPosition).isCellOccupied())
                {
                    if (this.isPromotionSquare(unCheckedPosition))
                    {
                        legalMoves.Add(new PawnPromotionMove(new NormalMove(board, this, unCheckedPosition), this.getPromotionPiece(PieceType.ROOK)));
                        legalMoves.Add(new PawnPromotionMove(new NormalMove(board, this, unCheckedPosition), this.getPromotionPiece(PieceType.KNIGHT)));
                        legalMoves.Add(new PawnPromotionMove(new NormalMove(board, this, unCheckedPosition), this.getPromotionPiece(PieceType.BISHOP)));
                        legalMoves.Add(new PawnPromotionMove(new NormalMove(board, this, unCheckedPosition), this.getPromotionPiece()));
                    }
                    else
                    {
                        legalMoves.Add(new PawnMove(board, this, unCheckedPosition));
                    }
                }

                if (argument == 16 && this.isFirstMove() &&
                    (this.piecePosition / 8 == 1 && this.isBlack() ||
                     this.piecePosition / 8 == 6 && this.isWhite()))
                {
                    int behindPosition = this.piecePosition + (this.direction * 8);
                    if (!board.getCell(unCheckedPosition).isCellOccupied() &&
                        !board.getCell(behindPosition).isCellOccupied())
                    {
                        legalMoves.Add(new PawnJump(board, this, unCheckedPosition));
                    }
                }

                if (argument == 9 &&
                    !((this.piecePosition % 8 == 7 && this.isBlack() ||
                       (this.piecePosition % 8 == 0 && this.isWhite()))))
                {
                    if (board.getCell(unCheckedPosition).isCellOccupied())
                    {
                        Piece occupiedPiece = board.getCell(unCheckedPosition).getPiece();
                        if (occupiedPiece.getSide() != this.getSide())
                        {
                            if (this.isPromotionSquare(unCheckedPosition))
                            {
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.ROOK)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.KNIGHT)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.BISHOP)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece()));
                            }
                            else
                            {
                                legalMoves.Add(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece));
                            }
                        }
                    }
                    else if (board.getEnPassantPawn() != null)
                    {
                        if (board.getEnPassantPawn().getPiecePosition() == this.piecePosition - (this.direction * -1))
                        {
                            Piece enPassantPiece = board.getEnPassantPawn();
                            if (this.getSide() != enPassantPiece.getSide())
                            {
                                legalMoves.Add(new PawnEnPassantAttackMove(board, this, unCheckedPosition, enPassantPiece));
                            }
                        }
                    }
                }

                if (argument == 7 &&
                    !((this.piecePosition % 8 == 0 && this.isBlack() ||
                       (this.piecePosition % 8 == 7 && this.isWhite()))))
                {
                    if (board.getCell(unCheckedPosition).isCellOccupied())
                    {
                        Piece occupiedPiece = board.getCell(unCheckedPosition).getPiece();
                        if (occupiedPiece.getSide() != this.getSide())
                        {
                            if (this.isPromotionSquare(unCheckedPosition))
                            {
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.ROOK)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.KNIGHT)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece(PieceType.BISHOP)));
                                legalMoves.Add(new PawnPromotionMove(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece), this.getPromotionPiece()));
                            }
                            else
                            {
                                legalMoves.Add(new PawnAttackMove(board, this, unCheckedPosition, occupiedPiece));
                            }
                        }
                    }
                    else if (board.getEnPassantPawn() != null)
                    {
                        if (board.getEnPassantPawn().getPiecePosition() == this.piecePosition + (this.direction * -1))
                        {
                            Piece enPassantPiece = board.getEnPassantPawn();
                            if (this.getSide() != enPassantPiece.getSide())
                            {
                                legalMoves.Add(new PawnEnPassantAttackMove(board, this, unCheckedPosition, enPassantPiece));
                            }
                        }
                    }
                }
            }
            return(legalMoves);
        }