Impartial games

Cram is played in pieces, and the pieces are small

A table of Cram rectangles answers the opening and nothing after it. Of the 58,830 positions reachable on a 4 × 5 board, 86% have already fallen into pieces no domino can cross, and the exclusive-or of the pieces' values is right on every one. The pieces come in 2,304 shapes, thirteen of them rectangles; two in five pieces are worth nothing at all; and no shape of up to eleven squares is worth more than ∗4.

Assumes: Cram · The board falls apart, and the arithmetic changes

Cram is Domineering with the orientations shared: either player may place a domino either way up. That one change makes the game impartial, and the Sprague–Grundy theorem then says every position is a Nim heap. The essays on Cram so far have read that heap off rectangles — the empty boards, the pairing strategy that settles the even-by-even ones, and the same boards under misère play.

A rectangle is a position exactly once in a game: before the first move. After it, the board is a rectangle with holes, and a few moves later it is usually not one board at all but several. The question a player actually faces is the value of a board in pieces, and the theorem’s other half — that a sum of games is worth the exclusive-or of its parts — says how to answer it. Split the free squares into the pieces no domino can cross, look each piece up, and exclusive-or.

That turns “solve Cram” into “keep a catalogue of shapes”, and the useful questions are about the catalogue: how many shapes it needs, how many of them are rectangles, and how large the numbers in it are.

A Cram position read as its pieces. A 4 × 5 Cram board after 3 dominoes, its free squares split into 3 pieces worth ∗1, 0, ∗2. The exclusive-or, 3, is the value of the whole board, which a search of all 58,830 reachable positions confirms is how every position adds up.
Fig. 1 A 4 × 5 board after three dominoes has fallen into three pieces: two squares, four squares and eight. Their values are ∗1, 0 and ∗2, and the board is worth their exclusive-or, ∗3 — a win for the player to move, read without searching the board.

Reading the worked position

The three pieces in the figure are worth looking at one at a time, because each is a different kind of entry.

The two-square piece is a domino-shaped slot. It has exactly one move, which fills it and leaves nothing, so its only option is worth nought and the slot is worth ∗1\ast 1. Every two-square piece in Cram is this game, whatever its orientation, which is why it is the second-commonest entry in the catalogue and the cheapest to know.

The four-square piece is the 2 × 2 square. Whichever of its four dominoes is placed, what is left is another two-square slot, worth ∗1\ast 1. A position whose every option is worth ∗1\ast 1 has mex nought, so the square is a loss for whoever must move in it — a second-player win sitting inside a first-player win.

The eight-square piece is the only one that needs a search, and the search is short because it too breaks up. Each domino placed in it leaves one or two smaller pieces, every one of which is already in the catalogue, and the mex of the exclusive-ors is ∗2\ast 2. A shape’s value is computed from smaller shapes only, so a catalogue fills itself from the bottom: every entry is a mex over exclusive-ors of entries already present.

The sum, checked rather than assumed

The arithmetic in the figure is the theorem, and the theorem does not need checking. What does need checking is that the pieces were found correctly — that two squares which touch only at a corner are in different pieces, since no domino covers a diagonal, and that a lone square is a piece worth nothing.

So the check is made against the whole board. Every position reachable from an empty 4 × 5 board — 58,830 of them — is evaluated twice: once by a mex search over the whole board’s dominoes, which knows nothing about pieces, and once by splitting it, looking up each piece’s value and taking the exclusive-or. The two agree on every one of the 58,830, and on every position of the 3 × 4, 4 × 4 and 3 × 6 boards as well.

That makes the catalogue a tool rather than a table. A board need never be searched as a board once its pieces are known; the search moves to the pieces, and a piece seen once is never searched again.

Most positions are already in pieces

Positions against shapes. Every position reachable on four Cram boards, split into pieces. On 4 × 5, 58,830 positions break into 154,512 pieces of only 2,304 distinct shapes, 13 of them rectangles, and the exclusive-or of the pieces gives every position's value.
Fig. 2 Every reachable position on four boards, split into pieces and the pieces sorted into shapes. On 4 × 5, 86% of positions are in two or more pieces, the 154,512 pieces come in 2,304 shapes, and 41% of all pieces are worth nothing.

