public void UndoMovement(Position origin, Position destination, Piece capturedPiece) { Piece piece = Board.RemovePiece(destination); if (capturedPiece != null) { Board.PlacePiece(capturedPiece, destination); captured.Remove(capturedPiece); } Board.PlacePiece(piece, origin); piece.MovesAmountDecrease(); //#Short Castling if (piece is King && destination.Column == origin.Column + 2) { Position rOrigin = new Position(origin.Line, origin.Column + 3); Position rDestination = new Position(origin.Line, origin.Column + 1); Piece R = Board.RemovePiece(rDestination); R.MovesAmountIncrease(); Board.PlacePiece(R, rOrigin); } //#Long Castling if (piece is King && destination.Column == origin.Column - 2) { Position rOrigin = new Position(origin.Line, origin.Column - 4); Position rDestination = new Position(origin.Line, origin.Column - 1); Piece R = Board.RemovePiece(rDestination); R.MovesAmountIncrease(); Board.PlacePiece(R, rOrigin); } if (piece is Pawn) { if (origin.Column != destination.Column && capturedPiece == EnPassantVul) { Piece pawn = Board.RemovePiece(destination); Position pawnP; if (piece.Color == Color.White) { pawnP = new Position(3, destination.Column); } else { pawnP = new Position(4, destination.Column); } Board.PlacePiece(pawn, pawnP); } } }