Share your repls and programming experiences

← Back to all posts
Nim Machine Learning
LigerBotsCSO (1)



Machine Learning, Teaching an idiot computer to play Nim.

How do you play Nim? Good question.

There's a pile of berries. You may select either 1, 2, or 3 berries. The computer moves next, in alternating turns. You may only make these moves.
The goal of the game is to be the last player to take berries, setting the number of berries to zero.

Here's a better definition:
The players take turns removing blocks — each player may remove any number of blocks (at least one) from any one pile, and it is fine to take a whole pile — whichever player takes the last block wins.

Okay so how to run the code and not break anything. Good question.
Click the run button.
After every game, a png will show up, which shows how much the computer is "learning"
Two files will be generated to keep the learning consistent.

Click play, and be patient until the computer prompts you. It gets a little confused sometimes.