The first column after the positions is the reason the catalogue matters. Five in six positions on a 4 × 5 board are already sums: 50,806 of the 58,830 have two or more pieces. On the small 3 × 4 board it is two in three. A Cram position stays whole only for the first few moves, because the board is narrow and every domino placed along a short side cuts it.

That matches what the count for Domineering found on a 4 × 4 board, where 47% of positions are in pieces, and it runs higher here for an unsurprising reason: Domineering’s players are each confined to one orientation, so play stops earlier, while a Cram board is filled further before anyone runs out of moves — and a fuller board is a more broken one.

The second number is the compression. 58,830 positions, 154,512 pieces, 2,304 shapes. A solver that keeps a table of positions keeps 58,830 entries; one that keeps a table of shapes keeps 2,304 and answers the same questions by exclusive-or. That is a factor of twenty-five on a board of twenty squares, and it grows with the board: the same count on 5 × 5 gives 1,125,703 positions and 16,457 shapes, a factor of sixty-eight.

Thirteen rectangles

Of the 2,304 shapes on 4 × 5, thirteen are rectangles. Everything else a player meets is an L, a T, a staircase, a ring, a strip with a bump on it.

So a table of rectangles — the kind the values of every small board built for Domineering, and the kind the first Cram essay printed — covers less than one per cent of the shapes play produces. It answers the opening move and almost nothing after it. The catalogue a solver needs is a catalogue of polyominoes, and that is a different and larger object than any table of boards.

What a quarter turn buys, and why only Cram gets it

A shape and its rotation by a quarter turn are the same Cram region: the rules do not distinguish vertical dominoes from horizontal ones, so turning the board changes nothing. The catalogue can therefore store shapes up to all eight symmetries of the square.

Domineering cannot do this. Left places vertical dominoes and Right horizontal ones, so a quarter turn exchanges the players and turns a value into its negative. The Domineering catalogue stores shapes up to reflection and half-turn only — four symmetries, not eight.

The table above prints both counts, and the saving is not what one might expect. On 4 × 5 the quarter turn reduces 2,572 shapes to 2,304, about a tenth. On 3 × 6 it saves seventeen shapes in 799. Only on the square board does it nearly halve the table, 379 to 198, because only there does every piece have room to appear in both orientations. On a narrow board most shapes fit only one way round, and a symmetry that maps a shape to something that cannot occur saves nothing.

The values are tiny

The second thing that makes a Cram catalogue cheap is what each entry holds. A Domineering region’s entry is a canonical form — a number, a switch, an infinitesimal, a nested expression in braces. A Cram region’s entry is one small integer.

The value of every small Cram region. The Grundy value of every polyomino of one to eleven squares played as a Cram region, counted by value. The counts of shapes are the standard 1, 1, 2, 5, 12, 35, 108, 369, 1,285, 4,655 and 17,073; no shape in range is worth more than ∗4.
Fig. 3 Every polyomino of one to eleven squares, 23,546 shapes in all, played as a Cram region. None is worth more than ∗4, and the sizes leave odd gaps: no seven-square region is worth ∗2, and no region of six squares or fewer reaches ∗4.

No region of up to eleven squares is worth more than ∗4. That is over 23,000 shapes, and every one of them is a three-bit number. On the 4 × 5 board, where pieces run to twenty squares, the largest value any piece takes is ∗7, first reached by pieces of sixteen squares; the whole 4 × 5 rectangle is worth only ∗2.

The values are small for a reason the mex rule makes plain. A region’s value is at most the number of distinct options it has, and options are counted after exclusive-or — two different dominoes that leave pieces worth ∗1\ast 1 and ∗2\ast 2 and pieces worth ∗3\ast 3 and nought both give ∗3\ast 3. The exclusive-or of small numbers is small, so the options pile up on a few values and the mex stays low. A Grundy value grows only as fast as the variety of what is left after a move, and in a region broken by every domino that variety grows slowly.

