Small Basic Small Basic E-Books > Basic Computer Games Small Basic Edition > Awari

Awari is an ancient African game. The board is divided into six compartments or pits on each side (numbered as shown below). In addition, there are two special home pits at the ends:

My Side
6 5 4 3 2 1
My Your
Home Home
1 2 3 4 5 6
Your Side

A move is made by taking all of the beans from any (non-empty) pit on your own side. Starting from the pit to the right of this one, these beans are 'sown' one in each pit working around the board anticlockwise.

A turn consists of one or two moves.

If the last bean of your move is sown in your own home you may take a second move.

If the last bean sown in a move lands in an empty pit, provided that the opposite pit is not empty, all the beans in the opposite pit, together with the last bean sown, are 'captured' and moved to the player's home.

This chapter is adapted from the book Basic Computer Games Small Basic Edition published by BibleByte Books.

To purchase this book in its entirety, please see the Computer Science For Kids web site.

When either side is empty, the game is finished. The player with the most beans in his home has won.

In the computer version, the board is printed as 14 numbers representing the 14 pits.

3 3 3 3 3 3
0 0
3 3 3 3 3 3

The pits on your (lower) side are numbered 1-6 from left to right. The pits on my (the computer's) side are numbered from my left (your right). To make a move you type in the number of a pit If the last bean lands in your home, the computer types 'AGAIN?' and you then type in your second move.

The computer's move is typed, followed by a diagram of the board in its new state. The computer always offers you the first move. This is considered to be a slight advantage.

There is a learning mechanism in the program that causes the play of the computer to improve as it plays more games.

This version of Awari is adopted from one originally written by Geoff Wyvill of Bradford, Yorkshire, England.

Code Listing (Small Basic File:

TextWindow.CursorLeft = 34 TextWindow.WriteLine("AWARI") 
TextWindow.CursorLeft = 15
For i = 1 TO 13 BArray[I] = 0 GArray[I] = 0 EndFor
For i = 1 TO 50 FArray[I] = 0 EndFor
N=0 LN20: TextWindow.WriteLine("") TextWindow.WriteLine("") E=0
For I=0 To 12 BArray[I]=3 EndFor C=0 FArray[N]=0 BArray[13]=0 BArray[6]=0
LN35: Sub500() TextWindow.Write("YOUR MOVE? ") Sub110()
If E=0 Then Goto LN80 EndIf If M=H Then Sub100() EndIf
If E=0 Then Goto LN80 EndIf TextWindow.Write("MY MOVE IS ") Sub800()
If E=0 Then Goto LN80 EndIf
If M = H THEN TextWindow.Write(",") Sub800() EndIf
If E>0 Then Goto LN35 EndIf LN80: TextWindow.WriteLine("")
TextWindow.WriteLine("GAME OVER") D=BArray[6]-BArray[13]
If D < 0 THEN textwindow.Write("I WIN BY "+-D+" POINTS")
Goto LN20 EndIf N=N+1
If D = 0 Then TextWindow.Write("DRAWN GAME") Goto LN20 EndIf
TextWindow.WriteLine("YOU WIN BY "+D+" POINTS") Goto LN20 Sub Sub100
TextWindow.Write("AGAIN? ") sub110() EndSub
Sub Sub110 LN110: M = TextWindow.ReadNumber()
If M<7 Then IF M>0 THEN M=M-1 Goto LN130 EndIf endif
LN120: TextWindow.Write("ILLEGAL MOVE - AGAIN? ") Goto ln110 LN130:
If BArray[M]=0 Then Goto LN120 EndIf H=6 Sub200() Sub500() EndSub
Sub Sub200 K=M Sub600() E=0 If K>6 Then K=K-7 EndIf C=C+1
If C<9 Then FArray[N]=FArray[N]*6+K EndIf For I=0 To 5 If BArray[I]<>0
Then Goto LN230 EndIf EndFor Goto ln240 LN230: For I=7 To 12
If BArray[I]<>0 Then E=1 Goto ln240 EndIf endfor
ln240: EndSub Sub Sub500 TextWindow.WriteLine("")
TextWindow.Write(" ") For I=12 To 7 Step -1 Sub580() EndFor
TextWindow.WriteLine("") I=13 Sub580() TextWindow.Write(" ")
TextWindow.WriteLine(BArray[6]) TextWindow.Write(" ") F
or I=0 To 5 Sub580() EndFor
TextWindow.WriteLine("") TextWindow.WriteLine("") EndSub
Sub Sub580 If BArray[I]<10 THEN Textwindow.Write(" ") endif
TextWindow.Write(BArray[I]) EndSub Sub Sub600 P=BArray[M] BArray[M]=0
For P=P To 1 Step -1 M=M+1
If M>13 Then M=M-14 EndIf BArray[M]=BArray[M]+1 EndFor
If BArray[M]=1 Then IF M<>6 THEN
IF M<>13 THEN IF BArray[12-M]<>0
THEN goto ln625 EndIf EndIf EndIf EndIf Goto LN799
ln625: BArray[H]=BArray[H]+BArray[12-M]+1
BArray[M]=0 BArray[12-M]=0
LN799: EndSub Sub Sub800 D=-99 H=13
For I=0 To 13 GArray[I]=BArray[I] EndFor
For J=7 To 12 If BArray[J]=0 Then Goto LN885 EndIf G=0 M=J Sub600()
For I=0 To 5 If BArray[I]=0
Then Goto LN845 EndIf L=BArray[I]+I R=0 LN830:
If L>13 Then L=L-14 R=1 Goto LN830 EndIf
If BArray[L]=0 Then IF L<>6 THEN
IF L<>13 THEN R=BArray[12-L]+R EndIf EndIf EndIf
If R>Q Then Q=R EndIf
LN845: EndFor Q=BArray[13]-BArray[6]-Q
If C>8 Then Goto LN875 EndIf K=J If K>6
Then K=K-7 EndIf For I=0 To N-1
If FArray[N]*6+K=Math.Floor(FArray[I]/math.power(6,7-C)+.1)
Then Q=Q-2 EndIf EndFor
LN875: For I=0 To 13 BArray[I]=GArray[I] EndFor
If Q>=D Then A=J D=Q EndIf
LN885: EndFor M=A
TextWindow.Write(Text.GetCharacter(42+M)) Sub200()
For I=0 To N-1 TextWindow.WriteLine(BArray[I]) EndFor EndSub


Sample Run:


Next Chapter > >

© Copyright 2010 By BibleByte Books. All Rights Reserved. BibleByte Books, the BibleByte Books Logo, Computer Science For Kids, the Computer Science For Kids logo, and related trade dress are trademarks or registered trademarks of BibleByte Books.