Ship in a Bottle
While enjoying a Sherlock Holmes mystery fantasy on the holodeck, Geordi and Data request that Barclay investigate some anomalies in the program. While doing so, Professor Moriarty appears and informs Barclay that the computer system has created him so well in the fantasy that he has come alive! According to Moriarty, Picard has held him hostage in the fantasy for over four years.
Unable to believe that Moriarty really exists, Picard instructs Beverly to examine him. She finds that the impossible has occurred — a fantasy has turned into a living, breathing human being.
Thrilled to be alive, Moriarty begs Picard to bring the love of his life in the fantasy, Countess Regina Barthalomew, to life as well. After conferring with Beverly, Data and Barclay, Picard decides to postpone any action until they discover more about what really happened.
Meanwhile, the U.S.S. Enterprise orbits around two giant, gaseous planets about to collide. Picard attempts to launch probes to the planets, when he is denied authorization access by the computer. Apparently, Moriarty transferred Picard's voice authorization to his own voice, attempting to take control of the starship. Moriarty refuses to relinquish control of the vessel unless Picard agrees to bring the countess to life. His hands tied, Picard agrees to try, otherwise the Enterprise could be caught in the collision between the two stars.
Later, as Picard and Geordi work to reinstate his computer authorization, Data informs them that all of the events of the day have been a simulation. It isn't that Moriarty is real, but that all of them are participating in the fantasy. Data discovered this by noticing that a normally right-handed Geordi was working on the padd with his left hand. Evidently, Picard, Data and Barclay are real, but everyone else is a simulation — a simulation being controlled by Moriarty.
Desperate to break free of the fantasy, Picard meets with the countess and urges her to persuade Moriarty to return navigational control to him. Instead of complying with Picard's request, Moriarty works with Riker to be transported into reality. Once he is transported, though, he refuses to relinquish control over the ship unless Riker gives him a shuttlecraft. Having no other choice, Riker agrees.
As Moriarty and the countess depart on their shuttlecraft, he releases authorization back to Picard, who promptly discontinues the entire simulation. He then lets the rest of the crew know that unbeknownst to Moriarty, his shuttlecraft adventure with the countess is just another simulation. In fact, Picard has both of them encapsulated in a small computerized cube. And in the greater scheme of things, he muses to his staff, who's to say that they aren't caught in someone else's fantasy right now.