The census also has gaps that nothing explains. No seven-square region is worth ∗2, though 49 are worth ∗1 and 50 are worth ∗3; at eight squares the ∗2s return, 48 of them. Parity alone does not do it — a seven-square region leaves five squares after a move, and five-square regions are worth ∗2 three times in twelve. The census records the gap and does not account for it.

Two in five pieces are worth nothing

A region worth nought can be dropped from a sum without changing anything. On 4 × 5, 41% of all the pieces that occur are worth nothing, and the share barely moves across the four boards, from 40% to 43%.

The commonest pieces of a 4 × 5 board. The twelve shapes that occur most often as pieces of positions reachable on a 4 × 5 Cram board, with their values and counts. A single square, worth nought, occurs 49,234 times; a two-square piece, worth ∗1, 36,895 times.
Fig. 4 The twelve commonest pieces in 4 × 5 play, with their values and how often they occur. A lone square — no domino fits — is the commonest by far; a two-square slot, worth ∗1, is next; and the 2 × 2 square and the P-shaped five are both worth nothing.

Most of that is lone squares. A single free square is the commonest piece in play, 49,234 times on 4 × 5, and it is a game with no moves: worth nought, and it is the dead space every board accumulates. But not all of it. The 2 × 2 square is worth nothing too — any domino leaves a domino-sized slot, so the mover always leaves ∗1 and the square is a second-player win — and so is the five-square P. A solver that drops every zero piece before it looks anything up works with three fifths of the pieces it was handed.

The twelve pentominoes as Cram regions. All twelve pentominoes as Cram regions with their Grundy values. Eight are worth nought, three are worth ∗2 and one is worth ∗1.
Fig. 5 All twelve pentominoes as Cram regions. Eight are worth nothing; three are worth ∗2; one — the plus sign — is worth ∗1, and it is the one pentomino a 4 × 5 board never isolates.

The pentominoes show how much nought there is in small regions. Eight of the twelve are worth nothing. The straight five is Dawson’s Kayles on a heap of five, since a domino on a strip removes two adjacent squares and may split what is left — and Dawson’s Kayles at five is nought. The other seven zeros have no such name and no common reason; each is a second-player win because of how its dominoes happen to leave ∗1s and ∗2s.

A catalogue of everything is mostly shapes play never makes

There is a temptation, once the catalogue is seen to be a catalogue of polyominoes, to build the obvious one — every polyomino up to some size — and be done. The census above is exactly that object to eleven squares. But play does not visit most of it.

Which shapes play makes. For each size from one to eleven squares, how many of the possible polyominoes actually occur as pieces of a 4 × 5 Cram board. Every small shape occurs; by eleven squares only 255 of 17,073 do.
Fig. 6 For each size, how many of the possible polyominoes ever occur as a piece on a 4 × 5 board. Every shape up to four squares occurs; all but the plus sign at five; then the share collapses, to 255 of 17,073 at eleven squares.

Every shape of up to four squares occurs on a 4 × 5 board, and eleven of the twelve pentominoes — the plus sign never does. Walling it in needs all eight squares around it covered by dominoes that point away from it, and on a board four squares deep the dominoes that would do it run into one another. From six squares on the coverage falls off a cliff: 78 of 108 at seven, 168 of 369 at eight, 255 of 17,073 at eleven. Most polyominoes of moderate size are too ragged to be cut out of a rectangle by dominoes; a domino’s cut is straight and two squares long, and the shapes it leaves are ones a straight cut can leave.

That is the same lesson the Domineering catalogue ordered by frequency taught: a catalogue by size is mostly entries play never consults. In Cram it arrives sooner and harder, because the board is cut in both orientations at once. A Cram catalogue worth building is the shapes a rectangle can be cut into, not the shapes there are.

What filling the catalogue costs

The bottom-up filling has a price that is easy to state. To know a shape, try each of its dominoes — a shape of nn squares has fewer than 2n2n — split what is left, and look up the pieces. Nothing is ever searched twice, because the pieces are smaller and already known. The whole census of 23,546 polyominoes to eleven squares is filled that way in a few seconds, and the values of the 2,304 shapes that occur on 4 × 5 come out of the same recursion with no reference to the board at all.

