Create the game: Mancala Setup Players sit on either side of the board. Each player has six
Question:
Create the game: Mancala
Setup
Players sit on either side of the board. Each player has six bowlsand one mancala. Before play begins, four stones are placed intoeach bowl, while both mancalas are left empty. The object of thegame is for a player to collect the most stones in his/hermancala.
Rules
Play begins by randomly choosing a player to move first. The firstplayer picks up all of the stones in one of his/her bowls. Theplayer then drops one stone into the bowl to the left or the rightof the current bowl and continues to move to each bowlsequentially, dropping a stone into each, until no more stonesremain in hand. Once a direction (clockwise or counter-clockwise)is chosen, the player must continue moving in that direction forthe duration of the turn. If a player passes by his/her ownmancala, a stone is dropped into it. The opponent's mancala,however, is simply ignored. (A player never drops a stone into theopponent's mancala.) If stones still remain in the player's handafter reaching a mancala, players continue moving around to theopposite side of the board (in a circular fashion).
For example, suppose the Blue player were chosen to move first. IfBlue opted to start at bowl 4 and to travel counter-clockwise, theboard would look like this at the end of Blue's turn:
If the last stone a player drops during a turn lands in his/her ownmancala, then the player immediately takes another turn. On theother hand, if a player drops the last stone into one of his/herempty bowls (on the correct side of the board), then that laststone, plus all the stones in the opponent's corresponding bowl,are collected and placed in the player's mancala. This is called acapture. For example, if the Red player begins a turn with thefollowing board:
and decides to move counter-clockwise, starting from bowl 1, thenthe last stone will land in bowl 5 (which is empty). Therefore, allof the stones from the Blue player's bowl 0 and the Red player'sbowl 5 will be added to the Red player's mancala.
(The Red player will now have seven stones in his mancala.) Playerscontinue alternating turns until one player no longer has any morestones in his bowls. At this point, the round ends. The otherplayer gathers all of the remaining stones in his bowls and addsthem to his mancala. The players then compare the total number ofstones in their respective mancalas, and the player with the mostwins the round.
- (Slightly modified rules based on those given here)
Implementation
For this assignment, you will need to use the following arraydefinition to represent the mancala game board.
int MancalaBoard[2][NUMBOWLS+1]; // Each row is one player's sideof the
// board. Indices [0,NUMBOWLS-1] represent
// a player's bowls. NUMBOWLS represents
// a player's mancala.
You may also find it useful to use a struct to represent the fullstate of the game, including the color of the current player, thestate of the board, etc., to make it easier to pass thisinformation to various functions.
For example =>
struct mancala
{
int MancalaBoard[2][NUMBOWLS+1];
char currentPlayer;
int currentBowlNumber;
int currentDirection;
};
Using a struct definition, however, is purely optional ... thegeneral program organization is left up to you.
You should define constants to represent the number of stones eachbowl begins with and the number of bowls for each player (notcounting the mancalas). This will allow you to easily change theway the board is designed simply by recompiling with newconstants.
Organize your code so that it is modular in design. This shouldinclude designing functions like the following (parameters are notincluded, and suggested preconditions are somewhat vague, sincethey will depend on your specific impelementation):
char checkForWin();
// pre: valid data is passed in representing the state of thegame.
// post: Returns 'R' if the Red player has won
// Returns 'B' if the Blue player has won
// Returns 'N' if neither player has won
int move();
// pre: valid data is passed in representing the mancalaboard,
// the current player and and the starting bowl the current
// player will move from (specified by an int between[0,NUMBOWLS-1]).
// direction = -1 (for clockwise) or 1 (for counterclockwise)
// post: The human player's move is executed, and the currentplayer is
// updated/switched. If the player's move wins him/herselfanother
// turn, the function returns 1 (to represent "true").Otherwise,
// the function returns 0 (to represent "false").
int computerMove();
// pre: valid data is passed in representing the mancalaboard
// and specifying that the currentplayer is the computer'scolor.
// post: The computer player executes a move according to itsstrategy
// (described below). The current player is updated/switched. Ifthe
// the computer's move wins itself another turn, the functionreturns
// the value 1 (representing "true"). Otherwise, the functionreturns
// the value 0 (representing "false").
void display();
/ / pre: The current mancala board has been passed in as aparameter.
// post: The current mancala board status has been printed to thescreen.
void addToMancala();
// pre: The current player just ended his turn by placing astone
// in one of his empty bowls. The current mancala board hasbeen
// passed in as a parameter.
// post: The newly placed stone, plus all of the stones fromthe
// opponent's corresponding bowl, are added to the currentplayer's
// mancala.
};
Guidelines For the Computer's Playing Strategy
The computer's strategy is a simple one. As long as your programimplements the following guidelines, feel free to expand upon themas you wish.
1) If possible, the computer player should move in such a way thatit wins another turn. If there are multiple options, any selectionwill do.
2) If guideline 1 is inapplicable, the computer player shouldexecute a turn that will result in a capture.
3) If guidelines 1 and 2 are both inapplicable, the computer playershould choose the bowl with the most number of stones, and move ineither direction. If there are multiple options for the startingbowl, any selection will do.
Output
The game's board and interface may be presented as text, as long asit is in a readable format. A very simple output style for gameexecution can be found here. Your program output need not match thesample execution; the given display is only one possibility. Youare welcome to provide a more complex display, but one of thislevel is perfectly acceptable. Before prompting the user forhis/her move each turn, however, your program should display theboard in its current state, as well as the color of the currentplayer. It may be helpful to display additional information (e.g.when a capture has taken place), but it is not required.
Additional Requirements
1) The program should continue to work without modification if theconstant defining the number of bowls used is given a differentvalue and the code is recompiled. (This means you will need towrite a formula for calculating the number of an opponent'scorresponding bowl, for use within the function that adds stones toa mancala.)
2) At any given time, a player should be allowed to save the gameinfo to a file. A save file
should store: the current player, the stones on the game board, andany other relevant
information. A previously saved game may also be loaded by the userat the beginning
of each round.
3) If a user wishes to play a new game without loading a new file,you will need to remember to re-initialize the board.
4) For guidelines 1 and 2 of the computer's strategy, be aware thatthe computer player could have enough stones in its starting bowlto circle the entire board, and still end the turn at its ownmancala (thus winning another turn). Your code should be able tohandle this situation.
5) Separate your code into different files containing functionprototypes, function bodies, and main(). Compile the program withan appropriate makefile.
Hints
In implementing the move() function, try using the value ofcurrPlayer to determine which row (0 or 1) is the current player'sside of the board. (You should not need to write one individualblock of code to handle a Red player move, and another block tohandle a Blue player move.)
To assist with the implementation of the computer's strategy, itmay help to write a function that takes the information for apotential move (i.e. a bowl number and the direction), anddetermines where the last stone will land, if the move isexecuted.
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel