Thursday 9 March 2023

Mathematical Puzzles in Fantasy Games

Mathematical Puzzles in Fantasy Games

Jonathan R. Partington

(Based on a Trinity Mathematical Society talk given on November 10th 1986)

Acheton

The connection between Mathematical puzzles and adventure- like settings is an old one: it predates the advent of computers and Adventure Games, as well as that of role-playing games.

For example H.E. Dudeney, in his 'Canterbury Puzzles' (about 1903) has a chapter relating 'The strange escape of the king's jester', who has to solve several mathematical puzzles, including a maze and the guessing of a safe's combination, on his way to freedom. The jester was presumably locked up for being a mathematician.

There are many much older examples, but we shall be interested here in more modern puzzles with a non-trivial mathematical content. I know of two specifically mathematical adventures, Peter Killworth's Giantkiller, and the American game 'L'. However mathematical puzzles occur in many other games.

Let's begin with a puzzle from Graph Theory. You are exploring a network of rooms that looks like this:

          O---O
          |  /|
          | / |
          |/  |
     -->--O---O
          |\ /|
          | \ |
            /
          |/ \|
          O---O-->--
          |  /|
          | / |
          |/  |
          O---O

You enter and leave the network as shown by the arrows. In addition, each room contains a single coin, so that there are eight altogether, and, by a strange coincidence, you need exactly eight coins to pay your fare home once you have got through the maze. Now comes the tricky part: these eight caves have a property shared by some old college rooms - the roof collapses as soon as you leave them.

Thus, reducing the problem to its mathematical basis, what you have to do is to find a path through the network that allows you to visit each node exactly once: A Hamiltonian Path, named after the Irish mathematician Hamilton. It is not hard to verify that there is exactly one way through, and so the puzzle has a unique solution. One could of course construct harder variants of this puzzle, in which it was impossible to visit all rooms, and one had to visit as many as possible: and so on.

In the next puzzle, another graph-theoretic problem arises.

          O---O
          |   |
          |   |
      O---O---O---O
      |   |   |   |
      |  A|   |   |
      O---O---O---O---O
         /|\  |   |   |
          |   |   |   |
      O---O---O---O---O
      |   |   |   |
      |   |   |   |
      O---O---O---O
          |   |
          |   |
          O---O

The above shows another network of paths connecting larger areas, and one enters (from the southwest) at the point A. Life is not simple, however, and the player is in fact being pursued by a Tyrannosaurus Rex; it is close behind him, and has the property that its stampeding causes avalanches to block each path behind it. The player is safe if he can leave A by the south-east, but he cannot do this immediately because of a flock of 32 pterodactyls that is taking off in perfect formation from the place he is aiming for.

It follows that what one has to do in this case is to find a path along the network that starts at A, takes in all 32 edges exactly once, and finishes up at A (just as the last bird is flying away).

This is an example of an Eulerian path. Originally Euler was asked by his pub-crawling friends whether it was possible to walk round Königsberg, whose network of pubs and bridges is shown below, in such a way as to take in every bridge exactly once.

        O----
       / \   \
       \ /    |
        O-----O
       / \    |
       \ /   /
        O----

In this case the problem is insoluble. Consider a node on one's route: if it is not the starting or finishing point then an even number of edges must radiate from it (as every time one arrives, one leaves by a different road). In this case however, all four nodes have an odd number of roads leading out, which makes the task impossible.

Another manifestation of the Eulerian path occurs in Giantkiller, where the player is forced to run along the strands of the giant's teatowel (which keep breaking), and must keep going long enough to avoid being dropped into a fire.

Mazes themselves are a fine source of mathematical puzzles. Sometimes there are straightforward ones that can be solved by mapping, though this can be made difficult, for example by having a rotating maze whose directions constantly change. In other examples, one is given a clue to the route, and must go the correct way or meet a horrible fate (often a minotaur!)

