CSCI 431 Homework 7

time due submission file
3 days after I return homeworks 4, 5, & 6 csci/431/HW7/OddWins.pm

The game

In the first grade at Isaac Dickson Elementary School, child play a game called "Odd Wins" to learn a little about the concept of odd and even numbers. In the game, children take turns picking up counters. The game begins with fifteen counters. On each turn you can pick up one to three counters (but no more than remain on the board). The winner is the child who ends the game with an odd number of tokens.

The assignment

Your task is to write a Perl module that plays a generalized version of the game. Your module should implement the following five methods:

  1. new(): Creates a new object with an initial counter number of 15 and where at most 3 counters can be removed on each turn.
  2. new(B): Creates a new object with an initial counter number of B and where at most 3 counters can be removed on each turn.
  3. new(B, M): Creates a new object with an initial counter number of B and where at most M counters can be removed on each turn.
  4. opponentTakes(N): Called to inform your object that the opponent has taken N counters. Return 1, if this seems legitimate; and return 0, otherwise. If your oppenent takes 5 tokens or doesn't allow you a turn, that would not be legitimate.
  5. myTakes(): Called on your "turn" to obtain the number of counters you wish to take. Again return 0, if this call doesn't seem appropriate.

Turning in

Copy OddWins.pm to the assignment drop-off directory.

You can perform some limited "sanity" tests for your module by running it against my my simple Perl test script. You could also test your module by allowing it to play against those written by other students. You can use my Perl script for dueling modules for this purpose.