The Ultimate Foe is the fourth and final serial of the larger narrative known as The Trial of a Time Lord which encompasses the whole of the 23rd season of the British science fiction television series Doctor Who.
At the Master's insistence, Glitz reveals the data he tried to obtain on Ravolox included technological secrets from the Matrix, which was stolen by the Sleepers.
When the Doctor demands to halt the trial as he cannot be both the defendant and prosecutor, the Valeyard flees into the Matrix, a virtual reality where normal logic does not apply.
Glitz is unable to rescue him, but the Doctor rises from the ground unharmed, insisting correctly that nothing that happens in the Matrix is real.
They agree that she should tell the truth, and she confirms to the court that the scenes of the Vervoids' destruction, the basis of the Valeyard's charge of genocide, are as she witnessed them.
She finds the Doctor and warns him – but he had already realised the courtroom was a fake and merely wished to reach a final confrontation with the Valeyard.
They realise that a concealed machine in the room is a particle disseminator, with which the Valeyard plans to murder the members of the court.
The Inquisitor drops the charges against him and reveals that Peri survived the events on Thoros Beta and became Yrcanos's queen.
The series script editor Eric Saward resigned around this time due to disagreements with the producer, John Nathan-Turner, but agreed to write the final episode based on Holmes' outline, and also rewrite Holmes' draft to tie the two together, for which he was credited as Script Editor.
[4] The original ending to the segment as a whole (and, indeed, the whole Trial story and possibly the series) would have seen the Doctor and the Valeyard in an inconclusive cliffhanger, both (seemingly) plunging into a void to their deaths as an extra "hook".
Saward refused to change the ending and withdrew permission to use his script very late in the day, by which point the production team had been assembled and the segment was entering rehearsals.
The only similarity between the two is the announcement that the High Council of the Time Lords have resigned, which was a natural development of the earlier scripts.
[citation needed] In keeping with this more optimistic stance, Nathan-Turner decided to amend the script at the last minute to show how Peri had not died as shown in Mindwarp but had in fact survived and became Yrcanos's warrior queen.
A novelisation of this serial, written by Pip and Jane Baker, was published by Target Books in April 1988 as The Ultimate Foe.