time due | submission file |
---|---|
3 days after I return homeworks 4, 5, & 6 | csci/431/HW7/OddWins.pm |
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.
Your task is to write a Perl module that plays a generalized version of the game. Your module should implement the following five methods:
new()
: Creates a new object with an initial
counter number of 15 and where at most 3 counters can be
removed on each turn.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.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.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.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.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.