Before I even start to try answering this question, it should be said that there is no clear and definitive answer. Endless debates are everywhere on the subject of consciousness but nothing has come close to becoming concrete, since many fields of knowledge have very different thing to say (like biology, philosophy, and of course, psychology).
So, as a psychologist, I will give information to try to give the best answer I can from my perspective:
Going to early psychology, in behaviorism (the works of mostly Pavlov, Skinner and Watson) have come to the conclusion that human behaviour will always steer in direction of receiving rewards and avoiding punishment, in other words, yes: our decisions are always in search of pleasure and escaping,reducing eliminating and (preferably) staying away of stressful stimuli.
The feelings of pleasure are tied to the neurotransmitter of dopamine, as it is well known, and the feelings of stress and discomfort are tied to cortisol (It is a lot more complicated than that, but I am trying to be simple and to keep it short). These hormones are released when the enviroment interacts with a person in a certain way, meaning that the objects or actions themselves are not what bring these emotions, but our perceptions and appreciation of the stimuli in question. This is the foundation of the intrinsic and extrinsic motivations.
Thanks to everyone's definition of pleasure and stress being different, and our own definitions of these terms can evolve and change (Mostly to our ever-changing perspective and more accurately, our neurotransmitter receptors adapting accordingly to the amounts of dopamine or cortisol being received) is that we don't make the same choices than the rest of humanity or even that our decisions are not always constant, since we make decisions are in the moment, and our solution to the problem "What is going to give me the most pleasure?" is made somethings in the split of a second.
These hormones have been guides to ensure our survival as a species, making us feel good about things that are good for us (Like good food and sex) and making us flee or solve bad situations (Like the pressence of a predator, or being socially rejected). But as we grew smarter, we learn to "cheat" our innate reward system to make us feel good a in much more ways and situations. Smoking, drugs, and junk food does sure give a rush of dopamine, but the pleasure it gives surely contradict the effects they do to our health, so dopamine and cortisol are no longer reliable indicators that we are doing a "good choice."
We can even make this MORE complicated if we start bringing in to this discussion the psychodinamics theories of Consciousness and the Unconscious, since if these ideas are to be believed, we could be making decisions that bring us stress and discomfort subconsciously, trying to appease the desires that we are not aware, giving some form of pleasure that we do not even accept.
And bringing this wall of text to a conclusion, you COULD try to make a formula of behaviour with the variables of stress and pleasure, but would it be scientifically accurate and consistent? I don't think it can be done, by the very nature of biology and neural science, there is an constant evolution of pleasure and our understanding, and too many variables to be an effective algorithm to be applied to a considerable size of persons. But it surely has been theorized.
So far my links have been Wikipedia articles, to make researching a bit simpler if you are not willing to read entire books and articles, but I do not recommend this if you are serious about your learning of the subjects. Here I will list some books and explain how they relate to your question:
The Principles of Learning and Behaviour by Michael Domjan. This detailed book can help you understand every facet of the more earlier works of behaviorism and some of the more present ideas.
Neurochemistry of Consciousness by Elaine Perry. It surely is a heavy read, but very insightful and detailed if you are for the task.
Unconscious Influences on Decision making by Géraldine Coppin. While I am not usually font of psychodinamics theories of decisions, I feel obligated to link at least an article to let you read on it and make your own conclusions.
Hope this helps.