A hero's worth is measured by the strength of the villain against which he fights. Young David triumphed over Goliath, brave Robin Hood defeated Prince John, and the genius sleuth Sherlock Holmes time and again locked horns with the equally brilliant but diabolical Professor James Moriarty. If such a villian as Moriarty ever truly roamed the real world, woe be to mankind. It just so happens, however, that a real Professor Moriarty need not exist. A holodeck version of the twisted mastermind can be trouble enough -- especially if he is self-aware.
When Geordi La Forge urges Data to spend a few relaxing hours playing Sherlock Holmes in the holodeck, neither of them anticipates the trouble ahead. One unwitting slip of the tongue, and Data's Holmes is confronted by a Moriarty who knows that he is a holodeck program. He is "alive," and he will do anything to stay that way.
The holodeck Moriary is an extremely likable man, despite his nefarious genius. All he wants is to survive. He is overwhelmed by the realization of his own exesitence, bewildered by his circumstances, yet eager to learn about the 24th-century world in which he suddenly finds himself. He is a true gentleman, surprisingly enough, because he is no longer limitede to Sir Arthur Conan Doyle's original definition of him. Moriarty has grown beyond his original pogramming -- an interesting phenomenon, considering that he was created to play the adversary to an android who has also grown beyond his original programming.
Moriarty allows himself to be truned off and stored in the computer when Captain Jean-Luc Picard convinces him that 24th-century technology is as yet incapable of bringing a holodeck creatin out of the holodeck grid. But after four years pass, Moriarty calls upon his genius to trap Picard, Data and Leiutenant Reginald Barclay in a holodeck simulation that they think is the real U.S.S. Enterprise-D. Moriarty is truly dangerous now, because he is willing to jeopardize real lives to achieve his goals.
All he wants is to live, and to have the love of his life, Countess Regina Barthalomew, with him. But facts are facts -- Moriarty and Regina cannot leave the holodeck. So, in an elaborate scheme, Picard, Data and Barclay fool Moriarty into thinking that he has left the holodeck, and with Regina has escaped in a shuttlecraft, thereafter to roam the stars forever together, forever happy.