Beispiel #1
0
        public void UndoMovement(Position origin, Position destination, Piece capturedPiece)
        {
            Piece P = Brd.RemovePiece(destination);

            P.DecreaseMovementsQty();
            if (capturedPiece != null)
            {
                Brd.PutPiece(capturedPiece, destination);
                Captured.Remove(capturedPiece);
            }
            Brd.PutPiece(P, origin);

            //#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(destinationR);
                R.DecreaseMovementsQty();
                Brd.PutPiece(R, originR);
            }

            //#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(destinationR);
                R.DecreaseMovementsQty();
                Brd.PutPiece(R, originR);
            }

            //#Special Play: En Passant
            if (P is Pawn)
            {
                if (origin.Column != destination.Column && capturedPiece == VulnerableEnPassant)
                {
                    Piece    pawn = Brd.RemovePiece(destination);
                    Position posP;
                    if (P.Color == Color.White)
                    {
                        posP = new Position(3, destination.Column);
                    }
                    else
                    {
                        posP = new Position(4, destination.Column);
                    }
                    Brd.PutPiece(pawn, posP);
                }
            }
        }