Ancient Game of Nim


Nim in progress Since this was not a known computer game, I started from scratch this time. I have since discovered a few versions of Nim that can be played on line so there probably is source code out there some place. No matter, Nim is a simple game with simple rules, although there are variants. Essentially there are multiple stacks or rows of markers, depending on what is used for the markers. Players take turns removing at least one, or as many as desired, markers from a single row or stack. The player to take the last marker loses. One variant is the player taking the last marker wins. The level of difficulty is the same for either variant.

Since I finally devised a scheme to win before Lt. Gmric (yes that is the correct spelling) took all my money and since I found no (actually didn't search for) existing source code, I wrote this as a graphical game from scratch in Java. I added a number of options. You can play it either with stacks or rows. You can specify the maximum of stacks or rows. You can specify the maximum number of markers for a stack or row. You can specify whether the player who takes the last marker wins or loses. Try it both ways some time as there is a definite strategy change required. Finally, you can play against the computer or another opponent. This is a screenshot of a game in play where the player has selected markers to remove but has not yet clicked the Remove button.