示例#1
0
        public Piece RunMovement(Position origin, Position destination)
        {
            Piece P = Brd.RemovePiece(origin);

            P.IncreaseMovementsQty();
            Piece CapturedPiece = Brd.RemovePiece(destination);

            Brd.PutPiece(P, destination);
            if (CapturedPiece != null)
            {
                Captured.Add(CapturedPiece);
            }

            //#Special Play: Castling short
            if (P is King && destination.Column == origin.Column + 2)
            {
                Position originR      = new Position(origin.Row, origin.Column + 3);
                Position destinationR = new Position(origin.Row, origin.Column + 1);
                Piece    R            = Brd.RemovePiece(originR);
                R.IncreaseMovementsQty();
                Brd.PutPiece(R, destinationR);
            }

            //#Special Play: Castling long
            if (P is King && destination.Column == origin.Column - 2)
            {
                Position originR      = new Position(origin.Row, origin.Column - 4);
                Position destinationR = new Position(origin.Row, origin.Column - 1);
                Piece    R            = Brd.RemovePiece(originR);
                R.IncreaseMovementsQty();
                Brd.PutPiece(R, destinationR);
            }

            //#Special Play: En Passant
            if (P is Pawn)
            {
                if (origin.Column != destination.Column && CapturedPiece == null)
                {
                    Position posP;
                    if (P.Color == Color.White)
                    {
                        posP = new Position(destination.Row + 1, destination.Column);
                    }
                    else
                    {
                        posP = new Position(destination.Row - 1, destination.Column);
                    }
                    CapturedPiece = Brd.RemovePiece(posP);
                    Captured.Add(CapturedPiece);
                }
            }

            return(CapturedPiece);
        }