CS 204: Software Design

Due 8:30AM Monday, 1 February 2010
You may work with a partner for this assignment and its follow-up.

Mancala

The family of board games known as Mancala has many rule variants from around the world. We're going to use Mancala to help us think about Test-Driven Development. For our purposes, we'll assume Mancala is played with these rules, using a layout and bin-numbering scheme like this:

PLAYER 2 SITS HERE x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x12 x x11 x x10 x x 9 x x 8 x x 7 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x13 x x 6 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0 x x 1 x x 2 x x 3 x x 4 x x 5 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x PLAYER 1 SITS HERE

In class on January 29, we imagined that we were going to develop the game logic (not the user interface) for a Mancala game, and we discussed possible methods for a MancalaBoard class. We'll wrap up that discussion Monday, but we know for sure that the methods will include:

class MancalaBoard: def __init__(self): '''Bins 0-5 are Player 1's bins, bin 6 is Player 1's store (i.e. the big bin), bins 7-12 are Player 2's bins, and bin 13 is Player 2's store.''' self.bins = [3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 0] self.isFirstPlayerTurn = True def move(self, binIndex): '''If the move starting in the specified bin index is legal, this method adjusts the game state accordingly. Otherwise, it raises an Exception.''' pass def isMoveLegal(self, binIndex): '''Returns True if a move starting at the specified binIndex is legal, and False otherwise.''' pass

Test cases

The goal of the current assignment will be to generate a collection of test cases to explore the behavior of the as-yet-unwritten MancalaBoard class. To enable us to automate the testing process, we need a file format in which to store test cases. Here, by fiat of the professor, it is.

Each test case will take up a single line in a text file. (Here, "line" means all the text between consecutive newline characters. Word-wrap and window size in this or that text editor is irrelevant to this definition of line.) The line will start with a comma-delimited sequence of bin indices, each one representing a single move. After the final move, the line will contain a semi-colon, followed by the fourteen integers representing the expected contents of bins 0-13 after the sequence of moves is complete, assuming the sequence of moves is legal. If any of the proposed moves is illegal (including a move after the game is over), then the semi-colon will be followed by one of the following error codes:

The error code shown should be the one that applies to the first illegal move found in the list of moves. If more than one error code applies to the first illegal move, then whichever applicable error code appears earlier in the list above should be used.

Finally, each test case will include a second semi-colon followed by a (possibly empty) comment briefly describing the test case's purpose.

For example, this test case represents a single move by Player 1, distributing the stones from Bin #1 into Bins 2, 3, and 4:

1;3,0,4,4,4,3,0,3,3,3,3,3,3,0;One simple move.

Because this one-move sequence is legal assuming the board begins with 3 stones in each of the non-store bins, the integers following the semi-colon represent the contents of the 14 bins after the move.

Here are a few more possible test cases:

5;3,3,3,3,3,0,1,4,4,3,3,3,3,0;A move that crosses through a store. 1,12;4,1,4,4,4,3,0,3,3,3,3,3,0,1;A pair of simple moves. 1,1,2;WrongPlayer;Playing out of turn. 1,8,1,12;AttemptToMoveFromEmptyBin; 1,8,2,14,3;BinIndexOutOfRange;A bin index larger than 13. 1,8,-3,14,3;BinIndexOutOfRange;A negative bin index.

Your task

By class time on Monday, please deliver to me via e-mail 20 test cases in the format described above.

After I have collected all the test cases and we have had more discussion on Monday in class, I will ask you to implement enough of the MancalaBoard class to enable you to run the test cases. On Friday, we will meet in the lab and try all of the test cases generated by the class (and perhaps a few by me) to see if we can find bugs in your program.

With this plan in mind, try to create test cases that probe the boundaries of the problem. You are trying to trip up your own program as well as the programs of the other students with the goal of making everybody's program as robust as possible.