Mancala


Collapse Content

In this challenge, you need to create a Program to Play Mancala, also known as Kalah.

Rules

Note: these rules and diagram are based on Wikipedia's.

Goal
The goal of the game is to capture more pieces, (or "seeds") than one's opponent.

Gameplay

Example turn

Store (0) 2 1 2 3 5 Store (0)
4 3 1 2h 2

The player begins sowing from the highlighted house.

Store (0) 2 1 2 3 5 Store (1)
4h 3 1 3

The last seed falls in the store, so the player receives an extra move.

Store (0) 2 1 2 3h 5 Store (1)
4 1 2 1h 3

The last seed falls in an empty house on the player's side, with seeds in the opposite house.

Store (0) 2 1 2 5 Store (5)
4 1 2 3

The player captures the 4 seeds and ends his/her turn.

The player captures the 4 seeds and ends his/her turn.

  1. At the beginning of the game, three pieces are placed in each cell.
  2. Each player controls the six cells and their pieces on his/her side of the board. His score is the number of pieces in the store to his right.
  3. Players take turns sowing their seeds (the pieces). On a turn, the player removes all seeds from one of the cells under his control. Moving counter-clockwise, the player drops one seed in each cell in turn, including the player's own store and his opponent's.*
  4. If the last sown seed lands in the player's store, the player gets an additional move. There is no limit on the number of moves a player can make in his/her turn.
  5. If the last sown seed lands in an empty cell owned by the player, both the last seed and the opposite seeds (if there are any) are captured and placed into the player's store. (Note that the player's own piece is "captured" even if there are no pieces on the other side.)*
  6. When one player no longer has any seeds in any of his/her cells, the game ends. The other player moves all remaining seeds to his store, and the score for each player is the number of pieces in his store.

* This rule is for a variety of Mancala used in the current challenge.

Scoring
The goal of the game is to get the highest score by getting the most pieces in your store. The game consists of 2 rounds, so each player can go first. The winner is the the player with the highest combined score.

Format

You will be given an integer array board with 14 cells in it from 0 to 13. It will contain the number of pieces in each cell. This is the starting position, with the array's index numbers above and below:

13 12 11 10  9  8  7
-----------------------
 0  3  3  3  3  3  3  
    3  3  3  3  3  3  0  
-----------------------
    0  1  2  3  4  5  6

You are player1. Each turn you need to return an integer from 0 to 5 of the cell you wish to empty. If you return 5 to start with, it will result in the following position:

0  3  3  3  3  4  4  
   3  3  3  3  3  0  1

This turn placed one piece in your own store, and 2 pieces on your opponent's side.

Challenge

Create a program to play mancala as described above. Good luck!

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

  • The game seems to have not the same behaviour as shown in the description. One example is:
    Field twelve contains 12 pieces.
    --> The computer takes all of them and puts 2 into field 13 and then 1 in field 0, 1 in field 1 and 1 in field 2.
    Why does the computer put two pieces in field two?

  • Sorry, field twelve does not contain 12, but 5 pieces.

Contact Us
Sign in or email us at [email protected]