June 14, 1994; Jerry Nowlin
This file is in the public domain.
The game of nim focuses on a pile of 15 sticks. Each player can
select 1, 2, or 3 sticks from the sticks remaining in the pile when
it's their turn. The player to pick up the last stick(s) wins. The
loser of the previous game always gets to go first.
There are two versions of nim in here. The first (default) version
uses an algorithm to make its moves. It will never lose if it gets
the first turn. The second version tries to learn from each game.
You'll have to play a few games before it will get very smart but
after a while it will also never lose if it gets the first turn. This
is assuming of course that you know how to play. Since the learning
version learns from the person it plays against, if you're lousy the
game will be too.
To invoke the learning version just pass any argument to the program.
If you want to see how the program learns, you can use the string
"show" as the argument and the program's current game memory will be
displayed after each game. If you invoke the game with the string save
as an argument a file called ".nimdump" will be created in the current
directory with a dump of the program's game memory when you quit and
the next time the game is played in learn mode it will initialize its
game memory from the dump. You can invoke this program with more than
one argument so show and save can be used at the same time.
Source code |
Program Library Page |
Icon Home Page