Marienbad

Strategy game based on the mathematical game of Nim.

Marienbad is a beautiful, strategic cat-stacking game based on misère Nim — the version where the last move loses. It's easy to learn but deeply rewarding once you understand the hidden math.

The Game Rules

The board always starts with four columns of cats

1  ·  3  ·  5  ·  7

Players take turns

On your turn you must remove one or more cats from a single column only. Cats are always taken from the top down of that column.

Crucial rule: the player who is forced to take the very last cat on the entire board loses. Your goal is to leave exactly one cat for your opponent.

How to move

Press and hold any cat, then swipe up or sideways. Everything from the cat you touched upward will fly off the screen. The computer always plays perfectly, using the optimal Nim strategy with the special misère adjustment for the endgame.

History

Origins

Nim is a classic impartial combinatorial game in which two players alternate removing objects from distinct heaps. Its conceptual origins lie in ancient practices of manipulating counters, though direct evidence for the precise multi-heap form is limited.

In prehistoric times, early humans likely engaged in rudimentary strategic activities using stones, seeds, or bones arranged in piles — for recreation, divination, or decision-making. These represent conceptual precursors to the broader family of pebble-distribution games that later evolved across cultures.

Ancient China

The game is traditionally linked to ancient China, where variants of stone-removal games — sometimes called jiǎn-shízǐ ("picking stones") — are believed to have circulated for many centuries, possibly predating written records.

European Renaissance

European references to Nim-like games appear in the early 16th century. A notable example is found in De Viribus Quantitatis (c. 1508) by Luca Pacioli, which describes a simplified single-pile variant involving removal of numbers up to a fixed limit to reach a target. Similar recreations circulated widely in Renaissance mathematical literature.

Modern Times

The multi-heap version received formal mathematical recognition in 1901, when Harvard mathematician Charles Leonard Bouton published "Nim, A Game with a Complete Mathematical Theory." Bouton introduced the Nim-sum — the bitwise XOR of heap sizes — as the key to determining winning and losing positions, and is credited with naming the game, possibly from the German imperative nimm ("take").

The 20th century brought early computing demonstrations, including the Nimatron (1940), an electromechanical device capable of playing perfect Nim, followed by digital implementations.

Marienbad

In 1961, the game gained wider cultural prominence through its appearance in Alain Resnais's avant-garde film L'Année dernière à Marienbad (Last Year at Marienbad). Characters repeatedly play a matchstick variant of Nim — one consistently defeating the other through superior strategy — introducing the game to a much larger audience.