Nim: A Simple Two-Player Game

PSU CS 410/510 Games Homework 3
Due before class Thursday May 2, 2002

The game of Nim is a venerable one. The variant we will play, Simple Nim, is especially easy to search. The initial state consists of three piles of stones: a pile containing one stone, a three-stone pile, and a five-stone pile. A player's turn consists of taking one or more stones from any single pile. For example, the first player could begin by taking the whole of the five-stone pile, or by taking two stones from the three-stone pile, etc. The player taking the last stone wins.

It is easy to see that this game is alternating, terminating, zero-sum, deterministic, and contains no hidden information. Its state space is small, and thus it is a reasonable candidate for valuing using minimax search.

Write a program that uses minimax search to give the value of Simple Nim: i.e., is it a first-player win or a second-player win? (It is obviously not a draw.) The program should also output a winning line: a sample game showing best play by the winning player.

(Almost all variants of Nim, including this one, are solved. Obvious question: If you know the answer, do you still have to write the minimax search program? Obvious answer: yes.)


Homework should be submitted by e-mail to <cs510games@cs.pdx.edu>. The words "cs510games hw3" should appear somewhere in the subject line. The homework submission should be a MIME message containing your source code, a writeup in ASCII answering all questions posed by the assignment, and the results of program runs. Please follow all accepted coding and software engineering practices for your programming language. Remember, if I can't understand your submission, I can't give you credit for it.

I'd like you to do this assignment by yourself. If you do work with anyone else, you must credit them in your submission.