The Seventh Doctor is terribly confused when, one day, he wakes up in the Swiss alps inside a cable car. It's 1928, and the wintery landscape underneath him is quite beautiful. The other passenger, a Mrs Queenie Glasscock, tells him that she's on her way to a sanitorium to visit her dear father (chessmaster Mr. Swapnil Khan), and since the Doctor has completely lost his memory, he decides that a sanitorium would be a pretty nice place to go.
The inmates, meanwhile, spend their days playing board games and trying very hard not to think of Doctors and TARDISes and tremendously scary electric shocks. When the Doctor arrives, he's not the only guest of the day: inmate Harry gets a visit from his twin brother, Herbert, and mute inmate Else finds a kindred spirit in former Glamorous Wartime Singer Lola Luna. Also, a "Mr. Black" has been murdered.
The Doctor still doesn't really know what's happening, but gets Dr. Ludo Comfort to take him up to the isolation ward in the attic. Ludo is oddly compliant, and doesn't at all mind showing the Doctor the other two inmates: a very posh couple named Bobo and Bunty, who are so obviously just Ace and Hex with really bad accents that the Doctor promptly snaps out of much of his amnesia. In a fit of rage, he destroys the shock therapy machine that's being used on the inmates. This seriously upsets Ace and Hex, who wonder if this is what being the Doctor must feel like: being Surrounded by Idiots and being forced to keep everyone Locked Out of the Loop in order to preserve the grand plan.
While the Doctor and Queenie get caught up in the inmates' games, particularly in Khan's meticulously crafted giant electrified chess room, Ace and Hex struggle to find a way to keep the plot from going Off the Rails. Just as the surrealism reaches its peak, and the Doctor confronts Ludo about his own recreational use of shock therapy, the Doctor suddenly realises that there's a very important thing hidden in the wall... a small, wooden ventriloquist's doll. And when the Doctor finds it, he knows its name... the Celestial Toymaker.
The name rings a bell for many of the inmates, and it terrifies them. In order to divert the Toymaker's attention, they all agree to stage a grand floor show with as many variety acts as they can manage. Harry and Herbert, twin comedians, will tell their jokes; Else and Lola give a gorgeous Berlin-style cabaret performance. Queenie, however, sneaks out and goes back to the cable car, and when Ace follows her in, Queenie whips out a bomb and sets the sky and the earth on fire. The entire world is just made of canvas.
Ace and Hex finally come clean to the Doctor, and explain to him what's going on. Weeks ago, they and the others defeated the Toymaker at his own games, after the TARDIS was intercepted by him. Some of the humans had been trapped there for a decade or more. After their revolution, the Toymaker was reduced to a wooden doll, and everyone agreed to take a part of the villain's consciousness into their own mind, to shatter its power. Ludo used that part of the Toymaker's power to create a copy of the sanitorium where he used to work. Since the Toymaker can't live on outside his own realm for very long, the Doctor devised a plan: they would spend about six weeks in a "Groundhog Day" Loop, and each day, they would use shock treatment to eradicate the part of the Toymaker that was inside their heads. Every day, the Doctor and Queenie would arrive by cable car, the Doctor would realise what was going on (since even he couldn't fool himself that thoroughly), and he would willingly electrocute himself. Next day, the murder of him — of "Dr. Black" — would be solved by himself, and the cycle would repeat for a month and a half until the last remaining bit of the Toymaker would be gone. But with the shock treatment machine destroyed by him, the Toymaker is now free to wreak havoc...
The Toymaker, still a wooden doll, manipulates the people around him into playing his games. With each loss — starting with Ludo — the part of his consciousness that's trapped inside people's heads transfer to the next person. Meanwhile, Ace and Hex try their best to destroy everything... until Ace discovers that the weapon she's holding is her own baseball bat. The Doctor, Ace and Hex all simultaneously realise that the world they're in isn't Switzerland at all — they're all still in the Toymaker's shop, and Ace and Hex both also have a piece of the Toymaker in their heads. No one ever stood a chance. The Toymaker just wanted to see what losing would feel like, as a nice little game.
In the end, after everyone else has lost and gets turned into wooden puppets, only Queenie and her father are left. The game they choose is chess; and as they remenisce over the wonderful games they saw in Queenie's youth, the Doctor guides them into a beautiful checkmate. Khan refuses to make the final move, and Queenie refuses to surrender her King, and just for a moment, both Queenie and Khan simultaneously possess all parts of the Toymaker's consciouness that are left. Ace chooses that moment to play Hex in a game of noughts & crosses (he loses, of course) and, since the Toymaker wasn't watching, Hex is able to escape being turned into a doll, as the part of the Toymaker that was inside his mind is transferred to Ace. She and the Doctor transfer their bits to the ongoing stalemate between Queenie and Khan, and Khan uses that ultimate power to transfer everyone to safety, condemning himself to eternity with the Celestial Toymaker.
In the real sanitorium, Queenie is left behind with all the wooden dolls that were once her friends, and is reduced to an infantile state. Khan and the Toymaker watch them from the toy shop, both — in their own way — quite content with how things turned out.
- Be Careful What You Wish For:And I'll give the winner exactly what he wishes for!
- Bittersweet Ending: Trapped for eternity, Swapnil safeguards the Toymaker. Unable to finish the game of chess otherwise he'd die, and the Toymaker unable to escape until the game is finished, saving the lives of all of his friends.
- Call-Back: The Gods of Ragnarok are mentioned.
- Ace mentions that burning things doesn't always work.
- CaptainErsatz: Lola Luna is pretty much Lola from The Blue Angel, only with Marlene Dietrich's later deep voice.
- The Chessmaster: Not the Seventh Doctor for a change, which freaks out both him (being entirely Locked Out of the Loop) and Hex (who's horrified to find out what it must feel like to be the Doctor). The Chessmaster is Swapnil Khan. Of course, The person behind it makes a good show of getting everyone Out-Gambitted.
- Cuckoos Nest: The sanitorium.
- Demonic Dummy: The Toymaker.
- Dismantled MacGuffin: The Big Bad has been taken apart and imprisoned into people's memories.
- Easy Amnesia: The shock treatments remove bits of people's memories, especially who's running the asylum.
- "Eureka!" Moment: ACE has one when she finds a backpack that she knows, that neither Hex nor the Doctor could have known about.
- Game Show: The final showdown is staged as one.
- "Groundhog Day" Loop: Everyone's trapped in one.
- Laser-Guided Amnesia: The Doctor starts the story out in a state of not knowing who he is.
- Madwoman in the Attic: The "pair in isolation" are in the attic.
- Mountaintop Healthcare: The story is set in an exclusive sanatorium hidden away in the Swiss Alps and accessible only by cable car - up until it turns out that it's not in Switzerland at all and the "winners" never left the Toymaker's realm.
- Nice Job Breaking It, Hero!: The Doctor undoes his own plan, unknowingly.
- Noodle Incident: Mrs. Kniddle hasn't spoken since an undisclosed incident in a rowing boat on lake Ballaton in 1919.
- Off the Rails: The Doctor destroys the shock therapy machine. Nice Job Breaking It, Hero!.
- Sidetracked by the Analogy:The Doctor: I'll bet my hat on it!Ludovic: But you haven't got a hat?The Doctor: Then aside from the mystery of my missing hat, we have one more thing to solve!
- The Silent Bob: Mrs. Kniddle.
- Smart People Play Chess: Only the Doctor and Swapnil play chess out of everbody at the asylum.
- Your Mind Makes It Real: Zigzagged throughout the episode.
- Who Wants to Live Forever?: The Man Behind the Man started the entire plot because he got bored of being invincible, and wanted to see what losing was like.
- Whole Plot Reference: The episode is basically Doctor Who meets The Rocky Horror Picture Show, with a bit of Shock Treatment thrown in — pun very much intended. Word of God is that it was also inspired by the 1920s period whodunnits of Agatha Christie and by Thomas Mann, specifically his novel The Magic Mountain.