The Game of NIM

NIM is not a game that needs heavy computer power... It is traditionally played using several piles (or 'heaps') of matches, each heap containing an arbitrary number of these at the start. Two players take turns in removing one or more matches from a heap. The game ends when all the heaps have been emptied.

There are a number of variants on the game, of which NIMROD knows two. In the simplest game, the player who takes the last match wins. NIMROD will also play the somewhat more interesting 'reverse' game, where the one who takes the last match loses. In both games, a player may only remove from a single pile at each turn, but may take as many of the remaining items in that as they wish.

NIMROD, of course, replaces piles of matches with rows of lights. For simplicity, it is limited to four rows ('heaps') with at most seven lamps in each.

NIM is interesting in that there is a non-obvious optimal strategy that ensures a win for one player (which one depending on the numbers of matches in the heaps at the start). NIMROD naturally uses this strategy, which is explained in the original booklet, included with this manual.

You may also be interested to know that the actual operation of this program is as close as possible to the original hardware. The "NIM Machine" is constructed of logical elements — Gates and Flip-Flops — that are connected together just as they were in the computer itself. The correspondence is not exact of course. For one thing, detailed schematics were not available. In the sections of which I do have a description, the elements and their connections are essentially identical. (Although parallel, direct-coupled logic can naturally only be approximated by a serial program!)

The Control Desk



All play of the game, and control of the various options in NIMROD, is through the buttons and switches on the control desk.

The Lights

Each row of coloured lights represents one heap of 'matches'. The number of matches remaining in the heap is indicated by the lights that are lit. The white light at the left of each row is not really part of the game state — it simply indicates which heap was last changed (by either player) during game play. In the setup phase, as an indication, all the lights are lit. [I suspect the real reason for the eighth column of lights is that the orignal designer of the panel liked symmetry...]

The Buttons

You operate a button on the desk as you would expect, simply by pressing the left mouse-button while the cursor is over it. It will always respond — like real hardware — by being 'depressed', but it will only have any other effect when it is appropriate in the sequence of the game.

The button adjoining any light will leave that many lights lit in the row (when appropriate). To leave no lights lit you of course click the leftmost button.

The two buttons at top centre of the panel control the computer's moves:

COMP. MOVE

Whenever it is the computer's turn to move, you must always press this button to ask it to do so.

STEP

This button is only functional when the instructions are being manually stepped. Each press and release advances the sequence by one full step.

The Switches