Compare the board-first search. It stores a value for every reachable set of covered squares on one board, and a table built for 4 × 5 says nothing about 3 × 6: the masks mean different squares. A shape table is portable. The 2 × 2 square is worth nothing on every board it appears on, and the same entry serves a corner of a 4 × 5 board and the middle of a 7 × 7 one. That is the practical content of the theorem for a program — the work moves from boards, of which there are as many as anyone cares to name, to shapes, of which play on any one board makes a few thousand.

The catalogue is a normal-play luxury

Everything above rests on one sentence of the theorem: the value of a sum is the exclusive-or of the values of its parts. That sentence is true under normal play, where the player who cannot move loses, and false under the other convention.

Cram with the last move losing is the same game with the loss and the win exchanged at the end, and there the pieces do not add. A misère position is not a Nim heap, a piece’s value is not enough to say what it does beside another piece, and the board has to be searched as a board — or the pieces have to be described by something richer than a number, which is what a misère quotient is. The wild positions that essay found on boards of ten free squares are exactly the pieces such a description would have to carry.

So the compression measured here — twenty-five positions to a shape on 4 × 5, sixty-eight on 5 × 5 — is not a fact about Cram’s board. It is a fact about Cram’s ending. The same 2,304 shapes arise under either convention, because which squares are covered does not depend on who will lose at the end; what changes is whether knowing a shape’s value is enough to use it. Under normal play it is, and the catalogue is the whole solver. Under misère play it is not, and the catalogue is only a list of what has to be described.

What the counts depend on

The board is cut into pieces by edges, not corners. Two free squares are in the same piece only if they share a side, since a domino covers two squares that share a side and nothing else. A piece is therefore an edge-connected set, and its holes, if it has any, are part of its shape.

Shapes are counted up to all eight symmetries of the square, except in the column that deliberately counts them up to four. A count up to translation alone would be larger by a factor approaching eight and would describe the storage rather than the game.

Positions are reachable positions: every set of covered squares that some sequence of legal dominoes produces from the empty board, regardless of whose turn it is. Cram is impartial, so the player to move does not change a position’s value, and a position is a set of covered squares and nothing more.

What the census cannot show

The boards are small. The largest board here has twenty squares and the polyomino census stops at eleven. The value ceiling of ∗4 is a fact about eleven squares, and the 4 × 5 board already has pieces worth ∗7. How fast the largest value grows with size, and whether the share of zero pieces stays near two fifths on larger boards, is not measured.

Reachability is not likelihood. The coverage counts which shapes can occur, not how often a player meets them. A shape that occurs on one position in fifty thousand counts the same as the lone square. The frequency figure weights by occurrence across all reachable positions, which treats every position as equally likely, and no player’s games do that.

And the gaps are not explained. No seven-square region is worth ∗2, and the plus-sign pentomino is the only one worth ∗1. Both are measured, and no argument here says why.

Still open: whether a short list of shapes answers most of play

The catalogue on 4 × 5 has 2,304 entries and a solver keyed on shapes needs them all to be exact. But most pieces are a handful of shapes — the lone square and the two-square slot alone are 55% of all the pieces that occur — and a zero piece can be dropped without looking it up.

So the measurement worth making is the Domineering one, made for Cram: order the shapes by how often they occur, and ask how many entries answer half the pieces, and nine tenths. If the answer is a dozen and a few hundred, Cram’s catalogue concentrates like Domineering’s; if it is smaller, the impartial game concentrates harder, which is what three-bit values and a quarter-turn symmetry would predict. And the board that would make the question worth asking is 5 × 5, where the 16,457 shapes are seven times as many as on 4 × 5 and the positions are nineteen times as many — the size at which a solver that stores shapes rather than positions first matters for time rather than for elegance.

Part 3 of 4

One argument about Cram. The parts either side of it:

The objects named here

The third axis, after the field and the series: the games, values and theorems themselves, and every essay that touches each one.

ComponentCramDecompositionDomineeringExhaustive searchGrundy valueImpartialNim-sumSprague–GrundySymmetry