Impartial games

Wythoff's game, and the ratio nobody put there

Two heaps, three kinds of move, and losing positions that lie along a line of irrational slope. Nothing in the rules mentions a ratio, a length or a continuous quantity — and the golden ratio comes out anyway.

Two heaps of counters. A move takes any positive number from one heap, or the same positive number from both. The player who cannot move — because both heaps are empty — loses.

That is the whole game, and it is barely a modification of two-heap Nim. Two-heap Nim is settled in a sentence: the losing positions are the ones where the heaps are equal, because whatever one player does to one heap the other copies in the other — the mirroring argument that runs through the whole subject. Adding the diagonal move destroys that argument completely, since a player can now take from both at once and equality no longer protects anybody.

Wythoff's game, and the line the losing squares lie onA queen moves left, down, or diagonally down-left any distance, and whoever cannot move loses. Every square carries the Grundy value the mex rule gives it. The squares worth nothing — the ones a player wants to hand over — lie along two lines whose slopes are the golden ratio and its reciprocal, in a game with no geometry and no continuous quantity in its rules.012345678910111213141204537861011913141220153486711910141213345620191012871511164532769018131211161553406810127121491517678191034513021617187869014531415131721086710125341516171809910111287131415161761951101198131201516171418762119107121421317618158192012131415119161718197810202113141211161517205619209714121316151718109122021711the value of the position with the queen on that square11 squares worth nothingevery one of them on the linesof slope φ = 1.6180…checked against ⌊nφ⌋, ⌊nφ²⌋and the table was never toldleft, down, or diagonally — a queen's moves, restricted to towards the corner
Fig. 1 Every position with both heaps at most fourteen, with the value the mex rule computes for it. The shaded squares are worth nothing — the ones a player wants to be handing over rather than receiving — and the dashed lines through them are drawn from the golden ratio, which nothing in the computation was told about.

The board

It is easier to see as a board than as two heaps. Put a queen on a square of a quarter-infinite chessboard whose corner is at the origin; the coordinates are the two heap sizes. Taking from the first heap moves the queen left, taking from the second moves it down, and taking equally from both moves it diagonally down and to the left. The corner is the position with nothing left, and whoever is forced to sit there having no move has lost.

So the game is a queen restricted to moving towards the corner. That is the version Willem Wythoff described in 1907, and it is the reason the game has a picture at all.

The cold squares

Call a square cold if the player who has to move from it loses. The corner is cold: no move exists at all. Every square a queen can reach the corner from in one move is therefore hot — a player standing on it wins by going there.

The rest follows by the usual recursion. A square is cold exactly when every move from it leads to a hot square, and hot when some move from it leads to a cold one. That is the same rule that gives every impartial position a Nim value, specialised to the question of whether that value is zero.

Running it produces the shaded squares in the figure above, and the first few are easy to read off:

(0,0),(1,2),(3,5),(4,7),(6,10),(8,13),(0,0), \quad (1,2), \quad (3,5), \quad (4,7), \quad (6,10), \quad (8,13), \ldots

together with the mirror images, since the game does not care which heap is which.

Two patterns are visible immediately and both are worth stating, because one of them is the answer and one of them is not.

The differences between the two coordinates go 0,1,2,3,4,5,0, 1, 2, 3, 4, 5, \ldots — the $n$th cold pair has a gap of exactly nn. That is a real pattern and it is easy to prove, and on its own it identifies nothing, because it does not say what the smaller coordinate is.

The smaller coordinates go 0,1,3,4,6,8,0, 1, 3, 4, 6, 8, \ldots, and every non-negative integer appears exactly once somewhere in the list — either as a smaller coordinate or as a larger one, never both and never twice. That is the fact the answer hangs on.

Nim with heaps of 3, 5Heaps of counters; a move takes any number from one heap. The position is a loss for the player to move exactly when the binary digits of the heap sizes cancel in every column — the nim-sum — and that is the whole of the theory of Nim.30115101nim-sum110= 6some column does notthe player to move winstake 2 from the heap of 5outcome N
Fig. 2 The same position under ordinary Nim, where taking from both heaps at once is not a move. Two heaps of three and five have nim-sum six, so Nim calls this a win for the player to move — and Wythoff’s game calls it a loss. One extra kind of move has changed the answer.

