write a python program to reflect the following: a class called Mancala that allows two people to play a text-based version of the game (check the attached PDF file for the detailed rules). For this board game, two players can play. As the figure shows, the player who choose the bottom red position will be player 1 and the player choose the top blue position will be player 2. Each player could only choose the pit on his side in each round: player 1 can only choose pits in red and player 2 can only choose pits in blue. The index for each pit is marked in the figure as well. We don’t require a GUI for this project and all the input/output will be in the text format. You can improve your code later on after you finished the required part to make it your own portfolio project. Your code for the game must define the class and methods described below, but you are encouraged to define other methods or classes that may be useful for the game. All data members must be private. Mancala: The Mancala object represents the game as played. The class should contain information about the players and information about the board, it must contain those methods (but may have more):

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

write a python program to reflect the following:

a class called Mancala that allows two people to play a text-based version of the game (check the attached PDF file for the detailed rules).

For this board game, two players can play. As the figure shows, the player who choose the bottom red position will be player 1 and the player choose the top blue position will be player 2. Each player could only choose the pit on his side in each round: player 1 can only choose pits in red and player 2 can only choose pits in blue. The index for each pit is marked in the figure as well.

We don’t require a GUI for this project and all the input/output will be in the text format. You can improve your code later on after you finished the required part to make it your own portfolio project.

Your code for the game must define the class and methods described below, but you are encouraged to define other methods or classes that may be useful for the game. All data members must be private.

Mancala: The Mancala object represents the game as played. The class should contain information about the players and information about the board, it must contain those methods (but may have more):

  • create_player: takes one parameter of the player’s name as a string and returns the player object. (You can define the player class by yourself. It will be your own design.)
  • print_board: takes no parameter and will print the current board information in this format:

player1:

store: number of seeds in player 1’s store

player 1 seeds number from pit 1 to 6 in a list

player2:

store: number of seeds in player 2’s store

player 2 seeds number from pit 1 to 6 in a list (check the last part for examples)

  • return_winner: takes no parameter.

If the game is ended, return the winner in this format:

“Winner is player 1(or 2, based on the actual winner): player’s name”

If the game is a tie, return "It's a tie";

If the game is not ended yet, return "Game has not ended".

  • play_game: takes two parameters, the player index (1 or 2), and the pit index (1 or 2…. or 6), both as integers. This method should follow the rules of this game including the two special rules and update the seeds number in each pit including the store. It should also check the ending state of the game and once the ending state is reached, it should follow the rules and updated the seeds number in the pit and store for both players.

If user input invalid pit index number (>6 or <=0), return "Invalid number for pit index";

If the game is ended at this point, return "Game is ended";

If the player 1 win an extra round following the special rule 1, print out “player 1 take another turn" (similar for player 2)

At the end, the method should return a list of the current seed number in this format:

[player1 pit1, player1 pit2, player1 pit3, player1 pit4, player1 pit5, player1 pit6, player1 store, Player2 pit1, player2 pit2, player2 pit3, player2 pit4, player2 pit5, player2 pit6, player2 store,]

Note: in order to test some methods in fewer steps, we may or may not follow the rules to call the two players in turns for play_game method, so your code should not enforce that. For example, we might keep calling player 1 for four times, then call player 2 twice, and then call player 1 for three times. 

  • As a simple example, your class could be used as follows:

    game = Mancala() player1 = game.create_player("Lily") player2 = game.create_player("Lucy") print(game.play_game(1, 3)) game.play_game(1, 1) game.play_game(2, 3) game.play_game(2, 4) game.play_game(1, 2) game.play_game(2, 2) game.play_game(1, 1) game.print_board() print(game.return_winner())
  • And the output will be:

    player 1 take another turn [4, 4, 0, 5, 5, 5, 1, 4, 4, 4, 4, 4, 4, 0] player 2 take another turn player1: store: 10 [0, 0, 2, 7, 7, 6] player2: store: 2 [5, 0, 1, 1, 0, 7] Game has not ended
  • Another test example could be:

    game = Mancala() player1 = game.create_player("Lily") player2 = game.create_player("Lucy") game.play_game(1, 1) game.play_game(1, 2) game.play_game(1, 3) game.play_game(1, 4) game.play_game(1, 5) game.play_game(1, 6) game.print_board() print(game.return_winner())
  • And the output will be:

    player 1 take another turn player1: store: 12 [0, 0, 0, 0, 0, 0] player2: store: 36 [0, 0, 0, 0, 0, 0] Winner is player 2: Lucy
