If a holodeck character is just following a set of IF-THEN rules, then it may mean it's all just smoke and mirrors.
A Voyager episode mentioned something about giving holo characters the ability to feel pain . That would mean that normally holo characters don't feel anything.
That might also mean their "emotional" reactions are just based on rules like - if subject is smiling at you, then smile back and laugh lightly'. Smoke and mirrors.
Re Moriarty- the computer may have played one big mind f*ck with the crew.
Geordi asks the computer to think of a opponent smart enough to outsmart Data. Not Sherlock Holmes, Data.
Possible theory-- The computer created a program that kept running outside the holo deck. Fed him data through the computers systems.
The Moriarty character "thinks" he's sentient because his program is just running outside the holo-deck and he's being given new information.
Notice that Moriarty stays the same character. He's ruthless and threatens to kill everyone unless he gets what he wants. He doesn't question himself or his morals.
He just plays the character the computer designed him to be.