Home Resume Projects Photos Songs Ninja Fencing

The Game of NIM

The game of NIM is a two-player game usually played with matchsticks. They are aligned into any number of stacks, with any number of matches in each stack. During each player's turn, he or she removes matchsticks from one stack only. He or she may choose as few as one, or as many as the entire stack. The goal of each player is to take the last matchstick.

The point of this project was to learn how to use an FPGA chip by automating the game with an interface and artificial intelligence acting as the other player. This implemenation of the game consisted of three stacks of seven matchsticks, represented by LEDS, a button for each stack, and "done" and "reset" buttons. The human player presses the button on one stack once for each matchstick he or she wishes to remove, then presses "done." The computer then calculates the best move, changes the interface to reflect that move, then allows the human player another chance to move.

The reason this game was selected as the project to learn FPGA programming was that the game has a fairly straight-forward winning computation. By using seven matchsticks/LEDS, each can be represented with three bits. The AI calculates the parity of the bits in each stack and makes a decision to keep the game in a winning position for itself. For more details, read the Technical Report (which includes a memory block diagram) submitted at the end of the project.

Peter Susi and I worked as partners to develop this project.

Comments? Questions? Send me email!