Nim is an ancient game of pickup sticks. The rules are simple. The sticks are arranged in piles. You can pick up as many pieces from any one pile you want and picking up the last piece determines the winner. The number of piles, the number in each pile, and whether the last piece is the winning piece or the loosing piece are all variations you can make to the game. The traditional setup is 3 piles of 3, 5 and 7 and the last piece is the loser, a ending condition known as misère.
Nim is a solved game, which is to say there has been discovered a mathematical formula that when followed guarantees the outcome within the first move or two. If one player knows how to play nim mathematically they are almost guaranteed a win against anyone who doesn’t know how to play nim, which makes playing against the computer not as much fun. On the other hand if you can learn how to play Nim mathematically…
This program, instead of merely playing a perfect game of Nim teaches you how to play a perfect game of Nim by showing you it’s mind set. The first thing you need to know about playing a perfect game of nim is the relationship between decimal numbers (like you’re used to counting in) and binary numbers. Once you know that you can use the binary representation of the number of sticks in each pile to develop a “nimber”. That nimber can then be used to plot your next move. Always try to leave your opponent with a nimber of zero until the end and you’ll be assured the win.
The one shortcoming with this trainer is if you miss it proceeds to school you through hard knocks. It would be better if it intentionally threw the game, but at the end of each round gave you a report card based on the number of rounds you gave it a nimber of zero, and offered other training modes that didn’t help you quite so much so that you can practice in a more “real” situation, without the hints. So that’s your homework. Rewrite this program to make it a better trainer.
Nim Trainer was written by Joe Larson

Download and Play
Download the source code
December 20th, 2009 - 9:28 am
quite fun and challenging :)