Prog 5: Mancala
Create a Mancala program where you can play against a computer opponent. If you are not familiar with the game see mancalatime.com, which is very similar to the rules we will be using (but not exactly the same). That board online looks like:
We will create a text-based representation of the board instead, and will only use 3 "stones" per hole, which will look like:
Author: Dale Reed Program 5: Mancala TA: Fred A. Stair, T 6:00 AM Nov 28, 2012
Welcome to the game of Mancala, where you are playing against a computer opponent. Your holes are on the bottom row and you get to go first.
-------------------------------------------
A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | 0 | | 0 | ----| 3 | 3 | 3 | 3 | 3 | 3 |---- ----------------------------- A B C D E F 1. Select a move (A..F)-> D
A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | 0 | | 1 | ----| 3 | 3 | 3 | | 4 | 4 |---- ----------------------------- A B C D E F You get another move -> A
A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | 0 | | 1 | ----| | 4 | 4 | 1 | 4 | 4 |---- ----------------------------- A B C D E F Squares in column D are captured.
A B C D E F ----------------------------- ----| 3 | 3 | 3 | | 3 | 3 |---- | 0 | | 5 | ----| | 4 | 4 | | 4 | 4 |---- ----------------------------- A B C D E F
------------------------------------------- Computer chooses C
A B C D E F ----------------------------- ----| 4 | 4 | | | 3 | 3 |---- | 1 | | 5 | ----| | 4 | 4 | | 4 | 4 |---- ----------------------------- A B C D E F Computer gets another move. Computer chooses F
A B C D E F ----------------------------- ----| 4 | 4 | 1 | 1 | 4 | |---- | 1 | | 5 | ----| | 4 | 4 | | 4 | 4 |---- ----------------------------- A B C D E F Squares in column C are captured.
A B C D E F ----------------------------- ----| 4 | 4 | | 1 | 4 | |---- | 6 | | 5 | ----| | 4 | | | 4 | 4 |---- ----------------------------- A B C D E F
-------------------------------------------
A B C D E F ----------------------------- ----| 4 | 4 | | 1 | 4 | |---- | 6 | | 5 | ----| | 4 | | | 4 | 4 |---- ----------------------------- A B C D E F
2. Select a move (A..F)->
. . .
The rules of the game might seem complicated, but once you play it they make sense. (Modified slightly from the Ask.com Mancala page)
The Mancala 'board' is made up of two rows of six holes each. If you don't have a Mancala board handy, an empty egg carton is perfect.
Three pieces (marbles, stones or seeds) are placed in each of the 12 holes. The color of the pieces is irrelevant.
Each player has a 'store' to the right side of the Mancala board. Cereal bowls work well for this purpose.
The game begins with one player picking up all of the pieces in any one of the holes on his side.
Moving counter-clockwise, the player deposits one of the stones in each hole (including your or your opponent's store) until the stones run out.
If the last piece you drop is in your own store, you get a free turn.
If the last piece you drop is in an empty hole on your side, you capture that piece and any pieces in the hole directly opposite. All captured pieces are placed in your store.
The game ends when all six spaces on one side of the Mancala board are empty.
The player who still has pieces on his side of the board when the game ends captures all of those pieces.
Count all the pieces in each store. The winner is the player with the most pieces.
Notes
If the number of stones in a hole is 0, do not display anything there.
Consider using the time.h function calls to "animate" the screen by clearing it between moves after displaying the computer move
I recommend you write this program in steps as follows, where the points are broken down out of the total 55 points for execution:
(0 points) Create the "shell" that displays instructions, identifying information, allocates space to store the board pieces. Initialize the values for each of the board stones, and display the board.
(25 points) Implement having the program let two humans play against each other, with no extra moves.
(10 points) Have the program detect when a user ends a move by putting a stone in their store. In this situation the program should indicate that there is an extra move and should allow that move.
(5 points) Have the program detect when a user ends a move by putting a stone in an empty hole. That piece and any pieces opposite should be transferred to the store.
(10 points) Have the program detect the end of the game, when all the pieces are cleared off of the side for one of the players. The opponent gets to transfer all stones on their side into their store. Indicate who won the game
(30 points) With the above steps all written, you now have the building blocks to play against a computer opponent.
(10 points) When it is the computer's turn, try each possible computer move to see which one gives the most stones in the store for the computer and the fewest for the human. This is trickier than it seems because certain moves result in a capture of opponent's stones, while other moves ending in the store result in one or more additional moves.. Have the computer select the best move of the 6 possibilities.
(10 points) Now expand the computer possibilities. For each of the six possible computer moves also consider the 6 possible human moves, for a total of 36 configurations that need to be examined. At each point assume the human will select the move that is best for the human, and the computer will select the move that is best for the computer. Moves like this that are good for one when they are bad for the other are called zero-sum. At this second level assume the human will choose the move that is worst for the computer.
(10 points) Same as before, but expand this notion to a 3rd level. For each of the 6 computer moves also look at the 6 human moves (from the step above), and now for each of those also consider the resulting 6 moves the computer might make. At this 3rd level we again select the best possible move from the perspective of the computer.
Turn in to Blackboard