Mancala Game
Due: October 5
Objective
To continue practicing Java programming including control structures, input, output, variables, functions and arrays.Task
For this program, you will write a version of the Mancala board game in Java. Mancala is one of the oldest board games and variations are played all over the world. Mancala is a two-player game and each player has one side of the board. Each side consists of six holes and a "well" which can store pieces:
There are 48 pieces which begin divided evenly among the 12 holes, with four pieces in each. The goal of the game is to get as many pieces into your well as possible.
Play consists of multiple turns in which the player whose turn it is chooses one of their holes. They then pick up the pieces in that hole and move them to their right, dropping a piece in each hole on the way. If they reach their well, they drop one piece there as well. If they still have pieces after dropping one into the well, they begin dropping pieces into their opponents side of the board as well - moving right to left. Players never drop pieces into their opponent's well, however.
If a player reaches their well with the last piece from the hole they picked up, then they get to go again.
If a player drops their last piece into one of their empty holes, and their opponent has any pieces in the adjacent hole, then the player takes the piece they dropped and those in the opponent's adjacent hole and puts them into their well.
Play ends when either player has zero pieces in the holes on their side of the board at the end of a turn. Once one player runs out, any pieces in the other player's holes are added to that player's well. The player with the most pieces in their well is then declared the winner.
There is an online version of Mancala here which you can use to familiarize yourself with the game.
Details
- Your program should allow the user to play Mancala against a computer opponent.
- The program should alternate between the player's turn, wherein you ask the user which of their holes they would like to move the pieces from, and the computer's turn wherein you use a strategy (discussed below) to move the computer's pieces.
- You should use arrays to represent each players side of the board, and to store the number of pieces in each hole.
- You should have appropriate bounds checking on the player's choice e.g. don't allow them to choose an invalid hole.
- You should alternate between player and computer turns until one runs out of pieces.
- You should then print the winner (or indicate a tie game in that case - which is possible).
- After each complete game, you should ask the user if they want to play again.
- It should be randomly chosen who goes first.
- You should split this program into at least three functions.
- You can design the user input and output however you like, but you must make it clear how to play the game. It also has to be clear to the player how many pieces that they and the computer have in each hole.
Computer Strategy
For this assignment, you will need to come up with a strategy for the computer player. The simplest strategy to make the game work would be to have the computer select its move at random, or always start from one end or the other. If you choose this strategy, you can receive a grade of up to an 85% on the assignment, assuming everything else works perfectly.
To get a better grade, you will need to program more intelligent behavior. How you accomplish this is up to you, but your grade will be based on how difficult your program is to beat, and by how sophisticated your algorithm is. Especially good strategies can get extra credit!
General Requirements
- Your code should be readable and reasonably indented.
- You must provide comments in your program.
- You must include a comment at the top with your name.
- You should not have a "package" line in your program.
- You should not have the comments NetBeans puts in by default e.g. the "license header", "@author" or "TODO" lines.
- Your file name/class name should be something descriptive, not something like "JavaApplication4".