That comparison is the thing to hold on to. The position (3,5)(3,5) is a first-player win at Nim and a first-player loss at Wythoff’s game. The board is the same, the counters are the same, and one additional move has turned the theory inside out — which is a reminder that a Grundy value is a fact about a rule set and not about a pile of objects.

How a square gets its number

The shading is only the zeros, and it is worth seeing where the rest of the table comes from, because the recursion is the only thing in this essay that is doing any work.

The smallest one missingThe Grundy value of a position is the least non-negative integer that is not the Grundy value of any option. That single rule turns any impartial game into a Nim heap, because a heap of that size has exactly the same set of reachable values.012345the values the options havethe smallest missing one is 2so this position is worth ∗2options: 0, 1, 3present · absent — and the first absent one is the answer
Fig. 3 The rule applied to one square. Every move from it leads somewhere whose value is already known; the square takes the smallest non-negative integer that is not among them. A square whose options include every value from zero upwards except nothing at all is worth zero, and a square worth zero is one nobody wants to be standing on.

The options of a square are unusually numerous — an entire row, an entire column and an entire diagonal — which is why the zeros are so sparse. A cold square has to avoid every value in three whole lines, and that scarcity is what forces them onto a line of their own.

Wythoff's game, and the line the losing squares lie onA queen moves left, down, or diagonally down-left any distance, and whoever cannot move loses. Every square carries the Grundy value the mex rule gives it. The squares worth nothing — the ones a player wants to hand over — lie along two lines whose slopes are the golden ratio and its reciprocal, in a game with no geometry and no continuous quantity in its rules.012345678912045378610201534867113456201910124532769018534068101276781910345137869014531486710125341591011128713141516the value of the position with the queen on that square7 squares worth nothingevery one of them on the linesof slope φ = 1.6180…checked against ⌊nφ⌋, ⌊nφ²⌋and the table was never toldleft, down, or diagonally — a queen's moves, restricted to towards the corner
Fig. 4 The same table on a smaller board with the lines left off, so the zeros can be looked at without a slope being suggested. Two per row and column at most, thinning as the board grows, and never two in the same row, column or diagonal — which is the geometric restatement of the fact that a queen can always move from a hot square to a cold one.

The last property is worth naming because it is the whole strategy in one sentence: no two cold squares attack each other. If two did, a player standing on the first could move to the second and hand a lost position back, and “cold” would be self-contradictory. So the cold squares form a set of mutually non-attacking queens, which is the connection to the name Wyt Queens and the reason the game is drawn on a board at all.

Where the ratio comes in

Take the two sequences of coordinates:

an=0,1,3,4,6,8,9,11,bn=0,2,5,7,10,13,15,18,a_n = 0, 1, 3, 4, 6, 8, 9, 11, \ldots \qquad b_n = 0, 2, 5, 7, 10, 13, 15, 18, \ldots

with bn=an+nb_n = a_n + n, which is the gap pattern already noticed. Between them they use every non-negative integer exactly once.

A pair of sequences that partitions the integers like that, each of the form nα\lfloor n\alpha \rfloor for a fixed α\alpha, is called a Beatty pair, and there is a clean condition for when it happens: two such sequences partition the positive integers exactly when

1α+1β=1\frac{1}{\alpha} + \frac{1}{\beta} = 1

with α\alpha and β\beta irrational. Combine that with bnan=nb_n - a_n = n, which forces β=α+1\beta = \alpha + 1, and there is one equation left:

1α+1α+1=1α2=α+1.\frac{1}{\alpha} + \frac{1}{\alpha+1} = 1 \quad \Longrightarrow \quad \alpha^2 = \alpha + 1.

The positive root is the golden ratio. The cold positions are

(nφ,  nφ2),φ=1+52,\left(\lfloor n\varphi \rfloor, \; \lfloor n\varphi^2 \rfloor\right), \qquad \varphi = \tfrac{1+\sqrt5}{2},

and the second coordinate is the first plus nn, because φ2=φ+1\varphi^2 = \varphi + 1.

