Course Project Guidelines

(Last Mod: 27 November 2010 21:38:40 )

ECE-1021 Home


Your final project in this course is to write a function that, given a pointer to an array that represents the current state of the board in a game of Mancala, returns the number of the pit from which you want your seeds sown.

For the above problem statement to make sense, you of course need to know what the game of Mancala is and how it is played. There are many resources available on the Internet devoted to Mancala - and there are many variants of the game. We will be using the most common version of the game and the specific rules we will follow will be posted later in the semester.

The Rules of Mancala

There are many variations of Mancala, but the basic set of rules is pretty much agreed to be consistent with those found at the following website:

http://www.cmi.k12.il.us/Urbana/projects/AncientCiv/africa/Mancala.html

  Player B's Bins  
1 2 3 4 5 6
 

Player B

HOME

 

             

Player A

 HOME

 

           
  6 5 4 3 2 1  
Player A's Bins

Board Layout

There are a total of fourteen bins on the board. Twelve are located in two rows of six and the other two are located on opposite ends of the two rows. The bins are the shaded boxes in the figure above.

Each player controls the six bins of their side of the board. The large bin located on the right end of the board (as they see it) is their Home Bin (traditionally called a "kalaha").

There are a total of fourty-eight playing pieces (traditionally calls "seeds" or "stones"). Initially, each of the twelve bins have four seeds each and the two kalahas are left empty.

Object of the Game

The object of the game is to have the most seeds in your kalaha when the game is over.

Playing the Game

One of the players is randomly chosen to go first.

A player makes a move by "sowing" the seeds from one of the six bins on their side of the board. To sow the seeds from a particular bin, all of the seeds are removed from the selected bin and then distributed one at a time to the other bins in a counterclockwise fashion as long as the seeds last. Seeds are sown into that player's kalaha but not into the opponents kalaha (it is skipped over). Unless one of the two rules below applies, the player's turn ends as soon as the last seed is sown.

If the last seed sown is placed in the player's kalaha, then that player gets to go again. There is no limit on how many consecutive times this rule may be invoked.

A player may capture seeds from their opponent if the last seed sown is placed into an empty bin on their  side of the board. If this happens, then that seed, along with any seeds that are located in the opponent's bin directly across the board, are placed in the player's kalaha. This ends the player's turn.

A player must make a move when it is their turn - "passing" is not an option.

How the Game Ends

The game ends as soon as either player has no seeds in any of the six bins on their side of the board. The other player then collects all of the seeds left in the bins on their side of the board and puts then in their kalaha. Each player counts their seeds and the player with the most seeds wins.


Your Function

You are to write a function that, when invoked, returns the number of the bin you wish to sow.

The prototype for your function will be as follows:

int Move_aaaa(MANCALA board, int player);

where aaaa is replaced with the four letter student identifier (the same one used in homework file names).

The function will return an integer between 1 and 6 inclusive that represents the number of the bin on your side that is to be sown.

Notice that the Mancala Engine will pass a structure to your function, not a pointer to a structure. The reason is that the desire is to pass the game board to your program by value and hence protect the Engine's master game board from your manipulations. This means that you are free to alter the data in this structure as you see fit since you are working with a local copy of it.

The pointer that is passed to your function will point to a fourteen element array used

struct MANCALA

{

    char board[2][7];

};

 

typedef struct MANCALA MANCALA;

There are two players - player 0 and player 1. Which player you are is provided to you in the second parameter to the function.

The data in the array is defined as follows:

board[player][0] - player's kalaha

board[player][n] - player's bin n (1 <= n <= 6) with bin 1 being closest to the kalaha

Your function is ONLY to decide which bin to sow. It is not to print anything out. You may dynamically allocated memory if necessary but your are expected to perform garbage collection prior to returning. 

If your function performs an illegal operation, hangs, prints anything out, writes to memory that doesn't belong to your function, or returns an illegal move then you will forfeit the current game. If your function performs an action (such as hanging or crashing the tournament engine) that requires instructor intervention then you will be disqualified from further participation in the tournament.

The tournament engine will be made available to you so that you may test your functions prior to the tournament.