But most people, IMO, do not think deeply about morality, they just mimic others around them.
I guess that would still apply to what you said though - it would take a very complex algorithm to come up with the optimal set of beliefs to minimize resistance you'd meet from others in the society you live in (I believe such an algorithm would not be unlike what goes on in the minds of many people).