예제 #1
0
        public int columnIndex(Piece piece)
        {
            PieceType type  = piece.getPieceType();
            Sides     color = piece.getSide();
            int       index = 0;

            if (color == Sides.BLACK)
            {
                index += 6;
            }
            if (type == PieceType.KING)
            {
                return(0 + index);
            }
            else if (type == PieceType.QUEEN)
            {
                return(1 + index);
            }
            else if (type == PieceType.ROOK)
            {
                return(2 + index);
            }
            else if (type == PieceType.BISHOP)
            {
                return(3 + index);
            }
            else if (type == PieceType.KNIGHT)
            {
                return(4 + index);
            }
            return(5 + index);
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is Piece))
            {
                return(false);
            }

            Piece otherPiece = obj as Piece;

            return(this.piecePosition == otherPiece.getPiecePosition() &&
                   this.pieceSide == otherPiece.getSide() &&
                   this.type == otherPiece.getPieceType() &&
                   this.isFirstMove() == otherPiece.isFirstMove());
        }
예제 #3
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);
        }