project3

project3 - Spring 2009 CS 32 Programming Assignment 3 Kalah...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Spring 2009 CS 32 Programming Assignment 3 Kalah Time due: 9:00 PM Tuesday, May 26 Kalah is one of a family of African and Asian games that have been played since ancient times. For this project, you are to write a program that plays the game of Kalah well. The game has many variants, so we'll first describe the one we'll use for this project. Kalah is played on a board that looks like this: Each of the two players, North and South, has six holes on his side of the board and one pot (his "kalah"). Each hole start off with four beans in it. Players take turns making moves. A move begins with a player picking up all of the beans in one of his six holes. Then, proceeding counterclockwise, he puts one bean in each hole and his own pot (skipping over his opponent's pot if the "sowing" gets that far), until all of the beans he picked up have been sown. For example, if South had 4 beans in his #5 hole, he might pick them up and deposit one each in his #6 hole, his pot, and North's #6 and #5 hole. Depending on where the last bean ends up, one of three things happens: If it was placed in the player's pot, he must take another turn. If it was placed in one of the player's own holes that was empty just a moment before, and if the opponent's hole directly opposite from that hole is not empty, then that bean and all beans in the opponent's hole directly opposite from that hole are put into the players pot, and the turn ends. (This is a capture .) In all other cases, the turn ends. Whenever a turn ends with all of the holes on one side of the board empty (no matter whose turn ended), the game is over, and any beans in the other player's holes are put into that other player's pot. The winner is then the player with the most beans in his pot. As an example of the rules, consider the following endgame; it's South's turn: North 1 2 3 4 5 6 ---------------- 2 4 0 0 0 0 North's pot 22 16 South's pot 0 0 1 1 1 1 ---------------- 1 2 3 4 5 6 South Suppose South moves from his hole #6: 2 4 0 0 0 0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
22 17 0 0 1 1 1 0 Since that ended up in his pot, he goes again, choosing, say, hole #4: 2 4 0 0 0 0 22 17 0 0 1 0 2 0 Suppose North now chooses her hole #1: 0 4 0 0 0 0 23 17 1 0 1 0 2 0 If South now chooses his hole #1, he captures the beans in North's hole #2: 0 0 0 0 0 0 23 22 0 0 1 0 2 0 Since all the holes on one side are empty, the game is over, and the 3 beans still in South's holes go into South's pot: 0 0 0 0 0 0 23 25 0 0 0 0 0 0 South has 25 beans to North's 23, so South wins. Your program will be designed to allow two players to play against each other. Each player will be either a human or a computer player. The computer player's behavior will be embodied in a C++ class described later. You will write different classes for different kinds of computer players. For example, one kind of computer player may be really dumb and just pick an arbitrary one of its holes for its turns. Another may play by considering moves and countermoves, selecting the move it determines is best. Let's see how it might
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

project3 - Spring 2009 CS 32 Programming Assignment 3 Kalah...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online