games we play

Nim, Hackenbush, and friends

STEM Mentorship Program for High School Girls

Neeldhara Misra

Indian Institute of Technology, Gandhinagar 

14 May 2024

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The Game of Nim

The last player to make a move wins.

The Game of Nim

has perfect information,

(nothing is hidden from either player, unlike, e.g, a lot of card games)

is impartial,

(both players have the same moves available)

& is played according to the normal play convention.

(the last player to make a move wins, as opposed to misére play,
where the last player to make a move loses)

deterministic,

(no randomization by way of shuffles, coin tosses, die rolls, etc.)

...a turn based two-player game,

The Game of Nim

has perfect information,

(nothing is hidden from either player, unlike, e.g, a lot of card games)

is impartial,

(both players have the same moves available)

& is played according to the normal play convention.

(note: there are no draws)

deterministic,

(no randomization by way of shuffles, coin tosses, die rolls, etc.)

...a turn based two-player game,

The Game of Nim

We often want to know...

WHO WINS?

The Game of Nim

A player might win because she played well 🎉

A player might also win because the other player played badly 👀

We will mostly focus on forced wins.

We want to know if a player can win...
no matter how the other player plays.

A winning strategy is a formula for
playing-to-win.

The Game of Nim

Strategy

Game Position

move

The Game of Nim

Strategy

Game Position

move

Can both players have a winning strategy?

The Game of Nim

Strategy

Game Position

move

Will at least one player have a winning strategy?

The Game of Nim

Strategy

Game Position

move

Let us work through some examples!

The Game of Nim

The Game of Nim

The Game of Nim

The first player wins by eliminating the whole heap.

The Game of Nim

What if there are two equal heaps?

The Game of Nim

What if there are two equal heaps?

The Game of Nim

What if there are two equal heaps?

The Game of Nim

What if there are two equal heaps?

The Game of Nim

What if there are two equal heaps?

...back to square one.

The Game of Nim

What if there are two equal heaps?

as soon as the first player empties out a heap,

the second player empties out the other one.

The Game of Nim

The second player can force a win.

as soon as the first player empties out a heap,

the second player empties out the other one.

The Game of Nim

The second player can force a win.

(a = b)

This is true of the the losing position.

a

b

Making any move on a board that has the property destroys it.

If the property does not hold, there exists a move that restores it.

The Game of Nim

(a = b)

This is true of the the losing position.

Making any move on a board that has the property destroys it.

If the property does not hold, there exists a move that restores it.

all two-heap

NIM games

with equal-sized

heaps

all two-heap

NIM games

with unequal

heaps

Making any move on a board that has the property destroys it.

\(\forall\)

\(\exists\)

The Game of Nim

If the starting position has the property, player 2 wins.

(a = b)

This is true of the the losing position.

a

b

Making any move on a board that has the property destroys it.

If the property does not hold, there exists a move that restores it.

The Game of Nim

If the starting position does not have the property, player 1 wins.

(a = b)

This is true of the the losing position.

a

b

Making any move on a board that has the property destroys it.

If the property does not hold, there exists a move that restores it.

The Game of Nim

Who wins this Nim game?

a

b

The Game of Nim

Who wins this Nim game?

a

b

The Game of Nim

This game belongs to Player 1.

a

b

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Player 2... when \(N\) is even.

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Player 2... when \(N\) is even.

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Player 1... when \(N\) is odd.

Upgrade: \(N\) heaps!

Assume every heap has just one token.

The only choice a player has
is to figure out which heap to take from.

But this is not much of a choice either,
since all heaps are basically identical.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

If \(N\) is even, the second player can win by grouping and mirroring.

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

If \(N\) is odd, the first player can win by reducing to the even case.

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

If \(N\) is odd, the first player can win by reducing to the even case.

Upgrade: \(N\) heaps!

Assume every heap has two tokens.

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) and \(b\) are both even?

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) and \(b\) are both even?

Player 2 wins (by mirroring and grouping again).

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is odd and \(b\) is even?

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is odd and \(b\) is even?

Player 1 wins (by removing one heap with two tokens).

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is even and \(b\) is odd?

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is even and \(b\) is odd?

Player 1 wins (by removing one heap with one token).

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is odd and \(b\) is odd?

The Game of Nim

Who wins?

Upgrade: \(N\) heaps!

Assume every heap has one or two tokens.

\(a\) heaps with two tokens each

\(b\) heaps with one token each

What if \(a\) is odd and \(b\) is odd?