I am going to post my version of Mancala here. This is NOT intended to be a replacement for the other mancala game by kg583, rather, it is simply another rule set, the one that I was taught. Please continue to optimise kg583's code if at all possible. We will publish both games on the mancala page, so the user can choose his/her rule set. Please see what can be optimised here, too. *arm wave to other members of the site* (it would be nice to have a better participation rate)

My rules are:

board 6 by 2 active houses with 4 stones starting in each, and two wells, one at either end.

Picture at start

(Its been stretched a little)

Each player, on their turn, chooses a house on their side of the board. (6 options)

the stones from that house get distributed by picking them up, and placing 1 stone in each house consecutive to the last, going around in a counter-clockwise pattern until the stones run out. If the last stone falls in one of the wells, then the player gets another turn. The first player to clear their side of the board of stones wins.

After first turn: player 1 has chosen the fourth house from the top, the last stone fell in a well, so player 1 will go again.

Player 1 goes again.

Now its player 2's turn.

End of game image:

Player 2 has won.

Here's the code: I does need optimisation. Be careful of the difference between L1 and the letter L

```
:Clrhome //setup
:14->dim(L1
:Fill(4,L1
:0->L1(7
:0->L1(14 //L1 setup finished here; board ready
:DelVar WDelVar K1->L
:"PLAYER_
:For(P,1,8
:Output(P,1,sub(Ans+"2",P,1
:Output(P,16,sub(Ans+"1",P,1
:End
:Repeat W // Main loop, Keep playing until W is no longer = 0, (equals 1 or 2)
:If L!=7 and L!=14 //Does not switch player if L = 7 or 14, allows for extra turns
:1+(P=1->P //switch player between 1 and 2
:1->L //Initialize L
:For(A,1,6 // Display the board after clearing possible extra numbers. See L1 schematic below.
:Output(A+1,6,"_
:Output(A+1,5,L1(A
:Output(A+1,12,"_
:Output(A+1,11,L1(14-A
:End
:Output(8,8,L1(7
:Output(1,8,L1(14
:1->R //initialize R which is the row input number
:Repeat K=105 and L1(R(P=2)+(14-R)(P=1))!=0 //repeat input routine until user presses enter and the current house is not empty
:Output(R+1,4(P=2)+13(P=1),sub("<>",P,1 //Display the appropriate cursor at the relative R coordinate and at the x value of 4 if P=2 and at 13 if P=1
:Repeat Ans // getkey
:getkey->K
:End
:Output(R+1,4(P=2)+13(P=1),"_ //Delete the cursor
:min(6,max(1,R+(K=34)-(K=25->R //Depending on input, add or subtract 1 from R, within the bounds
:End // End input routine
:R(P=2)+(14-R)(P=1)->L //Calculate L Based on R and the player number (right now, L is the list element number that was chosen)
:L1(L->S //Set S to the number of stones in the chosen lest element
:0->L1(L //Remove the stones from the chosen list element
:While S //Distribution loop ends when S = 0
:L+(L<14)-13(L=14->L //Select the next list element. If The current List element is 14, the next is 1 (loops around)
:1+L1(L->L1(L //These two commands add one to the list element house (determined by L), and take one away from the supply (S)
:S-1->S
:End //End Distribution loop, check S
:seq(L1(M),M,1,6 //take Player 2's Houses list from L1
:If not(max(Ans // If none of player 2's Houses have stones-
:2->W //then store 2 to W, Game will end.
:seq(L1(M),M,8,13 //take Player 1's Houses from L1
:If not(max(Ans //If none of player 1's Houses have stones-
:1->W //then store 1 to W, Game will end.
:End // End main loop, check W
:Clrhome // clear screen
:SetupEditor
:"CONGRATS_PLAYER"+sub("12",W,1 //display winner
```

Vars used:

- L1 - list of number of stones in each house
- R - Input row number from which L is derived (can be equal to any #1-6)
- P - Player 1 or 2
- L - Chosen List element (house) to empty - equals: R if P+2 and equals: 14-R if P=1
- W - Win or continue playing and for which player if win. Can equal 0,1, or 2, if 1 or 2, game ends
- S - number of stones left to distribute during distribution routine.
- A - a counting var used in For( loops.

List 1 schematic in relation to position of list elements on the screen.