// Audrey Shi
// ACSL Contest
#3
// Senior
Division
// Montgomery
Blair High School #2070
import
java.util.Scanner;
public class
Mancala {
private static int[] board = new int[14];
public static void main(String[] args) {
System.out.println("Welcome to
Audrey's ACSL Mancala program.");
System.out.println();
for (int i = 1; i <= 12; i++)
board[i] = 4;
board[0] = 0;
board[13] = 0;
getInput();
System.out.println();
System.out.println("Thank you
for using Audrey's ACSL Mancala program!");
}
public static void getInput() {
Scanner sc = new Scanner(System.in);
for (int i = 0; i <= 4; i++) {
System.out.println("Input
the starting bowl number and the bowl number whose count you want to print:
");
String input = sc.nextLine();
String startStr =
input.substring(0, input.indexOf(","));
int start =
Integer.parseInt(startStr);
String print =
input.substring(input.indexOf(",") + 2);
traverseBoard(i, start);
print(print);
}
}
public static void traverseBoard(int i,
int start) {
boolean a = false;
if (i % 2 == 0)
a = true;
else
a = false;
boolean end = false;
int counter = start;
int hand = board[counter];
boolean breakTraverse = false;
if (hand == 0)
breakTraverse = true;
board[counter] = 0;
if (counter == 6 && a ==
true)
counter = 0;
else if (counter == 0)
counter = 7;
else if (counter == 12 && a
== false)
counter = 13;
else if (counter == 13)
counter = 1;
else if (counter == 12)
counter = 1;
else
counter++;
traverse:
while (end == false && hand
!= 0) {
if (breakTraverse == true)
break traverse;
board[counter]++;
hand--;
if (hand == 0) {
if (counter == 0 ||
counter == 13 || board[counter] == 1 || board[counter] == 4) {
end = true;
break traverse;
}
else {
hand =
board[counter];
board[counter] =
0;
}
}
if (counter == 6 && a
== true)
counter = 0;
else if (counter == 0)
counter = 7;
else if (counter == 12
&& a == false)
counter = 13;
else if (counter == 13)
counter = 1;
else if (counter == 12)
counter = 1;
else
counter++;
}
}
public static void print(String print) {
try {
int printNum =
Integer.parseInt(print);
System.out.println(board[printNum]);
} catch (NumberFormatException e){
if
(print.equals("A")) {
int printNum = 0;
System.out.println(board[printNum]);
}
else if
(print.equals("B")) {
int printNum = 13;
System.out.println(board[printNum]);
}
}
}
}