In 'Exile', for example, there is a tavern, whose name can on occasion be the 'Sun Seed', the 'Nude Nun', or even the 'Used Ewe' (a farmers' pub). Once in the tavern, one has to evade the press gang. This involves a chase through the cellars, where the directions S-U-N-S-E-E-D are required. (In 'Brand X' the way out of the Garden of EDEN is 'spelled out for you' by the serpent!)

In a Dungeons and Dragons game, the players once came across the following doggerel:

   'Go deeper in, though ways be Dull:
   Follow the trail, aye to the Full!
   All foes disperse, as scraps of Fluff,
   Should you win through this blind man's Buff.'

It was necessary for them to interpret the last word of each line and go Down-Up-Left-Left etc, in order to get through the maze. Every wrong step brought them a monster to fight.

Another way of concealing directions is by anagram clues, so that North, South, East, West become Thorn, Shout, Seat and Stew.

Back to puzzles with a more serious mathematical content. Consider the following network of roads, where the numbers indicate how many hours is takes to get from one junction to the next.

                       /
                      /
   O--1--O--4--O--1--O
   |     |     |     |
   4     1     1     2
   |     |     |     |
   O--5--O--3--O--1--O
   |     |     |     |
   3     2     3     2
   |     |     |     |
   O--6--O--1--O--2--O
  /
 /
Here one starts at the southwest and wishes to get to a village at the northeast by the shortest possible route. (Some ways take longer than others because they are busy widening the road, or, if it is like Cambridge, narrowing it.) If one gets through in 12 hours, then one is in time to save the city from destruction by a giant: if not then the mangled villagers greet you with cries of "Oh great hero, if only could could have reached here sooner...".

This puzzle can be solved by a process known as Dynamic Programming, and the mathematical theory is well-known.

Another, more fantastic, puzzle is the ice-rink, which is square and with 25 letters painted on it in a five-by-five grid, e.g.

  Q  W  E  R  T
  U  I  O  P  A
  S  D  F  G  H
  J  K  L  Z  X
  C  V  B  N  M

so that there is one letter missing. The player now has the opportunity to skate along this rink, but only in 8 successive straight line segments, before the ice melts and he finds himself in an area strangely resembling Trinity Great Court. This has 26 staircases leading off it, lettered A to Z. Twenty-five of them have trolls living on them, the twenty- sixth has a tutor. Each is about to have dinner, but the trolls will eat him whereas the tutor probably won't. Thus, since the safe staircase corresponds to the missing letter (Y, in our example), the player has to have covered all 25 points in 8 successive lines (an old problem going back to Dudeney, and maybe beyond).

Another problem of a different type altogether comes from the game Exile, and is called the Plague Village. Here the problems involved are logical ones, in a style much used by Raymond Smullyan (see for example, his book called "What is the name of this book?")

When the adventurer reaches the plague village, he finds a parchment, which bears (in faded letters) the message:

"Beware of PLAGUE - its effects are slow but fatal. The village is dead. The alleyways are dangerous and mostly infected. We, the villagers, kept exactly one route to the graveyard free of infection. Alas, many people put up signs, and in the madness of the plague they often contradicted each other. God be with you, stranger!"

Thus, the player has to find the safe route to the graveyard or die a horrible death. At the first junction he sees three signs, which read:

  NW: Keep away! Plague!
  N:  Keep away! Plague!
  NE: At most one of these three signs is true.

(Clearly the village mathematician, or possibly the village idiot, wrote the sign on the north-east route!) Such a problem is easily solved, in fact by symmetry only the NE route could be the unique safe way. One further example:

  SW: The sign on the west alley is true.
  W:  If the southwest sign is true, so is the northwest sign.
  NW: This way is safe.

I leave this one as an exercise. Once the player reaches the graveyard safely, he finds a thighbone, which is then of some (non-mathematical) use to him.

One can even base adventure-type puzzles on Group Theory. Consider, for example the famous 'Fifteen puzzle' of Sam Loyd.

     +----+----+----+----+
     |    |    |    |    |
     |  1 |  2 |  3 |  4 |
     +----+----+----+----+
     |    |    |    |    |
     |  5 |  6 |  7 |  8 |
     +----+----+----+----+
     |    |    |    |    |
     |  9 | 10 | 11 | 12 |
     +----+----+----+----+
     |    |    |    |    |
     | 13 | 15 | 14 |    |
     +----+----+----+----+

Here one has fifteen numbered blocks which can be slided in their four-by-four box, either north-south or east-west, moving one into the empty space at each stage. The challenge (which was a sort of Rubik's cube of the early 20th century) is to exchange 14 and 15. However one can show by group theory that only half the positions are possible, and that the problem as posed is insoluble. To make that seem plausible, consider the 'Three puzzle', which I haven't bothered patenting...

     +----+----+
     |    |    |
     |  1 |  2 |
     +----+----+
     |    |    |
     |  3 |    |
     +----+----+

Here it is obvious that the only re-arrangements possible are cyclic rotations of the pieces.

The idea occurs in a more complicated form in the Relic puzzle in Fyleet.

     O---------O
     |        /|
     |       / |
     |   -O-   |
     | /       |
     |/        |
     O---------O

Here there are four sacred relics which have to be put into the correct rooms, and the supernatural forces are such that no two relics can occupy the same room simultaneously. After a bit of experimenting (or calculation) it turns out that the problem cannot be solved, as you start with one of the set of positions inequivalent to the desired one. However... one of the relics is the Sacred Sunglasses of St Tropez, and wearing them the player is able to see a secret door (linking the middle room with the bottom right room). Using this extra connection, one can now get all possible permutations, and the problem is soluble.

This is a puzzle that requires several stages of solution. Firstly, to work out what one must do; secondly to see that it is impossible; thirdly to find the trick!

Another group-theoretic puzzle occurs in 'L', where one has permute a set of lights by means of switches. For example, one may start with

         O        O        O        O
        red     blue    yellow    green

and have to obtain some other ordering using two switches. One switch swaps the colours of the first two, the second cycles the colours. Again it can be shown by elementary Group Theory that one can obtain any desired ordering.

One fruitful source of puzzles, with a certain mathematical content, is that of Ciphers. Should the adventurer see written on a wall the message

UIF QBTTXPSE JT IPSTF

he or she will guess it to be an encrypted message. If, further, the message is known to be something about passwords (someone somewhere asks you for a password, say) then it is easy to spot that all we have done above is shifted each letter on one in the alphabet, and 'The password is Horse'.

Elsewhere one may find the word TUBS written up; if one says it, maybe the roof falls in - the correct thing to say was STAR: same code! In fact not many English words do give real words when shifted: ANTS becomes BOUT, ADDS becomes BEET, and so on. (I am grateful to Mr Matthew Richards, T.M.S. Dogsbody, for telling me about SHEER and TIFFS, now the longest example I know.)

To decipher the average coded message one tends to need at least 60 characters of text, more if the letter frequencies are unusual (e.g. no E!) (It used to be a habit among Trinity mathematicians to confuse the porters by sending each other coded postcards from wherever they happened to be - Russia being the most exotic.) Thus if one has fewer letters, one needs some context information.

In the game Avon, based on Shakespeare, there is an area called Illyria Court, in which live (Sir Andrew) Aguecheek, Fabian, Orsino, Olivia and Malvolio. Elsewhere, one encounters Othello, who gives one a piece of paper in 'Moor's Code' (such bad puns are common), which is supposed to tell you which of the residents to visit. Thus the paper says one of NOSEBLEED, OVERSEAS, ASTHMA, TEABAG and FUNGUS. Assuming a simple substitution cipher, one can easily verify that only one resident's name can be referred to by any given codeword. Thus, e.g., FUNGUS refers to Fabian (6-letter word, second and fifth letters equal).

These patterns have interested me for some time, especially since I learned that my own name, Partington, has the same pattern as Budgerigar!

One can also hide numbers, e.g. by alphametic-type puzzles. In one Dungeons and Dragons game the players came across an addition sum written as

          ENTER
          ENTER
          ENTER
         ------
         HEROES

together with a magical artefact bearing a dial and a headpiece (in fact remarkably similar to a modern telephone!) It was necessary to solve the puzzle and dial the number corresponding to HEROES to proceed further.

The binary system is another source of good puzzles. One can get away from slot machines taking coins of values 1, 2, 4, 8, ... and construct more elaborate problems. For example, in Crobe, one finds a sword embedded in an anvil near which someone has written the legend "He who draws this sword from the anvil is the rightful Head of DAMTP" (well, in the original it was something else, but this is an Applied Maths puzzle). Various switches nearby have to be thrown to produce a binary representation of some code-number (provided). This turns off an electromagnet in the anvil and allows one to extract the sword, then going forth to multiply (or whatever they do in DAMTP).

In Fyleet, the ternary system is used for the 'hippogriff rides' puzzle. One's coins this time come in the values 1, 3, 9, 27, ... but the price for a ride can be any integral amount. This requires negative money, and nearby one goes through a matter converter, so that coins take negative values. Thus a fare of 20 groats can be paid (uniquely) as 27 + (-9) + 3 + (-1)!

Clearly many Adventure puzzles can be obtained by adapting classical puzzles from the Dudeney era or beyond. Consider the Wolf-Goat-Cabbage puzzle: here one has to cross a stream in a boat, and transport (one at a time) a wolf, a goat and a cabbage. However one cannot leave the wolf and the goat together unattended (at least it does the goat no good); similarly the goat will eat the cabbage if left alone with it. The solution here is to take the goat across first (since it cannot be left with anything else) and continue from there.

Thus, in Fyleet, one sees a poster, which reads:

LOST - ONE WOLF, ONE GOAT, AND ONE CABBAGE. REWARD OFFERED.

Here we have an almost straightforward adaptation of the puzzle (one twist being that the wolf bites you en route and you catch lycanthropy - become a werewolf - unless a remedy is found!)

In 'L', a tree-planting puzzle is borrowed directly. To assist the gardener one has to plant 9 trees in 10 rows of 3: the solution is essentially:

     O   O   O
       O O O
     O   O   O

Similarly, Acheton borrows the Tower of Hanoi puzzle - to transfer a series of flat disc-shaped rocks which are piled up in one room, to another room, without ever putting a larger rock on a smaller. Underneath the largest rock there is secret tunnel...

Then again, in Crobe there is a version of Dudeney's safe puzzle (in the original the secret word was PYX - here a more common word is intended).

The safe door bears 4 dials, each with letters round it thus:

                             B
                            ---
                          Y/   \G
                          X|   |H
                          N\   /K
                            ---
                             M

The man who writes poems on walls has been round again, and his effort this time is

   The safe door be broken
   By word sung or spoken.

In fact one (fairly obvious) English word can be made using just 4 letters, each one of the ones on the dials.

Finally, a puzzle that is mathematically quite intricate - a scheduling problem from Sangraal. This occurs in the endgame, when the Sangraal (Holy Grail) is almost won. You arrive at the castle where the Foul Fiend has imprisoned 8 knights. These are as follows:

Agravain - lightly bound - badly wounded;
Bors - lightly bound - scratched;
Caradoc - bound a bit more - badly wounded;
Dagonet - bound as C - scratched;
Ector - bound and gagged - somewhat wounded;
Feirefiz - in chains - badly wounded;
Gareth - in chains and gagged - somewhat wounded;
Harry - bound really tight in chains (poor chap) - scratched.

Here the state of binding means that it will take 1, 1, 2, 2, 3, 4, 5 and 6 minutes (respectively) to free them: a freed knight then goes away to wash and recover himself physically in time for the Sangraal's arrival. The time he takes for this second stage is 5, 10 or 15 minutes, according to injury. In twenty minutes' time the sun will set and the Sangraal will arrive. How many knights can you bring? We see, for example that if you want F, you must free him almost at once, as he can only be ready in 19 minutes at the earliest. Freeing Harry, though it takes 6 minutes, is not urgent, as he only needs to be freed by the 15th minute. This sort of puzzle has standard algorithms for solving it, but it is at least a bit more interesting than the average optimization exercise!

So what next? Adventure puzzles based on Chess, on the notorious game Neutron, on Complex Variable Theory? These are left as exercises for the reader!

Last updated on December 7th 2002 by Jonathan Partington

No comments:

Post a Comment