How to Play Mancala
Objective: To collect as many seeds in your store as possible. The player with the most seeds in
his/her store at the end of the game wins.
Set Up: Place four seeds in each of the six pits on your side of the game board. Your opponent
should do the same. The colors of the seeds don't matter. (For a shorter game, you can play with
three seeds in each pit.)
pits (sometimes
called hollows.
holes, or cups)
• WWW
• •
::
• :
Playing:
Basic Rules:
* Play always moves around the board in a counter-clockwise
circle (to the right)
* The store on your right belongs to you. That is where you keep the seeds you win.
* The six pits near you are your pits.
*Only use one hand to pick up and put down seeds.
* Once you touch the seeds in a pit, you must move those seeds.
*Only put seeds in your own store, not your opponent's store.
• :
Example of how to begin the game:
8
Starting the Game:
On a turn, a player picks up all the seeds in one pit and "sows" them to the right, placing one
seed in each of the pits along the way. If you come to your store, then add a seed to your store
and continue. You may end up putting seeds in your opponent's pits along the way.
Play alternates back and forth, with opponents picking up the seeds in one of their pits and
distributing them one at a time into the pits on the right, beginning in the pit immediately to the
right.
store (sometimes
called a "Mancala"
or a "capture pit")
Special Rules:
*When the last seed in your hand lands in your store, take another turn.
*When the last seed in your hand lands in one of your own pits, if that pit had been empty you
get to keep all of the seeds in your opponents pit on the opposite side. Put those captured seeds,
as well as the last seed that you just played on your side, into the store.
Created by Alycia Zimmerman for classroom use.
seeds (sometimes
called stones)
Ending the Game:
The game is over when one player's pits are completely empty. The other player takes the seeds
remaining in her pits and puts those seeds in her store. Count up the seeds. Whoever has the most
seeds wins.
:
On the game board above, the pink player (bottom row) just made his first move of the game. He
picked up all of the seeds from the third pit and placed one seed in each of the pits to the right.
The final seed in his hand landed in his store, so he now gets to take another turn.
Transcribed Image Text:How to Play Mancala Objective: To collect as many seeds in your store as possible. The player with the most seeds in his/her store at the end of the game wins. Set Up: Place four seeds in each of the six pits on your side of the game board. Your opponent should do the same. The colors of the seeds don't matter. (For a shorter game, you can play with three seeds in each pit.) pits (sometimes called hollows. holes, or cups) • WWW • • :: • : Playing: Basic Rules: * Play always moves around the board in a counter-clockwise circle (to the right) * The store on your right belongs to you. That is where you keep the seeds you win. * The six pits near you are your pits. *Only use one hand to pick up and put down seeds. * Once you touch the seeds in a pit, you must move those seeds. *Only put seeds in your own store, not your opponent's store. • : Example of how to begin the game: 8 Starting the Game: On a turn, a player picks up all the seeds in one pit and "sows" them to the right, placing one seed in each of the pits along the way. If you come to your store, then add a seed to your store and continue. You may end up putting seeds in your opponent's pits along the way. Play alternates back and forth, with opponents picking up the seeds in one of their pits and distributing them one at a time into the pits on the right, beginning in the pit immediately to the right. store (sometimes called a "Mancala" or a "capture pit") Special Rules: *When the last seed in your hand lands in your store, take another turn. *When the last seed in your hand lands in one of your own pits, if that pit had been empty you get to keep all of the seeds in your opponents pit on the opposite side. Put those captured seeds, as well as the last seed that you just played on your side, into the store. Created by Alycia Zimmerman for classroom use. seeds (sometimes called stones) Ending the Game: The game is over when one player's pits are completely empty. The other player takes the seeds remaining in her pits and puts those seeds in her store. Count up the seeds. Whoever has the most seeds wins. : On the game board above, the pink player (bottom row) just made his first move of the game. He picked up all of the seeds from the third pit and placed one seed in each of the pits to the right. The final seed in his hand landed in his store, so he now gets to take another turn.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education