C++代写:ITP4704 Mancala

代写游戏Mancala,也就是非洲棋。

Background

Mancala is an ancient family of board games, and there are numerous variants. One of the most basic games is known as Kalah. The Mancala board is made up of two rows of six holes, called pits, each. Four stones are placed in each of the twelve pits. Each player gets a bigger hole, called store, at the right sides of his/her row of pits. The stores are initially empty. The following diagram shows the initial setting of a Mancala board. (Reference: http://play-mancala.com)

Game Rule

  • The game begins with one player grabbing all the stones in one of the pits of his/her side.
  • Moving in anti-clockwise direction, the player deposits ONE stone in each pit hole until all the stones are “sowed”.
  • When you run into your own store, sow a stone into it also. If you run into your opponent’s store, skip it without sowing.
  • If you drop your last stone into your store, pick another pit to repeat the process again.
  • If your last stone goes into an empty pit of your side, you can capture all stones of your opponent’s pit that is directly opposite to your last pit, if there is any stone in it. If there is any stone to be captured, place your capture stones into your store together with the last stone you have just sowed. If there is no stone in the opposite pit, nothing will happened to your last stone sowed.
  • Two players take turn alternatively until one of the rows is emptied.
  • The player who still has stones in his/her side will capture all stones and put them into his/her own store.
  • Count the stones in the stores. The one who got more stones win the game.

Task

You will need to implement the game using C++. The assignment will be divided into two stages. In the first stage, you are required to implement the game using arrays. Your program must have a class called Mancala with the following functions:

  • Constructor with two int parameters - the first sets the number of pits per row and the second sets the number of initial stones in each pit.
  • Default constructor (or constructor with default values: 6 pits in a row, 4 stones in each pit.)
  • bool move(int player, int pit) - this function allows a player to pick a pit to start sowing. The first parameter represents the player (0 or 1) and the second parameter represents the pit to pick, counting towards the right, with the leftmost one being 1. The function returns true if the sowing stops at a player’s store (yields an extra move) and returns fasle otherwise. You should check if the move is valid (e.g. the pit is not empty) before calling the function.
  • int score(int player) - this function returns the number of stones inside the player’s store. The parameter represents the player (0 or 1).
  • int pit(int player, int pit) - this function returns the number of stones insides a player’s pit. The first parameter represents the player (0 or 1) and the second parameter represents the pit to retrieve.
  • void printBoard() - this functions uses std::cout to display the status of the Mancala board.
  • bool gameEnd() - returns if the game has come to an end. (One of the rows becomes all empty). The function will also clear all pits of the opponent and put the stones into its store.

You should also include a main program containing the game flow to execute the game. You can check the last two pages for some sample output of the programme. The first stage of your programme will contribute 50% of the marks of the whole EA.

After finishing your first stage, you are required to implement the data structure in your game (e.g. the rows and/or stores) again in a data structure that you have learnt in your class, e.g., Linked List, Circular List, Stack, Queue and etc. You can use the implementation given in the lecture and/or lab , but NOT the data structure classes provided by C++ STL. If you want to add extra functions to the data structure to solve question-specific problems, you may inherit the classes given in the lecture and/or lab. You may need to change some the private members to protected in the given data structure implementation in order to access some essential data, but you are not supposed to change the existing implementation of other functions.

This part, together with the documentation, testing evidence and other coding practice, will contribute 40% of the whole EA.

At the end, if you want to earn more bonus marks, you may choose to implement one more function in your game - Undo. Successfully implement such a function will earn you a maximum 10% of bonus in your EA.

Instructions to Students

  1. This assignment is the End of Module Assessment and you must have 40 marks or above in this assignment in order to pass the module.
  2. This assignment is an individual assignment and each student has to submit his/her own work. Plagiarism is a serious offence and any assignments that involve any plagiarism will be given ZERO marks. The award of Zero marks will apply to all parties, regardless of whether or not a student is the original author or the plagiarist. Further disciplinary action will follow.
  3. Your programs must follow a neat coding standard such as adequate comments and indentation. Marks will be deducted if the coding standard is poor.
  4. In your first stage, you need to hand in:
    • a. All related .cpp and .h files. If you are using Visual Studio to work out your assignment, state clearly which version of Visual Studio you are using in your document and zip all files in the project folder so that I can open it in Visual Studio.
  5. For your second stage, you are required to hand in:
    • a. The evidence of testing. Submit the listing of sample run. You should include some input errors in your sample output to show that you have performed adequate error checking in your program.
    • b. All related .cpp and .h files. If you are using Visual Studio to work out your assignment, state clearly which version of Visual Studio you are using in your document and zip all files in the project folder so that I can open it in Visual Studio.
    • c. A short description of your program design. Tell me how you have used your chosen data structure and how you have modified the data structure to suit the problem. You should also explain how your functions in Mancala class and the supporting class(es) work. You are also expected to explain the flow of your main program.
  6. All work is to be submitted through Moodle website