I'm sorry to break it to you. This is physics.
EVERYTHING in this universe follows strict laws of physics as far as i know.
Sounds and music follow the same LAWS of physics.
"Sound is a travelling wave which is an oscillation of pressure transmitted through a solid, liquid, or gas, composed of frequencies within the range of hearing"
As far as i know, there are certain frequencies and ratios what sound better to human ear and a certain series of sounds are percieved as more "enjoyable" to the human brain.
Unfortunatelly inner workings of the human brain is not fully understood, so there's no full algorithm or function to determine fitness of a musical passage.
I will look it up.
I will.
That's why i'm here.
I'm quite shocked you guys dont have any guidelines and algorithms you've stumbled across or noticed when composing or havent read any books on the subject you can recommend.
But that doesnt mean good composition algorithms doesnt exist, they are in your head, but you're not quite fully aware of them. Aware of the though process you're performing while composing music.