The identity φ2=φ+1\varphi^2 = \varphi + 1 is the golden ratio’s entire content and is the property everything else about it descends from; it is not re-derived here. What is worth stopping on is that the equation arrived from a partition condition and a difference pattern, with no geometry, no rectangle and no limit anywhere in sight.

What the solver computed, and how

The table in the first figure is built by the mex rule, and the code that builds it has never seen φ\varphi.

For each square (a,b)(a,b) in increasing order, the option set is assembled: every square to the left, every square below, and every square diagonally down-left. Their values are already known, and the value of (a,b)(a,b) is the smallest non-negative integer missing from that set. The cold squares are those with value zero.

The formula is then computed separately — nφ\lfloor n\varphi \rfloor and nφ+n\lfloor n\varphi \rfloor + n, in double-precision floating point — and the two sets are compared as sets. The figure refuses to draw if a single square is in one and not the other, and the site’s gate makes the same comparison out to heaps of forty.

A comparison that can only pass is not evidence, so the gate also runs it with the wrong constant. The silver ratio 1+21+\sqrt2 is the obvious near-miss — the same kind of number, arriving from the same kind of equation — and its pairs are not cold. Several of them fail immediately, and the gate requires them to.

Grundy values for subtraction of 1, 2The Grundy value of every heap size for a take-away game, computed by the mex rule. A period, if the figure marks one, was found by searching the computed sequence rather than assumed — and where no period is marked, none was found in the range drawn, which is not the same as there being none.001201420128012012120116201220012024heap size, and the value of a heap that bigperiod 3 from heap 0, holding through all 2001 values computeda heap of size n is worth ∗g(n) — and the whole game is the nim-sum of its heaps
Fig. 5 For contrast, a one-heap game with a period. Wythoff’s cold positions are not periodic in either coordinate and never become so — the gaps between consecutive cold squares follow the golden ratio’s continued fraction rather than repeating, which is what an irrational slope means in a picture made of squares.

Playing it

The strategy that comes out of the table is unusually satisfying to execute, because it can be followed by a person with the first few cold pairs memorised.

From a hot square, some move reaches a cold one; find it and play it. From a cold square there is no such move, so anything is as good as anything else and the game is already lost against an opponent who knows the list.

Wythoff from (5, 8) — and who winsA Wythoff position with the outcome named before anybody moves. The queen slides left, down or diagonally down-left, and whoever cannot move loses. Every reply was computed in advance from the table of values, so the machine is reading a theorem rather than searching, and a reader who wins has found a mistake in the table.shaded squares are worth nothing to the player who must move from themthe player to move winsstated before a move is madeyou move firstwith the script running, the squares the queen can reach become clickable and this claim can be tested
Fig. 6 The queen starts on a square that is not shaded, so the player to move wins — that is stated before anything happens. Every reply was computed from the table at build time, so the machine lands on a shaded square whenever one is in reach, and from a shaded square there is always one in reach.

The demonstration is worth attempting rather than reading about. The claim is not that the machine plays well; it is that the machine plays the move the table names, that the table is the mex recursion, and that there is consequently no line of play from a hot start in which the machine loses.

There is one honest caveat in the figure. The board is finite, so a few squares near its edge have options that would leave it, and those are simply not offered. A player who wants the real game should imagine the board continuing.

Where the model stops

This is one game, not a family. Wythoff’s game has a closed form for its cold positions. Almost no impartial game does. Octal games mostly have periodic Grundy sequences and no formula at all, and the ones that resist periodicity have neither. Wythoff’s game is a beautiful exception, and treating it as typical would be a serious misreading of the subject.

Cold positions are not the same as values. The figure shows the full Grundy table, but the golden-ratio result is only about the zeros. The non-zero values in Wythoff’s game have their own structure, and it is considerably less tidy — no formula of comparable simplicity is known for the value of an arbitrary square. The zeros settle who wins; the rest of the table is what would be needed to add this game to another one, and that part has no closed form.

The convention is normal play. Under misère play, where the player unable to move wins, the answer changes and the golden ratio does not survive the change. That is the usual situation, and it is worth saying explicitly whenever a result this pretty appears.

