The NIM game is a game in which two players play against each other. It is excellent to clarify machine learning according to the principle of reinforcement learning.
Game construction
There are 10 game pieces in a row.

Game sequence
The players take turns taking away one, two or three pieces in turn. The player who takes the last piece from the field has lost the game.
Try it out until you find a strategy!
Ablauf für einen KI-Spieler
Now a player is playing against a computer player. Here's how you can build and run the game:
Game construction
Place a mug with three coins representing the values 1, 2 and 3 behind the first nine pieces of play. You will quickly find that some coins are not needed for this game, so you can put them aside.

Game sequence
When it is the computer player's turn, randomly draw a coin from the cup behind the next piece that can be taken and place it in front of the cup (between the cup and the piece).

Now take the number of figures from the row that indicates the value of the coin. Pay attention: If there are not enough figures in the row to reach the value of the coin, this coin should not have been in the cup at all.
If the AI player loses, remove the coin that led to defeat from the game - unless it is the last coin in the cup. In this case, take the previous coin from the cup (unless it is also the last coin).
Put the remaining coins back in the cup and start the game again.

You can find the print files (.stl) for cups, coins and game pieces (in addition to a more detailed game instructions) at cults3d or makerworld.
Reinforce learning using the example of the NIM game
Reinforcement learning (or reinforcement learning) is a learning approach in which an agent (in this case the cups with the coins) learns to make optimal decisions through interactions with an environment. The agent receives rewards or punishments based on his actions.
Here the agent is punished by not putting the coins back in the cups in case of defeat. In the event of a victory, nothing happens, i.e. the coins that led to the victory are put back in the cup. That's the reward.

Leave a Reply