NIM with Reinforcement Learning

See how an AI system learns to play NIM from scratch – just by playing against itself.

1
Train the AI – Choose how many games the AI should practise. Watch how the Q-table changes during training!
2
Explore the Q-table – The table on the right shows what the AI has learned. Green = good move, red = bad. Can you spot a pattern?
3
Play against the AI – Challenge a half-trained or fully trained AI. Can you beat it?
Goal: Avoid taking the last stick – whoever does loses.

How to play:
Players take turns. On your turn choose to take 1, 2 or 3 sticks (you must take at least 1).

Example with 9 sticks:
You take 2 β†’ 7 left
AI takes 3 β†’ 4 left
You take 3 β†’ 1 left
AI forced to take last β†’ AI loses!
← AI Activities

NIM

See how an AI system learns to play NIM using reinforcement learning – then try playing against it!

πŸ‡ΈπŸ‡ͺ Svenska
Settings
Imagine learning a game just by playing it over and over and noticing what worked. That is exactly what the AI does.

For every situation in the game it learns a Q-value – a score for how good a particular move tends to be. If a move leads to a win the score goes up; if it leads to a loss the score goes down. At first the AI tries moves almost at random – it explores. The more it trains, the more it begins to exploit what it has learned, choosing the moves with the highest scores. The table on the right shows the score for each move in each situation.
Q-table – the AI's brain
Each row = number of sticks remaining. Each column = move. Green = good move, red = bad. Gold border = best move in that state.
Good move
Bad move
Best move
Train the AI to see the Q-table fill in.