
You have the words. Now the program has to know them. That means a table of the words the game understands, and a way of finding a typed word in it. The simplest way is to compare whole words. The other way, older and very common in the games of the period, is to compare only the first few letters. Each has a price.
The words go in a typed constant, as the Turbo course kept its levels:
const
Vocab: array[1..Count] of Str12 =
('NORTH', 'SOUTH', 'TAKE', 'DROP', ...);
A word's number in the table is how the program will know it. Whole reads down the table and returns the number of the entry that equals the typed word exactly, or 0.
First compares only the first Sig letters of each:
if Copy(Vocab[I], 1, Sig) = Copy(W, 1, Sig) then
Copy past the end of a short word simply gives what there is, so KEY is compared as KEY whatever Sig is.
With Sig at 4, the player can type LANT for LANTERN, or MATCH for MATCHES, and misspell the end of a long word as much as they like. LANTERNS is understood too, though the game has no such word. And two words that share their first letters become one: with Sig at 2, LANTERN and LAMP are both LA, and the program cannot tell them apart.
Zork chose six letters. Its dictionary, read off its disc, holds every word the game knows cut to six letters, and in play only those six count:
| Typed in Zork I | Zork said |
|---|---|
OPEN MAILBOXXYZ | Opening the small mailbox reveals a leaflet. |
OPEN MAILBOZ | understood as the mailbox |
OPEN MAILBIX | I don't know the word "mailbix". |
Six letters is enough to keep the game's 697 words apart, and short enough to be stored compactly (S16).
Alice and the March Hare chose whole words. Its table holds INVENTORY and NORTH in full, and in play INVENTORY worked while INVENTOR, INVENTORYX and NORT all got No such command!. To save the player typing, it simply has extra entries: I for INVENTORY, N for NORTH, L for LOOK.
Both work. First letters forgive typing mistakes and can save space; whole words never confuse two words, at the price of a longer table.
program Know;
const
Count = 12;
Sig = 4;
type
Str12 = string[12];
const
Vocab: array[1..Count] of Str12 =
('NORTH', 'SOUTH', 'TAKE', 'DROP',
'LOOK', 'LANTERN', 'LAMP',
'LOGBOOK', 'MATCHES', 'KEY',
'CROWBAR', 'OIL');
var
W: Str12;
function Whole(W: Str12): Integer;
var
I, Found: Integer;
begin
Found := 0;
for I := 1 to Count do
if Vocab[I] = W then
Found := I;
Whole := Found;
end;
function First(W: Str12): Integer;
var
I, Found: Integer;
begin
Found := 0;
for I := 1 to Count do
if Copy(Vocab[I], 1, Sig) =
Copy(W, 1, Sig) then
Found := I;
First := Found;
end;
begin
repeat
Write('Word? ');
Readln(W);
Writeln('Whole ', Whole(W),
' First ', First(W));
until W = '';
end.
Starting from
A new work file KNOW. Type in capitals (CAPS LOCK as Turbo starts). ENTER on its own ends the program.
What you should see
Word? LANTERN
Whole 6 First 6
Word? LANT
Whole 0 First 6
Word? LANTERNS
Whole 0 First 6
Word? LAMP
Whole 7 First 7
Word? KEYS
Whole 0 First 0
Word? MATCH
Whole 0 First 9
Word? LOGS
Whole 0 First 0
Sig = 4 to Sig = 2. Type the same words. Which answers are now wrong, and why?Sig = 6. Which shortened words stop working?Whole, add else Found := 0; after Found := I (and take the semicolon off Found := I). Which words can Whole still find?7.1 With Sig = 2, make First count how many entries match, and return -1 when more than one does, so the program can say the word is ambiguous.
7.2 Work the way Zork does: at the start, cut every word in the table to six letters, and cut each typed word to six letters before looking it up. Show that LANTERNXYZ is understood and LANTEX is not.
7.3 Instead of numbers, print You mean LANTERN for a word that First recognises, and I don't know and the word for one it does not.
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
| A word is taken for a different word | Too few letters compared: two words share them. |
| A word is never found | Small letters typed, or a space on the end. Tidy first (S5). |
| Only the last word in the table is ever found | The loop clears Found again after finding the word. |
A table of words and a loop down it recognise a word. Comparing whole words never confuses two words; comparing the first few letters forgives mistakes and long endings but can merge words that start alike. Zork kept six letters of every word; Alice and the March Hare kept whole words and added short ones as extra entries.
S8, Words Into Numbers: once a word is known, stop comparing strings.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.