What should be the strategy for this nim game

game theory

I am facing with a problem. I don't think it is a nim game but in some points, it it the same.

There is a heap of n sticks. Two players play this game. Each players can remove 1, 2, 3, 4 or 5 sticks and not remove the same number of sticks as previous player.

The player who can not make a legal move is loser.

Given n = 22, is there a strategy for the first player always win?

What really makes me confused is the number of moves you can make is depend on the previous move.

Best Answer

It is a nim game, but the state of the game consists of not just the number of sticks remaining, but also the last move done. Each of these pairs (sticks, last move) can be given a Sprague-Grundy number just as in any other Nim-type game.

However, in this case it is easier to just build a table listing all the winning moves for each number of sticks.

$$ \begin{array}{c|l} \text{Sticks} & \text{Winning Moves} \\ \hline 0 & - \\ 1 & 1\\ 2 & 1,2\\ 3 & 3\\ 4 & 4\\ 5 & 5\\ 6 & 3\\ 7 & -\\ 8 & 1,4\\ 9 & 2,3\\ 10 & 3,5 \\ ...& ... \end{array} $$

On each new line, simply list all the moves that (if available) would lead to a position with no winning moves available. For example, for 6 sticks 3 is a winning move cause it leads to a state where the only possible winning move (3) is no longer available.

I don't see any repeating pattern yet, even when extended up to 22.