The formula is checked, not proved, by the machinery here. The comparison covers heaps up to forty. The proof — that the Beatty condition and the difference pattern together force the cold set — is a paragraph of argument and is not something a table can supply.

The generalisation

Wythoff’s game generalises in a direction that is more surprising than it sounds. Allow the diagonal move to be unequal — take pp from one heap and qq from the other, with pq|p-q| bounded — and a whole family of games appears whose cold positions follow lines of other irrational slopes, each the root of a quadratic determined by the bound.

So the golden ratio is not doing anything mystical here. It is the answer to a particular quadratic, and the quadratic comes from the particular move set. Change the moves and the constant changes with them, in a way that can be predicted.

That is the correct reading of every appearance of φ\varphi in this subject, and it is the reading that survives contact with the surrounding literature, much of which is not careful.

Reading a heap size instead of a table

There is a way to decide a position without the list, and it is the most practical thing the golden ratio buys.

Every positive integer has a unique representation as a sum of non-consecutive Fibonacci numbers — 12 is 8+3+18+3+1, 30 is 21+8+121+8+1, and no representation ever uses two neighbours in the sequence. Write both heap sizes that way, and the status of the position can be read off the last term of each: a position is cold exactly when one representation ends in an even-indexed Fibonacci number and the other is its shift.

That is the same fact as the formula, in a different alphabet. Multiplying by φ\varphi is, in this representation, shifting every term one place along the Fibonacci sequence — which is what φ2=φ+1\varphi^2 = \varphi + 1 says when it is applied to a sum rather than a single number.

The practical upshot is that a player can decide a position of any size with arithmetic small enough to do in their head, and does not need the table the first figure drew. That is not true of most games in this subject, where the value of a position of interesting size is out of reach of any exact evaluation.

What the picture cannot show

The table is finite and the game is not, and the two differ in a way the shading quietly hides.

A drawn board stops at fourteen, so the squares along its top and right edge have had options removed — the moves that would have gone off the board. Their values in the figure are the values they would have in the real game, because every move goes towards the corner and never away from it, so nothing outside the drawn region is reachable. That is a genuine property of this particular game and is why the picture is honest; it would not hold for a game whose moves could increase a coordinate.

What the picture does hide is the irrationality. Any finite patch of shaded squares is consistent with infinitely many slopes, rational ones included, and the eye cannot tell φ\varphi from a close rational approximation over fourteen rows. The claim that the slope is irrational is not something the figure demonstrates — it comes from the partition argument, and the figure’s job is only to show that the computed zeros and the formula’s pairs are the same set as far as both were taken.

The same caution applies to the strategy. Knowing a square is cold says the player to move loses; it does not name the move, because from a cold square there is no good move to name. Knowing a square is hot does name one, and the figure gives it.

Who found it, and when

Willem Abraham Wythoff published the game in 1907 in a Dutch journal, under the title of a modification of Nim, and gave both the queen picture and the closed form.

Samuel Beatty’s theorem on the partitioning sequences dates from 1926, so Wythoff found the sequences without the general result that explains why they partition. The two were connected afterwards, which is the usual order of events.

The game turns up under other names — Wyt Queens in Winning Ways, and Tsyanshidzi or “picking stones” in a Chinese tradition that predates the European publication — and the independent appearances are a reasonable sign that the rule is a natural one rather than a construction built to have a pretty answer.

The ladder from here

This is the base rung of its own anchor, and the ladder above it is unusually concrete.

Later rungs: the proof that the Beatty condition forces the cold set, which is short and worth doing properly. The generalised games with an unequal diagonal and the family of quadratic constants they produce. The Grundy values of the non-zero squares, and why they resist any description as neat as the periodic sequences a one-heap game produces. The connection to Fibonacci representations, in which a heap size written in a base of Fibonacci numbers reveals its status directly. And the misère version, which is worse behaved than the normal-play version by exactly the amount misère play usually costs.

The thing this rung establishes, and which the rest depend on, is that the table came first. The formula was checked against a recursion that had never been told what it was looking for, and that is the only reason the agreement means anything.