YCP Logo Assignment 1: The Game of Nim

ECE 470 - Assignment 1

Due: Monday, September 8th, by 11:59 PM

In this assignment, you will write a program to allow two players to play a game of Nim.

A game of Nim consists of one or more heaps of stones (or other objects). Players take turns taking 1 or more objects from one of the heaps. The last player to take a stone loses. So, the object of the game is to force the other player to take the last stone.

Example Session

Here is an example session (user input in bold):

How many heaps? 3
Size of heap 1? 3
Size of heap 2? 4
Size of heap 3? 5

Player 1's turn
Heaps: 1:3 2:4 3:5
Pick from which heap? 3
How many? 5

Player 2's turn
Heaps: 1:3 2:4 3:0
Pick from which heap? 2
How many? 4

Player 1's turn
Heaps: 1:3 2:0 3:0
Pick from which heap? 1
How many? 1

Player 2's turn
Heaps: 1:2 2:0 3:0
Pick from which heap? 1
How many? 1

Player 1's turn
Heaps: 1:1 2:0 3:0
Pick from which heap? 1
How many? 1
Player 2 wins

Getting started

Download CS201_Assign1.zip. Import it into your Eclipse workspace (File->Import...->General->Existing projects into workspace->Archive File). You will see a project called (surprise) CS201_Assign1 in the Package Explorer. The package edu.ycp.cs201.nim contains a file Nim.java which contains the main method of the program.

Requirements

At a minimum, your program should allow the game to be played with 1 to 3 heaps. (Supporting any number of heaps is good: see Grading section below.)

Use the example session above as a model for what the program's prompts and output should look like.

Grading

Your grade will be determined as follows:

  • If your program works correctly when given valid user input, it will receive a grade of up to 80.
  • If your program works correctly, and checks to ensure that user input is valid (prompting the user to re-enter the value when an invalid input is received), it will receive a grade of up to 90.

I expect you to use good coding style (identation, naming of identifiers, etc.) I will deduct points for programs that use poor style.

The following extra credit features may be implemented:

  • The game may be played with any number of heaps. (up to +5 points)
  • A "graphical" representation of the heaps is drawn using text characters. (up to +5 points)
  • Use classes and objects to represent the game, heaps, players, etc. (up to +10 points)
  • A GUI is supported. (up to +10 points)
  • The game may be played against a computer opponent. See the Wikipedia article for a discussion of an optimal strategy for playing the game. (up to +10 points)

Do not copy any code from other students, web sites, etc. The program you submit must be your work alone. Failure to follow the Academic Integrity policy specified in the syllabus will be treated as Academic Dishonesty, and could have severe consequences.

Submitting your work

Export your finished program to a zip file (right-click on the project, then Export...->Archive File). Upload the zip file to the marmoset server as project assign1. The server URL is

https://camel.ycp.edu:8443/

IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.