예제 #1
0
        public IChessPiece PerformEnPassantIfApplicable(ChessMove chessMove,
                                                        IEnumerable <IChessPiece> pieces)
        {
            if (chessMove.PawnPromotion != ChessPieceType.Pawn)
            {
                return(null);
            }
            var pieceToMove = pieces
                              .First(p => p.Position == chessMove.StartingPosition);

            if (pieceToMove.PieceType != ChessPieceType.Pawn)
            {
                return(null);
            }
            if (!IsDiagonalMove(chessMove))
            {
                return(null);
            }
            if (IsFinishedPositionTaken(chessMove, pieces))
            {
                return(null);
            }

            pieceToMove.IncrementMoveCounter();
            pieceToMove.Position = chessMove.FinishedPosition;
            history.Add(chessMove.ReturnWithCaptureAsTrue());

            return(FindPawnToRemove(chessMove, pieces));
        }
예제 #2
0
        public IChessPiece Move(ChessMove chessMove, IEnumerable <IChessPiece> pieces)
        {
            if (piecePromoter.PromoteIfPromotionMove(chessMove, pieces))
            {
                return(null);
            }
            if (castlingMover.PerformCastlingIfCastlingMove(chessMove, pieces))
            {
                return(null);
            }

            var pieceToRemove = enPassantMover.PerformEnPassantIfApplicable(chessMove, pieces);

            if (pieceToRemove != null)
            {
                return(pieceToRemove);
            }

            var pieceToMove = pieces
                              .First(p => p.Position == chessMove.StartingPosition);

            pieceToRemove = pieces
                            .FirstOrDefault(p => p.Position == chessMove.FinishedPosition);
            pieceToMove.Position = chessMove.FinishedPosition;
            pieceToMove.IncrementMoveCounter();
            if (pieceToRemove != null)
            {
                chessMove = chessMove.ReturnWithCaptureAsTrue();
            }
            history.Add(chessMove);
            return(pieceToRemove);
        }