Awale 1. Introduction 2. Rules 3. Compiling 4. Playing 1. Introduction Awale is an African Mancala game for two players. Mancala games are games played on a board, with 12 pits and 48 seeds although these numbers may be different for some games. There are many different games that can be played on such a board, one of which is Awale. I have seen several variations on the rules of Awale, so even if you think you know how to play, be sure to read through the rules before you start. I implemented this program for fun. I know there are already programs out there that play many different versions of Mancala games. There are even some Java-based games you play online. I decided to implement my own game because I couldn't find any implementation that used the exact rules I was used to. The user interface is spartan, but hopefully clear. If you enjoy this game, please drop me a note at davesullins@earthlink.net. Thanks! 2. Rules The Awale board consists of 12 pits, 6 on each side. Six pits belong to Player 1 and the other six pits belong to Player 2. The two players take turns choosing one of their pits, scooping up their seeds, and sowing them around the board counter-clockwise. The object of the game is to capture as many of your opponent's seeds as possible. At the end of the game, whoever has the most seeds wins. Initially, four seeds are placed in each pit. The board looks something like this: +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ When it is your turn, you may choose any pit on your side of the board with seeds in it to sow from. You sow seeds by removing all the seeds from the pit you have chose, and then placing one seed in each adjacent pit, moving counter-clockwise from the pit you started in, until you run out of seeds. For example, suppose you are the player on the bottom side of the board shown above. If we number your pits 1 through 6, as shown below, then let's see what happens if you decide to move pit 4. +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ 1 2 3 4 5 6 First, you remove all the seeds from pit 4: +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 0 | 4 | 4 | (4 seeds in your hand) +---+---+---+---+---+---+ 1 2 3 4 5 6 Then, you place one seed in pit 5. +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 0 | 5 | 4 | (3 seeds in your hand) +---+---+---+---+---+---+ 1 2 3 4 5 6 Then, you place one seed in pit 6. +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 4 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 0 | 5 | 5 | (2 seeds in your hand) +---+---+---+---+---+---+ 1 2 3 4 5 6 Then, you place one seed in pit 7. 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 4 | 5 | (1 seed in your hand) +---+---+---+---+---+---+ | 4 | 4 | 4 | 0 | 5 | 5 | +---+---+---+---+---+---+ Finally, you place the last seed in pit 8. 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 4 | 4 | 4 | 5 | 5 | +---+---+---+---+---+---+ | 4 | 4 | 4 | 0 | 5 | 5 | +---+---+---+---+---+---+ In Awale, unlike some other Mancala games, each player only make one move on his or her turn, whether or not any of the opponent's seeds are captured. Seeds are captured in the following manner. If at the end of your turn the final seed you place on the board ends in the opponent's pit, and placing that seed brings the total number of seeds in the pit to 2 or 3, then you may capture some seeds. Additionally, if the pit before it also belongs to the opponent and contains 2 or 3 seeds, you capture those seeds as well. This continues backward around the board until you reach a pit that belongs to you or does not contain 2 or 3 seeds. The following examples should illustrate the concept. Suppose the layout of the board is the following, you are the bottom player, and it is your turn. 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 5 | 2 | 1 | 0 | 1 | +---+---+---+---+---+---+ | 0 | 5 | 5 | 5 | 5 | 2 | +---+---+---+---+---+---+ 1 2 3 4 5 6 If you move pit 5, after sowing the seeds the board will look like this: 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 5 | 3 | 2 | 1 | 2 | (final pit is 10) +---+---+---+---+---+---+ | 0 | 5 | 5 | 5 | 0 | 3 | +---+---+---+---+---+---+ 1 2 3 4 5 6 Since pit 10 contains 3 seeds and pit 9 contains 2 seeds, you remove all 5 seeds. Your score increases by 5 and the board now looks like this: 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 5 | 0 | 0 | 1 | 2 | +---+---+---+---+---+---+ | 0 | 5 | 5 | 5 | 0 | 3 | +---+---+---+---+---+---+ 1 2 3 4 5 6 Now suppose instead you had moved the seeds from pit 3. After sowing the seeds, the board would look like this: 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 5 | 2 | 1 | 1 | 2 | (final pit is 8) +---+---+---+---+---+---+ | 0 | 5 | 0 | 6 | 6 | 3 | +---+---+---+---+---+---+ 1 2 3 4 5 6 Even though the pit before the one you ended in, pit 7, contains 2 seeds, you capture nothing. The final pit, pit 8, contains only 1 seed, and you need 2 or 3 seeds in the final pit to capture something. As a final example, suppose we had moved pit 2. After sowing the seeds, the board would look like this: 12 11 10 9 8 7 +---+---+---+---+---+---+ | 4 | 5 | 2 | 1 | 0 | 2 | (final pit is 7) +---+---+---+---+---+---+ | 0 | 0 | 6 | 6 | 6 | 3 | +---+---+---+---+---+---+ 1 2 3 4 5 6 In this case you capture the 2 seeds in pit 7, but not the 3 seeds in pit 6. You can only capture seeds on your opponent's side of the board, not your own. You would remove the 2 seeds from pit 7, and your score would increase by 2. There is one other rule that seems to be the biggest difference between different versions of Awale. It is not difficult to imagine a case where one player has no seeds left at the beginning of their turn. This could happen either because one player captured all of his or her opponent's seeds on the preceding turn, or because one player "starved" the other player by refusing to make any move that would give the other player any seeds until the other player ran out. The question is, what should happen when a player has no seeds left to sow on their turn? Suppose it is now player 1's turn and he or she has no seeds left. The various possible outcomes are: 1) The game ends immediately and whoever has captured the most seeds wins. 2) Player 1 receives all the seeds left on the board. 3) Player 2 receives all the seeds left on the board. 4) Player 1 automatically loses. 5) Player 1 automatically wins. 6) Player 2 is not allowed to leave player 1 in this position. I have seen most of these rules used, but the last one is the one that was used when I learned to play Awale. It was explained to me that the game is based on agricultural tradition, and while one farmer may want to have the most bountiful harvest, the farmer would never leave the neighboring farmer to starve. Thus, you simply are not allowed to leave your opponent with no seeds. Unfortunately, rule 6 this leaves an ambiguity of what happens when you CANNOT give the other player any seeds. Since this case was not covered in the rules I learned, I find that rule 5 is the closest in spirit to rule 6, without leaving any ambiguity. Therefore, in my program when you leave your opponent with no seeds the game is over and your opponent wins. 3. Compiling To compile Awale, you can probably just run "make" from the source directory. The program will be called "awale." Copy this file to a bin directory for convenience, and you are set. If this does not work, you probably need to edit the Makefile. If you don't have gcc, change the line "CC=gcc" to "CC=cc" (or whatever your C compiler is named). You may want to remove the -O3 option from CFLAGS as well, since optimizations may sometimes cause programs to be unstable, especially with strange development versions of gcc. 4. Playing In the simplest form, you can run awale just by typing "awale". If you want the computer to make the first move, you can try "awale -c". If you want to change the level of difficulty, you simply type "awale -5" or any number between 1 and 9. I don't recommend any setting higher than -6 for current processors (P4 2GHz) and I don't recommend anything higher than -5 for old processors (Pentium 1, AMD K6). This level number is the number of moves the computer looks ahead when choosing its next move. The number of moves it has to simulate is approximately 36^n, where n is the level. So -4 (the default level) simulates up to 36^4, or 1679616 different moves. When playing the game, you are always the player on the bottom. Enter a number between 1 and 6 to choose which pit you will move. If you want the computer to suggest a move, you can type s or S. That's it. Have fun!