Each of the siz lever switches at the top of the panel has two positions, which will be referred to as "Set" and "Unset". ("On and "Off" don't quite seem suitable.) Unset is with the handle vertical; Set is with it slanted away from you (and to the left as you are viewing the desk during the game). In the sketch above, the leftmost switch is shown Set.

A switch is operated by grabbing it with the left mouse button and dragging in the desired direction (left for Set, right for Unset). If all this seems a little left-handed [aside from the fact that I am...!] remember that at the actual machine the demonstrator would be sitting across from you, so the switches are appropriate for him — and presumably the labels would actually be the other way up too!

From left to right the switches are:

SETUP / PLAY

You do the initial setup of the game with this switch in the Unset (vertical) position, choosing the number of matches to be in each heap, and setting the other switches to desired options. The game begins when you move it to the Set position.

SIMPLE / REVERSE GAME

In the Simple game (Unset position) the winner is the player who takes the last match. In the Reverse game, the one forced to take the last match loses.

OPPONENT / COMPUTER STARTS

When this switch is Unset, you are expected to make the first move. With it in the Set position, the computer will take first crack (when you press the COMP. MOVE button).

AUTO / MANUAL INSTRUCTION STEPPING

In AUTO mode, the computer runs intself completely through its program on each move once you've pressed the COMP. MOVE button. In MANUAL, you step it through the sequence yourself — using the STEP button —, so you can watch its operation at your own pace.

FAST / SLOW STEPPING

(Only functional in AUTO mode.) With the switch in the FAST position, the computer makes its move essentially instantaneously when you press the COMP. MOVE button. In SLOW mode it goes at about one step per second, so you can observe its sequence of logic.

PLAY OPPONENT / PLAY SELF

If you set ths to PLAY SELF, the computer will take the part of both players. Pressing the COMP. MOVE button causes it to make each player's move alternately. The heap buttons are not active in this mode.

Note that switches nay be flipped without harm at any time, but they do not always take effect immediately when the game is already in progress.

Playing the Game

Setup

Before you can play, you must put some matches in the heaps. With the leftmost switch in the SETUP position, click on one button in each row to determine the starting number. (As long as you are in SETUP you can freely add or remove from any row.) For example, you might light seven lamps in the top row, one in the second, six in the third and four in the last. (These numbers are completely arbitrary, but that choice would actually allow you to win... if you know how...! (grin)]

Play

Once you've settled on a suitable configuration of matches, flip the left switch to the PLAY position, and the game starts. With the other switches in their default Unset position, you get the first move, so choose a row, decide how many lights you want to remain lit, and press the button corresponding to the rightmost lamp you want to keep lit. (You must turn off at least one lamp in the chosen row.) Make your choice before you press the button — you only get one chance!

Press the COMP. MOVE button to tell the machine to make its move. It will remove some lights from a row it chooses, and return control to you for your next move. Play continues in this way until the last match is taken. In the Simple game, the taker is the winner. If you've set the REVERSE switch, the taker is the loser.

Once you're familiar with the Simple game, you can flip other switches on the Control Desk to vary the action (see 'The Switches' above):

Try the Reverse game, by setting the second switch from the left.
The next one over instructs the computer to start first.
Set SLOW or MANUAL mode using switches on the right, so you can watch the machine 'thinking' about its move.



The Main Facade

The main NIMROD Facade — the background picture while you're playing the game, but 9 feet by 12 feet in real life — has three display panels that show the operation of the machine in more detail. (Below these are the racks of valves that perform the actual logic of the machine.)

Only the centre panel is meaningful in normal-speed play. The two side panels (although illuminated in all games) are just used in SLOW and MANUAL modes to illustrate the computer's steps in making a move.

Centre Panel — Game State Display

The rows of lights in the upper section simply echo the coloured ones on the Control Desk. Below these are a set of indicator panels that show the state of the game. You might just be able to read the legends as they are illuminated during the game, but here are rather clearer versions:

You will only see the bottom line illuminated during SLOW or MANUAL mode. The one above it is really a request for you to press COMP. MOVE. The other legends should be self evident.

Left Panel — Instruction Display

This panel shows the instruction currently being executed by the computer during SLOW and MANUAL operation. You definitely can't read these legends on the active screen, so they are reproduced below. They probably won't be immediately informative even so. They relate to the full description of the computer's algorithm — given in The NIMROD Guide. Decisions at each (possible branching) step depend on the information shown in the right-hand panel.

The branch arrows that appear on the live display are not reproduced here. They simply show if a branch mentioned in the current step will actually be taken.

Right Panel — Block Schematic Display

Here are shown (meaningfully in SLOW and MANUAL modes only) some of the internal regusters used by NIMROD to make its decisions. Again you will need to have knowledge of NIMROD's workings (from the Guide) to decode this panel.

At upper centre of the panel is a display of the Main Store, which holds the state of the rows in binary form. Below this are the binary values of the Heap (i.e. Row) and Column counters used to examine the game position. There are also lights adjacent to each row and column (not seen in the sketch) that show the decoded column and row references. Right at the bottom is the legend that is illuminated when the machine has selected a heap to operate on.

The green panels shown in the sketch are simply labels denoting specific subsections of the computer's circuitry.

The NIMROD Machine — Some Facts and Figures

The original machine stood 9 feet ny 12 feet by 5 feet, but most of this was just to house the display [and impress the crowds...?]. Electronics took up less than 2% of that volume. It ran at a healthy six kilowatts, though four of these were for the display lamps.

It housed 480 valves, all 12AT7 double-triodes. Only 350 of them actually took part in the action; the rest were spares being "burned in". 120 relays drove the displays. A few germanium diodes were used as 'OR' gates. Most of the connections were directly soldered — rather than using pluggable connectors — for reliability. (This, however, made for difficult transportation!)

Unlike most digital computers, then and now, NIMROD used directly-coupled voltage levels rather than clocked pulses, so it could run as slowly as the demostrator wished. When run at full speed, it was driven by 10kc/s steps [10kHz in modern parlance].

Designing a processor was no doubt rather simpler in those days, but work on the design was begun on 1 December 1950, and it was delivered on 12 April 1951. The Science Exhibition opened on the 5th of May, and ran through September. Unlike transistors, valves burn out, so there were a few failures, but it seems these were easily traced, amd things would be running again in an hour or so. There was one original wiring mistake that early on caused a couple of errors a day, but once this was found it ran flawlessly.

Caveats and Cheats

As mentioned in the beginning, an attempt has been made to keep as close as possible to the original operation of the machine. However, the source documents were one original guide booklet (reproduced in this documentation) and an article in a 1951 Electronic Engineering journal. So information is highly incomplete, and considerable imaginative licence has been employed at many points.

The simulation logic has been built fairly straightforwardly from the description of the algorithm, and probably corresponds reasonably to the original. In a few places, where a portion of the circuitry was described in the article — such as the 'column adder' — the replication should be fairly exact.

There are definitely a number of shortcomings, though. The original NIMROD, for example, was able to play 'Multiple NIM', where more than one heap could be altered in a turn. Only a sketchy algorithm for this is mentioned, and it rather conflicts with the way operation was displayed ('HEAP SELECTED' particularly) so no attempt was made to add it to the simulation.

Most of the Facade display could be reconstructed exactly, but there are probably gaps and inaccuracies in the 'Block Schematic' panel. The labels in the "green" panels [in fact the colours used in the reproductions as well] are pure guesswork, as they are indecipherable in the photo. There may have been some additional lamps in those areas, but there is no indication as to what they might have been.

The exact Control Desk switch functions are also unknown, although the options provided here must have been included. Some switches doubtless had more than two positions, and would handle the options — like Multiple NIM — that haven't been replicated. There probably was some more flexible speed control, rather that just 'FAST' and 'SLOW' as here.

Administration

Copyright and Distribution

The NIMROD Simulation, its source code, this documentation and associated images are Copyright 2001 by Peter J. Goodeve.

The package is freely distributable without restraint, provided that it is kept complete as supplied.

Complete source to the program is available, but at the moment only on request... [It's really not suitable for public viewing as yet! Needs a lot of cleanup and commenting.]

References and Links

All the information to construct this simulation came from two sources: the little book published at the time to explain the computer, and an article in Electronic Engineering (UK journal). The first is reproduced in its entirety in this package. The other is:
"Nimrod -- A Small Automatic Computer" R. Stuart-Williams [Electronic Engineering Sept 1951 pp 344-348]

There are many more facts and details about early computers at many sites on the Web. The Ferranti Mark I has a detailed page at:

" http://www.computer50.org/mark1/FM1.html
The parent site (www.computer50.org) has much more about other machines born of the Manchester University Computer Group.

You can learn more about the 1951 Festival of Britain (but not much about the Exhibition of Science) at these Websites:
"Festival of Britain" — http://www.packer34.freeserve.co.uk/
"1951 Festival of Britain" — http://members.spree.com/thearts/gbex/1951.htm

Pete Goodeve, the author of the simulation, can be reached at:

pete.goodeve@computer.org