April 2024
Beginner to intermediate
500 pages
24h 20m
English
Next, we will teach the computer to play Nim. The game of Nim begins with a pile of stones. Two players take turns nimming (stealing) 1, 2, or 3 stones from the pile. The player who steals the last stone wins the game. You can play this game with stones, coins, or any tokens you choose. We will play Nim with digital stones.
In this section, we will have the computer be both players so that the computer is essentially playing itself. But the computer will have two different strategies for making a play. Our first strategy will be to choose a random number of stones to remove. To do this, we need to explore how to generate a random number.
To generate a random play, we will use the random module. This ...
Read now
Unlock full access