-


> > > > Programming Assignments > Assignment 7 - Chomp

Objectives

Introduction

Chomp is a game played by two players on an r-by-c grid. The players alternate claiming one of the remaining locations on the grid; that location and all locations above and to the right are removed from play. The last player to make a move (taking the bottom-left location) loses. (Note that the Wikipedia article describes the game upside-down.)

Assignment

Write a program called Chomp that takes a single argument that is a non-empty string of nonincreasing digits starting with a non-zero digit representing the state of a game of Chomp. The output should be a single line containing "LOSS" if there is no winning move from that state and "WIN" along with the state resulting from making the winning move if there is a winning move. The output should be in the format given in the example below. If there is more than one winning move then the output should reflect the one that selects the leftmost piece among all the winning moves.

Your program must be efficient in terms of time and memory, where "efficient" is defined as "passes the large public test cases without execeeding the time or memory limits".

If the input file or command-line arguments are not as specified then your program must behave gracefully: it must not crash or go into an infinite loop.

Your program and any program must not produce any error messages when run with valgrind --tool=memcheck --leak-check=yes -q.

We reserve the right to deduct points from submissions for violations of the following guidelines.

Example

[jrg94@tick Chomp]$ ./Chomp 33333
WIN: 33322
[jrg94@tick Chomp]$ ./Chomp 33322
LOSS
[jrg94@tick Chomp]$ ./Chomp 33321
WIN: 22221

Files and Submissions

A suggested partial implementation is available in /home/httpd/html/zoo/classes/cs223/f2017/Assignments/Chomp. You may make any changes to this code as you see fit.
Valid HTML 4.01 Transitional