NINE MEN'S MORRIS JAVA CODE

126
//author AMAL SYIHAN BIN ABDULLAH import java.util.*; public class Play { public static void main (String [] args){ int selection; Scanner s = new Scanner(System.in); System.out.println("P1 vs P2 = 1"); System.out.println("P1 vs COM = 2"); selection = s.nextInt(); if (selection == 1){ PlayHH p = new PlayHH("W","B"); p.Display(); System.out.println(); p.play1(); p.play2(); } else if(selection == 2) { PlayHC p = new PlayHC("W","B"); p.Display(); System.out.println(); p.play3(); p.play4(); }

description

CONTAINS JAVA CODES OF HUMAN VS HUMAN AND HUMAN VS COMPUTER. CONTAINS A FEW BUGS

Transcript of NINE MEN'S MORRIS JAVA CODE

Page 1: NINE MEN'S MORRIS JAVA CODE

//author AMAL SYIHAN BIN ABDULLAH

import java.util.*;

public class Play {

public static void main (String [] args){

int selection;

Scanner s = new Scanner(System.in);

System.out.println("P1 vs P2 = 1");

System.out.println("P1 vs COM = 2");

selection = s.nextInt();

if (selection == 1){

PlayHH p = new PlayHH("W","B");

p.Display();

System.out.println();

p.play1();

p.play2();

}

else if(selection == 2)

{

PlayHC p = new PlayHC("W","B");

p.Display();

System.out.println();

p.play3();

p.play4();

}

}

}

Page 2: NINE MEN'S MORRIS JAVA CODE

////////////////////////////////////////////////////////////////////////////////////////////////////////

///HUMAN VS HUMAN CLASS

import java.util.*;

public class PlayHH {

private int countB=0,countW=0;

protected String P1,P2,onMove;

protected String [] location;

Scanner sc = new Scanner(System.in);

int A1=0,D1=1,G1=2,B2=3,D2=4,F2=5,C3=6,D3=7,E3=8,A4=9,B4=10,C4=11,E4=12,F4=13,G4=14,C5=15,D5=16,E5=17,B6=18,D6=19,F6=20,A7=21,D7=22,G7=23;

int buttonW = 9,buttonB = 9;

int BWoutside = 9,BBoutside = 9;

boolean canPut = false,canTake=false,adj=false;

private ArrayList<Integer> MLoc;

protected int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0;

protected int a1=0,b1=0,c1=0,d1=0,e1=0,f1=0,g1=0,h1=0,i1=0,j1=0,k1=0,l1=0,m1=0,n1=0,o1=0,p1=0,q1=0,r1=0,s1=0,t1=0,u1=0,v1=0,w1=0,x1=0,y1=0,z1=0;

protected int a2=0,b2=0,c2=0,d2=0;

//private boolean isMill = false;

public PlayHH(String p1,String p2){

MLoc = new ArrayList<Integer>();

P1 = p1;

Page 3: NINE MEN'S MORRIS JAVA CODE

P2 = p2;

location = new String[24];

for (int i = 0; i < 24; i++) {

location[i]="0";

}

onMove = "W";

}

public void play1(){

// int loop1=0;

do{

System.out.println("[Current Score]");

System.out.println("White total = "+buttonW);

System.out.println("White left outside board = "+BWoutside);

System.out.println("Black total = "+buttonB);

System.out.println("Black left outside board = "+BBoutside);

String input="";

do{

System.out.println(onMove+" to Move");

System.out.println("insert your selection");

input = sc.next().toUpperCase();

canPut(input);

}while(canPut!=true);

put(input);

Page 4: NINE MEN'S MORRIS JAVA CODE

Display();

System.out.println();

if(isMill()==true){

if(onMove.equals("W")){

BBoutside--;

buttonB--;

}

else if(onMove.equals("B")){

BWoutside--;

buttonW--;

}

System.out.println("MILL!");

Milling();

Display();

System.out.println();

//a++;

}

if(onMove.equals("W")){

BWoutside--;

//buttonW--;

onMove = "B";

}

else if(onMove.equals("B")){

BBoutside--;

Page 5: NINE MEN'S MORRIS JAVA CODE

//buttonB--;

onMove = "W";

}

// loop1++;

}while(BBoutside>0);

System.out.println("end play 1");

}

public void play2(){

a=0;b=0;c=0;d=0;e=0;f=0;g=0;h=0;i=0;j=0;k=0;l=0;m=0;n=0;o=0;p=0;q=0;r=0;s=0;t=0;u=0;v=0;w=0;x=0;y=0;z=0;

a1=0;b1=0;c1=0;d1=0;e1=0;f1=0;g1=0;h1=0;i1=0;j1=0;k1=0;l1=0;m1=0;n1=0;o1=0;p1=0;q1=0;r1=0;s1=0;t1=0;u1=0;v1=0;w1=0;x1=0;y1=0;z1=0;

a2=0;b2=0;c2=0;d2=0;

String input1;

String input2;

System.out.println("All button is on the board.\nYou need to select one button and move to another location.");

do{

do{

System.out.println(onMove+" on move");

System.out.println("Select which button to move");

input1 = sc.next().toUpperCase();

canTake(input1);

}while(canTake!=true);

do {do{

System.out.println("Select your destination");

Page 6: NINE MEN'S MORRIS JAVA CODE

input2 = sc.next().toUpperCase();

adjacent(input1,input2);

} while(!adj);

canPut(input2);

} while (!canPut);

put(input2);

clear(input1);

Display();

System.out.println();

if(isMill()==true){

if(onMove.equals("W")){

buttonB--;

}

else if(onMove.equals("B")){

buttonW--;

}

System.out.println("MILL!");

Milling();

Display();

System.out.println();

//a++;

}

Page 7: NINE MEN'S MORRIS JAVA CODE

if(onMove.equals("W")){

BWoutside--;

//buttonW--;

onMove = "B";

}

else if(onMove.equals("B")){

BBoutside--;

//buttonB--;

onMove = "W";

}

}while(checkWin());

}

public void clear(String input){

if(input.equals("A1")){

location[A1]="0";

}

if(input.equals("D1")){

location[D1]="0";

}

if(input.equals("G1")){

location[G1]="0";

}

if(input.equals("B2")){

Page 8: NINE MEN'S MORRIS JAVA CODE

location[B2]="0";

}

if(input.equals("D2")){

location[D2]="0";

}

if(input.equals("F2")){

location[F2]="0";

}

if(input.equals("C3")){

location[C3]="0";

}

if(input.equals("D3")){

location[D3]="0";

}

if(input.equals("E3")){

location[E3]="0";

}

if(input.equals("A4")){

location[A4]="0";

}

if(input.equals("B4")){

location[B4]="0";

}

if(input.equals("C4")){

location[C4]="0";

}

if(input.equals("E4")){

Page 9: NINE MEN'S MORRIS JAVA CODE

location[E4]="0";

}

if(input.equals("F4")){

location[F4]="0";

}

if(input.equals("G4")){

location[G4]="0";

}

if(input.equals("C5")){

location[C5]="0";

}

if(input.equals("D5")){

location[D5]="0";

}

if(input.equals("E5")){

location[E5]="0";

}

if(input.equals("B6")){

location[B6]="0";

}

if(input.equals("D6")){

location[D6]="0";

}

if(input.equals("F6")){

location[F6]="0";

}

if(input.equals("A7")){

Page 10: NINE MEN'S MORRIS JAVA CODE

location[A7]="0";

}

if(input.equals("D7")){

location[D7]="0";

}

if(input.equals("G7")){

location[G7]="0";

}

}

public void put(String input){

if(input.equals("A1")){

location[A1]=onMove;

}

if(input.equals("D1")){

location[D1]=onMove;

}

if(input.equals("G1")){

location[G1]=onMove;

}

if(input.equals("B2")){

location[B2]=onMove;

}

if(input.equals("D2")){

location[D2]=onMove;

}

if(input.equals("F2")){

Page 11: NINE MEN'S MORRIS JAVA CODE

location[F2]=onMove;

}

if(input.equals("C3")){

location[C3]=onMove;

}

if(input.equals("D3")){

location[D3]=onMove;

}

if(input.equals("E3")){

location[E3]=onMove;

}

if(input.equals("A4")){

location[A4]=onMove;

}

if(input.equals("B4")){

location[B4]=onMove;

}

if(input.equals("C4")){

location[C4]=onMove;

}

if(input.equals("E4")){

location[E4]=onMove;

}

if(input.equals("F4")){

location[F4]=onMove;

}

if(input.equals("G4")){

Page 12: NINE MEN'S MORRIS JAVA CODE

location[G4]=onMove;

}

if(input.equals("C5")){

location[C5]=onMove;

}

if(input.equals("D5")){

location[D5]=onMove;

}

if(input.equals("E5")){

location[E5]=onMove;

}

if(input.equals("B6")){

location[B6]=onMove;

}

if(input.equals("D6")){

location[D6]=onMove;

}

if(input.equals("F6")){

location[F6]=onMove;

}

if(input.equals("A7")){

location[A7]=onMove;

}

if(input.equals("D7")){

location[D7]=onMove;

}

if(input.equals("G7")){

Page 13: NINE MEN'S MORRIS JAVA CODE

location[G7]=onMove;

}

}

public boolean checkWin(){

if(buttonB<3){

System.out.println("White is win");

return false;

}

else if(buttonW<3){

System.out.println("Black is win");

return false;

}

else return true;

}

public boolean isMill(){

if(location[0].equals("W")&&location[1].equals("W")&&location[2].equals("W")&&a==0){

a++;

return true;

}

if(location[3].equals("W")&&location[4].equals("W")&&location[5].equals("W")&&b==0){

b++;

return true;

Page 14: NINE MEN'S MORRIS JAVA CODE

}

if(location[6].equals("W")&&location[7].equals("W")&&location[8].equals("W")&&c==0){

c++;

return true;

}

if(location[9].equals("W")&&location[10].equals("W")&&location[11].equals("W")&&d==0){

d++;

return true;

}

if(location[12].equals("W")&&location[13].equals("W")&&location[14].equals("W")&&e==0){

e++;

return true;

}

if(location[22].equals("B")&&location[19].equals("B")&&location[16].equals("B")&&f==0) {

f++;

return true;

}

if(location[15].equals("B")&&location[11].equals("B")&&location[6].equals("B")&&g==0){

g++;

return true;

}

Page 15: NINE MEN'S MORRIS JAVA CODE

if(location[18].equals("B")&&location[10].equals("B")&&location[3].equals("B")&&h==0) {

h++;

return true;

}

if(location[21].equals("B")&&location[9].equals("B")&&location[0].equals("B")&&i==0){

i++;

return true;

}

if(location[21].equals("B")&&location[22].equals("B")&&location[23].equals("B")&&j==0){

j++;

return true;

}

if(location[18].equals("B")&&location[19].equals("B")&&location[20].equals("B")&&k==0){

k++;

return true;

}

if(location[15].equals("B")&&location[16].equals("B")&&location[17].equals("B")&&l==0) {

l++;

return true;

}

Page 16: NINE MEN'S MORRIS JAVA CODE

if(location[12].equals("B")&&location[13].equals("B")&&location[14].equals("B")&&m==0){

m++;

return true;

}

if(location[9].equals("B")&&location[10].equals("B")&&location[11].equals("B")&&n==0){

n++;

return true;

}

if(location[6].equals("B")&&location[7].equals("B")&&location[8].equals("B")&&o==0) {

o++;

return true;

}

if(location[3].equals("B")&&location[4].equals("B")&&location[5].equals("B")&&p==0){

p++;

return true;

}

if(location[0].equals("B")&&location[1].equals("B")&&location[2].equals("B")&&q==0){

q++;

return true;

}

Page 17: NINE MEN'S MORRIS JAVA CODE

if(location[23].equals("W")&&location[14].equals("W")&&location[2].equals("W")&&r==0){

r++;

return true;

}

if(location[20].equals("W")&&location[13].equals("W")&&location[5].equals("W")&&s==0){

s++;

return true;

}

if(location[17].equals("W")&&location[12].equals("W")&&location[8].equals("W")&&t==0){

t++;

return true;

}

if(location[7].equals("W")&&location[4].equals("W")&&location[1].equals("W")&&u==0){

u++;

return true;

}

if(location[22].equals("W")&&location[19].equals("W")&&location[16].equals("W")&&v==0){

v++;

return true;

}

Page 18: NINE MEN'S MORRIS JAVA CODE

if(location[15].equals("W")&&location[11].equals("W")&&location[6].equals("W")&&w==0){

w++;

return true;

}

if(location[18].equals("W")&&location[10].equals("W")&&location[3].equals("W")&x==0){

x++;

return true;

}

if(location[21].equals("W")&&location[9].equals("W")&&location[0].equals("W")&&y==0){

y++;

return true;

}

if(location[21].equals("W")&&location[22].equals("W")&&location[23].equals("W")&&z==0){

z++;

return true;

}

if(location[18].equals("W")&&location[19].equals("W")&&location[20].equals("W")&&a1==0){

a1++;

return true;

}

Page 19: NINE MEN'S MORRIS JAVA CODE

if(location[15].equals("W")&&location[16].equals("W")&&location[17].equals("W")&&b1==0){

b1++;

return true;

}

if(location[7].equals("B")&&location[4].equals("B")&&location[1].equals("B")&&c1==0){

c1++;

return true;

}

if(location[17].equals("B")&&location[12].equals("B")&&location[8].equals("B")&&d1==0){

d1++;

return true;

}

if(location[20].equals("B")&&location[13].equals("B")&&location[5].equals("B")&&e1==0){

e1++;

return true;

}

if(location[23].equals("B")&&location[14].equals("B")&&location[2].equals("B")&&f1==0){

f1++;

return true;

}

if(location[6].equals("W")&&location[7].equals("W")&&location[

Page 20: NINE MEN'S MORRIS JAVA CODE

8].equals("W")&&location[11].equals("W")&&location[15].equals("W")&&g1==0){

g1++;

return true;

}

if(location[6].equals("W") && location[11].equals("W") && location[15].equals("W") && location[16].equals("W") && location[16].equals("W")&&h1==0){

h1++;

return true;

}

if(location[15].equals("W")&&location[16].equals("W")&&location[17].equals("W")&&location[12].equals("W")&&location[8].equals("W")&&i1==0){

i1++;

return true;

}

if(location[6].equals("W")&&location[7].equals("W")&&location[8].equals("W")&&location[12].equals("W")&&location[17].equals("W")&&j1==0){

j1++;

return true;

}

if(location[0].equals("W")&&location[9].equals("W")&&location[21].equals("W")&&location[1].equals("W")&&location[2].equals("W")&&k1==0){

k1++;

return true;

}

Page 21: NINE MEN'S MORRIS JAVA CODE

if(location[21].equals("W")&&location[22].equals("W")&&location[23].equals("W")&&location[14].equals("W")&&location[2].equals("W")&&l1==0){

l1++;

return true;

}

if(location[21].equals("W")&&location[22].equals("W")&&location[23].equals("W")&&location[9].equals("W")&&location[0].equals("W")&&m1==0){

m1++;

return true;

}

if(location[0].equals("W")&&location[1].equals("W")&&location[2].equals("W")&&location[14].equals("W")&&location[23].equals("W")&&n1==0){

n1++;

return true;

}

if(location[3].equals("W")&&location[4].equals("W")&&location[5].equals("W")&&location[10].equals("W")&&location[18].equals("W")&&o1==0){

o1++;

return true;

}

if(location[3].equals("W")&&location[10].equals("W")&&location[18].equals("W")&&location[20].equals("W")&&location[19].equals("W")&&p1==0){

p1++;

Page 22: NINE MEN'S MORRIS JAVA CODE

return true;

}

if(location[18].equals("W")&&location[19].equals("W")&&location[20].equals("W")&&location[13].equals("W")&&location[5].equals("W")&&q1==0){

q1++;

return true;

}

if(location[3].equals("W")&&location[4].equals("W")&&location[5].equals("W")&&location[13].equals("W")&&location[20].equals("W")&&r1==0){

r1++;

return true;

}

if(location[6].equals("B")&&location[7].equals("B")&&location[8].equals("B")&&location[11].equals("B")&&location[15].equals("B")&&s1==0){

s1++;

return true;

}

if(location[6].equals("B") && location[11].equals("B") && location[15].equals("B") && location[16].equals("B") && location[16].equals("B")&&t1==0){

t1++;

return true;

}

if(location[15].equals("B")&&location[16].equals("B")&&location[17].equals("B")&&location[12].equals("B")&&location[8].equals("B")&&u1==0){

Page 23: NINE MEN'S MORRIS JAVA CODE

u1++;

return true;

}

if(location[6].equals("B")&&location[7].equals("B")&&location[8].equals("B")&&location[12].equals("B")&&location[17].equals("B")&&v1==0){

v1++;

return true;

}

if(location[0].equals("B")&&location[9].equals("B")&&location[21].equals("B")&&location[1].equals("B")&&location[2].equals("B")&&w1==0){

w1++;

return true;

}

if(location[21].equals("B")&&location[22].equals("B")&&location[23].equals("B")&&location[14].equals("B")&&location[2].equals("B")&&x1==0){

x1++;

return true;

}

if(location[21].equals("B")&&location[22].equals("B")&&location[23].equals("B")&&location[9].equals("B")&&location[0].equals("B")&&y1==0){

y1++;

return true;

}

Page 24: NINE MEN'S MORRIS JAVA CODE

if(location[0].equals("B")&&location[1].equals("B")&&location[2].equals("B")&&location[14].equals("B")&&location[23].equals("B")&&z1==0){

z1++;

return true;

}

if(location[3].equals("B")&&location[4].equals("B")&&location[5].equals("B")&&location[10].equals("B")&&location[18].equals("B")&&a2==0){

a2++;

return true;

}

if(location[3].equals("B")&&location[10].equals("B")&&location[18].equals("B")&&location[20].equals("B")&&location[19].equals("B")&&b2==0){

b2++;

return true;

}

if(location[18].equals("B")&&location[19].equals("B")&&location[20].equals("B")&&location[13].equals("B")&&location[5].equals("B")&&c2==0){

c2++;

return true;

}

if(location[3].equals("B")&&location[4].equals("B")&&location[5].equals("B")&&location[13].equals("B")&&location[20].equals("B")&&d2==0){

d2++;

Page 25: NINE MEN'S MORRIS JAVA CODE

return true;

}

else return false;

}

public void canTake(String s){

if(onMove.equals("W")){

if(s.equals("A1")){

if(location[A1].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D1")){

if(location[D1].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("G1")){

if(location[G1].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("B2")){

Page 26: NINE MEN'S MORRIS JAVA CODE

if(location[B2].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D2")){

if(location[D2].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("F2")){

if(location[F2].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("C3")){

if(location[C3].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D3")){

if(location[D3].equals("W"))

canTake=true;

else

Page 27: NINE MEN'S MORRIS JAVA CODE

canTake=false;

}

if(s.equals("E3")){

if(location[E3].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("A4")){

if(location[A4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("B4")){

if(location[B4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("C4")){

if(location[C4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("E4")){

Page 28: NINE MEN'S MORRIS JAVA CODE

if(location[E4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("F4")){

if(location[F4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("G4")){

if(location[G4].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("C5")){

if(location[C5].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D5")){

if(location[D5].equals("W"))

canTake=true;

else

Page 29: NINE MEN'S MORRIS JAVA CODE

canTake=false;

}

if(s.equals("E5")){

if(location[E5].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("B6")){

if(location[B6].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D6")){

if(location[D6].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("F6")){

if(location[F6].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("A7")){

Page 30: NINE MEN'S MORRIS JAVA CODE

if(location[A7].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("D7")){

if(location[D7].equals("W"))

canTake=true;

else

canTake=false;

}

if(s.equals("G7")){

if(location[G7].equals("W"))

canTake=true;

else

canTake=false;

}

}

else if(onMove.equals("B"))

{

if(s.equals("A1")){

if(location[A1].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D1")){

Page 31: NINE MEN'S MORRIS JAVA CODE

if(location[D1].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("G1")){

if(location[G1].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("B2")){

if(location[B2].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D2")){

if(location[D2].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("F2")){

if(location[F2].equals("B"))

canTake=true;

else

Page 32: NINE MEN'S MORRIS JAVA CODE

canTake=false;

}

if(s.equals("C3")){

if(location[C3].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D3")){

if(location[D3].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("E3")){

if(location[E3].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("A4")){

if(location[A4].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("B4")){

Page 33: NINE MEN'S MORRIS JAVA CODE

if(location[B4].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("C4")){

if(location[C4].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("E4")){

if(location[E4].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("F4")){

if(location[F4].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("G4")){

if(location[G4].equals("B"))

canTake=true;

else

Page 34: NINE MEN'S MORRIS JAVA CODE

canTake=false;

}

if(s.equals("C5")){

if(location[C5].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D5")){

if(location[D5].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("E5")){

if(location[E5].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("B6")){

if(location[B6].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D6")){

Page 35: NINE MEN'S MORRIS JAVA CODE

if(location[D6].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("F6")){

if(location[F6].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("A7")){

if(location[A7].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("D7")){

if(location[D7].equals("B"))

canTake=true;

else

canTake=false;

}

if(s.equals("G7")){

if(location[G7].equals("B"))

canTake=true;

else

Page 36: NINE MEN'S MORRIS JAVA CODE

canTake=false;

}

}

}

public void canPut(String s){

//if(!sc.equals("A1") || !sc.equals("D1") || !sc.equals("G1") || !sc.equals("B2") || !sc.equals("D2") || !sc.equals("F2")

// || !sc.equals("C3") || !sc.equals("D3") || !sc.equals("E3") || !sc.equals("A4") || !sc.equals("B4") || !sc.equals("C4")

//|| !sc.equals("E4") || !sc.equals("F4") || !sc.equals("G4") || !sc.equals("C5") || !sc.equals("D5") || !sc.equals("E5")

//|| !sc.equals("B6") || !sc.equals("D6") || !sc.equals("F6") || !sc.equals("A7") || !sc.equals("D7") || !sc.equals("G7")){

//canPut=false;

//}

//else{

if(s.equals("A1")){

if(location[A1].equals("0"))

canPut=true;

else

canPut=false;

}

Page 37: NINE MEN'S MORRIS JAVA CODE

if(s.equals("D1")){

if(location[D1].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("G1")){

if(location[G1].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("B2")){

if(location[B2].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("D2")){

if(location[D2].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("F2")){

if(location[F2].equals("0"))

canPut=true;

Page 38: NINE MEN'S MORRIS JAVA CODE

else

canPut=false;

}

if(s.equals("C3")){

if(location[C3].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("D3")){

if(location[D3].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("E3")){

if(location[E3].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("A4")){

if(location[A4].equals("0"))

canPut=true;

else

canPut=false;

}

Page 39: NINE MEN'S MORRIS JAVA CODE

if(s.equals("B4")){

if(location[B4].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("C4")){

if(location[C4].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("E4")){

if(location[E4].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("F4")){

if(location[F4].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("G4")){

if(location[G4].equals("0"))

canPut=true;

Page 40: NINE MEN'S MORRIS JAVA CODE

else

canPut=false;

}

if(s.equals("C5")){

if(location[C5].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("D5")){

if(location[D5].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("E5")){

if(location[E5].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("B6")){

if(location[B6].equals("0"))

canPut=true;

else

canPut=false;

}

Page 41: NINE MEN'S MORRIS JAVA CODE

if(s.equals("D6")){

if(location[D6].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("F6")){

if(location[F6].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("A7")){

if(location[A7].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("D7")){

if(location[D7].equals("0"))

canPut=true;

else

canPut=false;

}

if(s.equals("G7")){

if(location[G7].equals("0"))

canPut=true;

Page 42: NINE MEN'S MORRIS JAVA CODE

else

canPut=false;

}

if(onMove.equals("W"))

countW++;

else if (onMove.equals("B"))

countB++;

// }

}

public void adjacent(String s,String s2){

if(s.equals("A1")){

if(s2.equalsIgnoreCase("A4")||s2.equalsIgnoreCase("D1"))

adj=true;

else

adj=false;

}

if(s.equals("D1")){

if(s2.equalsIgnoreCase("A1")||s2.equalsIgnoreCase("D2")||s2.equalsIgnoreCase("G1"))

adj=true;

else

adj=false;

}

Page 43: NINE MEN'S MORRIS JAVA CODE

if(s.equals("G1")){

if(s2.equalsIgnoreCase("D1")||s2.equalsIgnoreCase("G4"))

adj=true;

else

adj=false;

}

if(s.equals("B2")){

if(s2.equalsIgnoreCase("D2")||s2.equalsIgnoreCase("B4"))

adj=true;

else

adj=false;

}

if(s.equals("D2")){

if(s2.equalsIgnoreCase("D1")||s2.equalsIgnoreCase("B2")||s2.equalsIgnoreCase("D3")||s2.equalsIgnoreCase("F2"))

adj=true;

else

adj=false;

}

if(s.equals("F2")){

if(s2.equalsIgnoreCase("D2")||s2.equalsIgnoreCase("F4"))

adj=true;

else

adj=false;

}

Page 44: NINE MEN'S MORRIS JAVA CODE

if(s.equals("C3")){

if(s2.equalsIgnoreCase("D3")||s2.equalsIgnoreCase("C4"))

adj=true;

else

adj=false;

}

if(s.equals("D3")){

if(s2.equalsIgnoreCase("D2")||s2.equalsIgnoreCase("C3")||s2.equalsIgnoreCase("E3"))

adj=true;

else

adj=false;

}

if(s.equals("E3")){

if(s2.equalsIgnoreCase("D3")||s2.equalsIgnoreCase("E4"))

adj=true;

else

adj=false;

}

if(s.equals("A4")){

if(s2.equalsIgnoreCase("A1")||s2.equalsIgnoreCase("B4")||s2.equalsIgnoreCase("A7"))

adj=true;

else

adj=false;

}

if(s.equals("B4")){

Page 45: NINE MEN'S MORRIS JAVA CODE

if(s2.equalsIgnoreCase("A4")||s2.equalsIgnoreCase("C4"))

adj=true;

else

adj=false;

}

if(s.equals("C4")){

if(s2.equalsIgnoreCase("C5")||s2.equalsIgnoreCase("B4")||s2.equalsIgnoreCase("C3"))

adj=true;

else

adj=false;

}

if(s.equals("E4")){

if(s2.equalsIgnoreCase("E5")||s2.equalsIgnoreCase("F4")||s2.equalsIgnoreCase("E3"))

adj=true;

else

adj=false;

}

if(s.equals("F4")){

if(s2.equalsIgnoreCase("F2")||s2.equalsIgnoreCase("E4")||s2.equalsIgnoreCase("F6")||s2.equalsIgnoreCase("G4"))

adj=true;

else

adj=false;

}

if(s.equals("G4")){

Page 46: NINE MEN'S MORRIS JAVA CODE

if(s2.equalsIgnoreCase("G7")||s2.equalsIgnoreCase("F4")||s2.equalsIgnoreCase("G1"))

adj=true;

else

adj=false;

}

if(s.equals("C5")){

if(s2.equalsIgnoreCase("D5")||s2.equalsIgnoreCase("C4"))

adj=true;

else

adj=false;

}

if(s.equals("D5")){

if(s2.equalsIgnoreCase("C5")||s2.equalsIgnoreCase("E5")||s2.equalsIgnoreCase("D6"))

adj=true;

else

adj=false;

}

if(s.equals("E5")){

if(s2.equalsIgnoreCase("D5")||s2.equalsIgnoreCase("E4"))

adj=true;

else

adj=false;

}

if(s.equals("B6")){

Page 47: NINE MEN'S MORRIS JAVA CODE

if(s2.equalsIgnoreCase("D6")||s2.equalsIgnoreCase("B4"))

adj=true;

else

adj=false;

}

if(s.equals("D6")){

if(s2.equalsIgnoreCase("D7")||s2.equalsIgnoreCase("F6")||s2.equalsIgnoreCase("D5")||s2.equalsIgnoreCase("B6"))

adj=true;

else

adj=false;

}

if(s.equals("F6")){

if(s2.equalsIgnoreCase("D6")||s2.equalsIgnoreCase("F4"))

adj=true;

else

adj=false;

}

if(s.equals("A7")){

if(s2.equalsIgnoreCase("D7")||s2.equalsIgnoreCase("A4"))

adj=true;

else

adj=false;

}

if(s.equals("D7")){

Page 48: NINE MEN'S MORRIS JAVA CODE

if(s2.equalsIgnoreCase("A7")||s2.equalsIgnoreCase("G7")||s2.equalsIgnoreCase("D6"))

adj=true;

else

adj=false;

}

if(s.equals("G7")){

if(s2.equalsIgnoreCase("D7")||s2.equalsIgnoreCase("G4"))

adj=true;

else

adj=false;

}

}

public void Milling(){

boolean doMill = false;

do{

System.out.println("Enter location to delete");

String input = sc.next().toUpperCase();

if(input.equals("A1")){

if(!location[A1].equals("0")&&!location[A1].equals(onMove)){

doMill = true;

Page 49: NINE MEN'S MORRIS JAVA CODE

location[A1]="0";

a--;i--;q--;y--;k1--;n1--;w1--;y1--;z1--;

if(a<0)

a=0;

if(i<0)

i=0;

if(q<0)

q=0;

if(y<0)

y=0;

if(k1<0)

k1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(y1<0)

y1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D1")){

Page 50: NINE MEN'S MORRIS JAVA CODE

if(!location[D1].equals("0")&&!location[D1].equals(onMove)){

doMill = true;

location[D1]="0";

a--;q--;u--;c1--;k1--;n1--;w1--;z1--;

if(a<0)

a=0;

if(q<0)

q=0;

if(u<0)

u=0;

if(c1<0)

c1=0;

if(k1<0)

k1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

Page 51: NINE MEN'S MORRIS JAVA CODE

if(input.equals("G1")){

if(!location[G1].equals("0")&&!location[G1].equals(onMove)){

doMill = true;

location[G1]="0";

a--;q--;r--;f1--;k1--;l1--;n1--;w1--;x1--;z1--;

if(a<0)

a=0;

if(q<0)

q=0;

if(r<0)

r=0;

if(f1<0)

f1=0;

if(k1<0)

k1=0;

if(l1<0)

l1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(x1<0)

x1=0;

if(z1<0)

z1=0;

}

Page 52: NINE MEN'S MORRIS JAVA CODE

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B2")){

if(!location[B2].equals("0")&&!location[B2].equals(onMove)){

doMill = true;

location[B2]="0";

b--;h--;p--;x--;o1--;p1--;r1--;a2--;b2--;d2--;

if(b<0)

b=0;

if(h<0)

h=0;

if(p<0)

p=0;

if(x<0)

x=0;

if(o1<0)

o1=0;

if(p1<0)

p1=0;

if(r1<0)

r1=0;

if(a2<0)

a2=0;

Page 53: NINE MEN'S MORRIS JAVA CODE

if(b2<0)

b2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D2")){

if(!location[D2].equals("0")&&!location[D2].equals(onMove)){

doMill = true;

location[D2]="0";

b--;p--;u--;c1--;o1--;r1--;a2--;d2--;

if(b<0)

b=0;

if(p<0)

p=0;

if(u<0)

u=0;

if(c1<0)

c1=0;

if(o1<0)

o1=0;

if(r1<0)

Page 54: NINE MEN'S MORRIS JAVA CODE

r1=0;

if(a2<0)

a2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("F2")){

if(!location[F2].equals("0")&&!location[F2].equals(onMove)){

doMill = true;

location[F2]="0";

b--;p--;s--;e1--;o1--;q1--;r1--;a2--;c2--;d2--;

if(b<0)

b=0;

if(p<0)

p=0;

if(s<0)

s=0;

if(e1<0)

e1=0;

Page 55: NINE MEN'S MORRIS JAVA CODE

if(o1<0)

o1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(a2<0)

a2=0;

if(c2<0)

c2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("C3")){

if(!location[C3].equals("0")&&!location[C3].equals(onMove)){

doMill = true;

location[C3]="0";

c--;g--;o--;w--;g1--;h1--;j1--;s1--;t1--;v1--;

if(c<0)

c=0;

if(g<0)

Page 56: NINE MEN'S MORRIS JAVA CODE

g=0;

if(o<0)

o=0;

if(w<0)

w=0;

if(g1<0)

g1=0;

if(h1<0)

h1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D3")){

if(!location[D3].equals("0")&&!location[D3].equals(onMove)){

doMill = true;

Page 57: NINE MEN'S MORRIS JAVA CODE

location[D3]="0";

c--;o--;u--;c1--;g1--;j1--;s1--;v1--;

if(c<0)

c=0;

if(o<0)

o=0;

if(u<0)

u=0;

if(c1<0)

c1=0;

if(g1<0)

g1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E3")){

if(!location[E3].equals("0")&&!location[E3].equals(onMove)){

Page 58: NINE MEN'S MORRIS JAVA CODE

doMill = true;

location[E3]="0";

c--;o--;t--;d1--;g1--;i1--;j1--;s1--;u1--;v1--;

if(c<0)

c=0;

if(o<0)

o=0;

if(t<0)

t=0;

if(d1<0)

d1=0;

if(g1<0)

g1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(u1<0)

u1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

Page 59: NINE MEN'S MORRIS JAVA CODE

doMill=false;

}

}

if(input.equals("A4")){

if(!location[A4].equals("0")&&!location[A4].equals(onMove)){

doMill = true;

location[A4]="0";

d--;i--;n--;y--;k1--;m1--;w1--;y1--;

if(d<0)

d=0;

if(i<0)

i=0;

if(n<0)

n=0;

if(y<0)

y=0;

if(k1<0)

k1=0;

if(m1<0)

m1=0;

if(w1<0)

w1=0;

if(y1<0)

y1=0;

}

else{

Page 60: NINE MEN'S MORRIS JAVA CODE

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B4")){

if(!location[B4].equals("0")&&!location[B4].equals(onMove)){

doMill = true;

location[B4]="0";

d--;h--;n--;x--;o1--;p1--;a2--;b2--;

if(d<0)

d=0;

if(h<0)

h=0;

if(n<0)

n=0;

if(x<0)

x=0;

if(o1<0)

o1=0;

if(p1<0)

p1=0;

if(a2<0)

a2=0;

if(b2<0)

b2=0;

}

Page 61: NINE MEN'S MORRIS JAVA CODE

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("C4")){

if(!location[C4].equals("0")&&!location[C4].equals(onMove)){

doMill = true;

location[C4]="0";

d--;g--;n--;w--;g1--;h1--;s1--;t1--;

if(d<0)

d=0;

if(g<0)

g=0;

if(n<0)

n=0;

if(w<0)

w=0;

if(g1<0)

g1=0;

if(h1<0)

h1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

Page 62: NINE MEN'S MORRIS JAVA CODE

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E4")){

if(!location[E4].equals("0")&&!location[E4].equals(onMove)){

doMill = true;

location[E4]="0";

e--;m--;t--;d1--;i1--;j1--;u1--;v1--;

if(e<0)

e=0;

if(m<0)

m=0;

if(t<0)

t=0;

if(d1<0)

d1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(u1<0)

u1=0;

if(v1<0)

Page 63: NINE MEN'S MORRIS JAVA CODE

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("F4")){

if(!location[F4].equals("0")&&!location[F4].equals(onMove)){

doMill = true;

location[F4]="0";

e--;m--;s--;e1--;q1--;r1--;c2--;d2--;

if(e<0)

e=0;

if(m<0)

m=0;

if(s<0)

s=0;

if(e1<0)

e1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(c2<0)

c2=0;

Page 64: NINE MEN'S MORRIS JAVA CODE

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("G4")){

if(!location[G4].equals("0")&&!location[G4].equals(onMove)){

doMill = true;

location[G4]="0";

e--;m--;r--;f1--;l1--;n1--;x1--;z1--;

if(e<0)

e=0;

if(m<0)

m=0;

if(r<0)

r=0;

if(f1<0)

f1=0;

if(l1<0)

l1=0;

if(n1<0)

n1=0;

if(x1<0)

Page 65: NINE MEN'S MORRIS JAVA CODE

x1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("C5")){

if(!location[C5].equals("0")&&!location[C5].equals(onMove)){

doMill = true;

location[C5]="0";

g--;l--;w--;b1--;g1--;h1--;i1--;s1--;t1--;u1--;

if(g<0)

g=0;

if(l<0)

l=0;

if(w<0)

w=0;

if(b1<0)

b1=0;

if(g1<0)

g1=0;

if(h1<0)

Page 66: NINE MEN'S MORRIS JAVA CODE

h1=0;

if(i1<0)

i1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

if(u1<0)

u1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D5")){

if(!location[D5].equals("0")&&!location[D5].equals(onMove)){

doMill = true;

location[D5]="0";

f--;l--;v--;b1--;h1--;i1--;t1--;u1--;

if(f<0)

f=0;

if(l<0)

l=0;

if(v<0)

v=0;

Page 67: NINE MEN'S MORRIS JAVA CODE

if(b1<0)

b1=0;

if(h1<0)

h1=0;

if(i1<0)

i1=0;

if(t1<0)

t1=0;

if(u1<0)

u1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E5")){

if(!location[E5].equals("0")&&!location[E5].equals(onMove)){

doMill = true;

location[E5]="0";

l--;t--;b1--;d1--;i1--;j1--;u1--;v1--;

if(l<0)

l=0;

if(t<0)

t=0;

if(b1<0)

Page 68: NINE MEN'S MORRIS JAVA CODE

b1=0;

if(d1<0)

d1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(u1<0)

u1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B6")){

if(!location[B6].equals("0")&&!location[B6].equals(onMove)){

doMill = true;

location[B6]="0";

h--;k--;x--;a1--;o1--;p1--;q1--;a2--;b2--;c2--;

if(h<0)

h=0;

if(k<0)

Page 69: NINE MEN'S MORRIS JAVA CODE

k=0;

if(x<0)

x=0;

if(a1<0)

a1=0;

if(o1<0)

o1=0;

if(p1<0)

p1=0;

if(q1<0)

q1=0;

if(a2<0)

a2=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D6")){

if(!location[D6].equals("0")&&!location[D6].equals(onMove)){

doMill = true;

Page 70: NINE MEN'S MORRIS JAVA CODE

location[D6]="0";

f--;k--;v--;a1--;p1--;q1--;b2--;c2--;

if(f<0)

f=0;

if(k<0)

k=0;

if(v<0)

v=0;

if(a1<0)

a1=0;

if(p1<0)

p1=0;

if(q1<0)

q1=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("F6")){

if(!location[F6].equals("0")&&!location[F6].equals(onMove)){

Page 71: NINE MEN'S MORRIS JAVA CODE

doMill = true;

location[F6]="0";

k--;s--;a1--;e1--;p1--;q1--;r1--;b2--;c2--;d2--;

if(k<0)

k=0;

if(s<0)

s=0;

if(a1<0)

a1=0;

if(e1<0)

e1=0;

if(p1<0)

p1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

Page 72: NINE MEN'S MORRIS JAVA CODE

doMill=false;

}

}

if(input.equals("A7")){

if(!location[A7].equals("0")&&!location[A7].equals(onMove)){

doMill = true;

location[A7]="0";

i--;j--;y--;z--;k1--;l1--;m1--;w1--;x1--;y1--;

if(i<0)

i=0;

if(j<0)

j=0;

if(y<0)

y=0;

if(z<0)

z=0;

if(k1<0)

k1=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(x1<0)

x1=0;

if(y1<0)

y1=0;

}

Page 73: NINE MEN'S MORRIS JAVA CODE

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D7")){

if(!location[D7].equals("0")&&!location[D7].equals(onMove)){

doMill = true;

location[D7]="0";

f--;j--;v--;z--;l1--;m1--;x1--;y1--;

if(f<0)

f=0;

if(j<0)

j=0;

if(v<0)

v=0;

if(z<0)

z=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(x1<0)

x1=0;

if(y1<0)

y1=0;

Page 74: NINE MEN'S MORRIS JAVA CODE

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("G7")){

if(!location[G7].equals("0")&&!location[G7].equals(onMove)){

doMill = true;

location[G7]="0";

j--;r--;z--;f1--;l1--;m1--;n1--;x1--;y1--;z1--;

if(j<0)

j=0;

if(r<0)

r=0;

if(z<0)

z=0;

if(f1<0)

f1=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(n1<0)

n1=0;

Page 75: NINE MEN'S MORRIS JAVA CODE

if(x1<0)

x1=0;

if(y1<0)

y1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

}while(doMill != true);

}

public void Display(){

System.out.print(" A B C D E F G");

System.out.print("\n");

System.out.print("\n");

System.out.print("1 ");

System.out.print(location[0]);

System.out.print("-----------");

System.out.print(location[1]);

System.out.print("-----------");

System.out.print(location[2]);

System.out.print("\n");

System.out.print(" ");

Page 76: NINE MEN'S MORRIS JAVA CODE

System.out.print("| | |");

System.out.print("\n");

System.out.print("2 ");

System.out.print("| ");

System.out.print(location[3]);

System.out.print("-------");

System.out.print(location[4]);

System.out.print("-------");

System.out.print(location[5]);

System.out.print(" |");

System.out.print("\n");

System.out.print(" ");

System.out.print("| | | | |");

System.out.print("\n");

System.out.print("3 ");

System.out.print("| | ");

System.out.print(location[6]);

System.out.print("---");

System.out.print(location[7]);

System.out.print("---");

System.out.print(location[8]);

System.out.print(" | |");

System.out.print("\n");

System.out.print(" ");

System.out.print("| | | | | |");

System.out.print("\n");

System.out.print("4 ");

Page 77: NINE MEN'S MORRIS JAVA CODE

System.out.print(location[9]);

System.out.print("---");

System.out.print(location[10]);

System.out.print("---");

System.out.print(location[11]);

System.out.print(" ");

System.out.print(location[12]);

System.out.print("---");

System.out.print(location[13]);

System.out.print("---");

System.out.print(location[14]);

System.out.print("\n");

System.out.print(" ");

System.out.print("| | | | | |");

System.out.print("\n");

System.out.print("5 ");

System.out.print("| | ");

System.out.print(location[15]);

System.out.print("---");

System.out.print(location[16]);

System.out.print("---");

System.out.print(location[17]);

System.out.print(" | |");

System.out.print("\n");

System.out.print(" ");

System.out.print("| | | | |");

System.out.print("\n");

Page 78: NINE MEN'S MORRIS JAVA CODE

System.out.print("6 ");

System.out.print("| ");

System.out.print(location[18]);

System.out.print("-------");

System.out.print(location[19]);

System.out.print("-------");

System.out.print(location[20]);

System.out.print(" |");

System.out.print("\n");

System.out.print(" ");

System.out.print("| | |");

System.out.print("\n");

System.out.print("7 ");

System.out.print(location[21]);

System.out.print("-----------");

System.out.print(location[22]);

System.out.print("-----------");

System.out.print(location[23]);

System.out.print("\n");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////HUMAN VS COMPUTER CLASS

Page 79: NINE MEN'S MORRIS JAVA CODE

import java.util.ArrayList;

import java.util.Random;

public class PlayHC extends PlayHH {

private ArrayList<String> Rand ;

Random rn = new Random();

public PlayHC(String p1, String p2) {

super(p1,p2);

Rand = new ArrayList<String>(24);

}

public String Random(){

int temp=0;

Rand.add("A1");Rand.add("D1");Rand.add("G1");Rand.add("B2");Rand.add("D2");Rand.add("F2");Rand.add("C3");Rand.add("D3");Rand.add("E3");Rand.add("A4");Rand.add("B4");Rand.add("C4");Rand.add("E4");Rand.add("F4");Rand.add("G4");Rand.add("C5");Rand.add("D5");Rand.add("E5");Rand.add("B6");Rand.add("D6");Rand.add("F6");Rand.add("A7");Rand.add("D7");Rand.add("G7");

String get="";

do{

temp=rn.nextInt(24);

canPut(Rand.get(temp));

}while(canPut!=true);

get=Rand.get(temp);

/*

Page 80: NINE MEN'S MORRIS JAVA CODE

for(int i=0;i<Rand.size();i++){

canPut(Rand.get(i));

if(canPut)

get = Rand.get(i);

}*/

return get;

}

public void play3(){

// int loop1=0;

do{

System.out.println("[Current Score]");

System.out.println("White total = "+buttonW);

System.out.println("White left outside board = "+BWoutside);

System.out.println("Black total = "+buttonB);

System.out.println("Black left outside board = "+BBoutside);

String input="";

do{

System.out.println(onMove+" to Move");

if(onMove.equals("W")){

System.out.println("insert your selection");

input = sc.next().toUpperCase();

}

else if(onMove.equals("B")){

input = Random();

}

Page 81: NINE MEN'S MORRIS JAVA CODE

canPut(input);

}while(canPut!=true);

put(input);

Display();

System.out.println();

if(isMill()==true){

if(onMove.equals("W")){

BBoutside--;

buttonB--;

}

else if(onMove.equals("B")){

BWoutside--;

buttonW--;

}

System.out.println("MILL!");

Milling();

Display();

System.out.println();

//a++;

}

if(onMove.equals("W")){

BWoutside--;

//buttonW--;

Page 82: NINE MEN'S MORRIS JAVA CODE

onMove = "B";

}

else if(onMove.equals("B")){

BBoutside--;

//buttonB--;

onMove = "W";

}

// loop1++;

}while(BBoutside>0);

System.out.println("end play 1");

}

public void play4(){

a=0;b=0;c=0;d=0;e=0;f=0;g=0;h=0;i=0;j=0;k=0;l=0;m=0;n=0;o=0;p=0;q=0;r=0;s=0;t=0;u=0;v=0;w=0;x=0;y=0;z=0;

a1=0;b1=0;c1=0;d1=0;e1=0;f1=0;g1=0;h1=0;i1=0;j1=0;k1=0;l1=0;m1=0;n1=0;o1=0;p1=0;q1=0;r1=0;s1=0;t1=0;u1=0;v1=0;w1=0;x1=0;y1=0;z1=0;

a2=0;b2=0;c2=0;d2=0;

String input1="";

String input2;

System.out.println("All button is on the board.\nYou need to select one button and move to another location.");

do{

do{

System.out.println(onMove+" on move");

if(onMove.equals("W")){

System.out.println("Select which button to move");

input1 = sc.next().toUpperCase();

Page 83: NINE MEN'S MORRIS JAVA CODE

}

else if(onMove.equals("B")){

input1 = Random();

}

canTake(input1);

}while(canTake!=true);

do {do{

if(onMove.equals("W")){

System.out.println("Select your destination");

input2 = sc.next().toUpperCase();

}

else if(onMove.equals("B")){

input2 = Random();

}

input2 = sc.next().toUpperCase();

adjacent(input1,input2);

} while(!adj);

canPut(input2);

} while (!canPut);

put(input2);

clear(input1);

Display();

System.out.println();

Page 84: NINE MEN'S MORRIS JAVA CODE

if(isMill()==true){

if(onMove.equals("W")){

buttonB--;

}

else if(onMove.equals("B")){

buttonW--;

}

System.out.println("MILL!");

Milling();

Display();

System.out.println();

//a++;

}

if(onMove.equals("W")){

BWoutside--;

//buttonW--;

onMove = "B";

}

else if(onMove.equals("B")){

BBoutside--;

//buttonB--;

onMove = "W";

}

Page 85: NINE MEN'S MORRIS JAVA CODE

}while(checkWin());

}

public void Milling1(){

boolean doMill = false;

String input="";

do{

if(onMove.equals("B")){

input = Random();

}

else if(onMove.equals("W")){

System.out.println("Enter location to delete");

input = sc.next().toUpperCase();

}

if(input.equals("A1")){

if(!location[A1].equals("0")&&!location[A1].equals(onMove)){

doMill = true;

location[A1]="0";

a--;i--;q--;y--;k1--;n1--;w1--;y1--;z1--;

if(a<0)

a=0;

if(i<0)

i=0;

if(q<0)

q=0;

if(y<0)

Page 86: NINE MEN'S MORRIS JAVA CODE

y=0;

if(k1<0)

k1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(y1<0)

y1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D1")){

if(!location[D1].equals("0")&&!location[D1].equals(onMove)){

doMill = true;

location[D1]="0";

a--;q--;u--;c1--;k1--;n1--;w1--;z1--;

if(a<0)

a=0;

if(q<0)

q=0;

Page 87: NINE MEN'S MORRIS JAVA CODE

if(u<0)

u=0;

if(c1<0)

c1=0;

if(k1<0)

k1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("G1")){

if(!location[G1].equals("0")&&!location[G1].equals(onMove)){

doMill = true;

location[G1]="0";

a--;q--;r--;f1--;k1--;l1--;n1--;w1--;x1--;z1--;

if(a<0)

a=0;

Page 88: NINE MEN'S MORRIS JAVA CODE

if(q<0)

q=0;

if(r<0)

r=0;

if(f1<0)

f1=0;

if(k1<0)

k1=0;

if(l1<0)

l1=0;

if(n1<0)

n1=0;

if(w1<0)

w1=0;

if(x1<0)

x1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B2")){

if(!location[B2].equals("0")&&!location[B2].equals(onMove)){

Page 89: NINE MEN'S MORRIS JAVA CODE

doMill = true;

location[B2]="0";

b--;h--;p--;x--;o1--;p1--;r1--;a2--;b2--;d2--;

if(b<0)

b=0;

if(h<0)

h=0;

if(p<0)

p=0;

if(x<0)

x=0;

if(o1<0)

o1=0;

if(p1<0)

p1=0;

if(r1<0)

r1=0;

if(a2<0)

a2=0;

if(b2<0)

b2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

Page 90: NINE MEN'S MORRIS JAVA CODE

}

}

if(input.equals("D2")){

if(!location[D2].equals("0")&&!location[D2].equals(onMove)){

doMill = true;

location[D2]="0";

b--;p--;u--;c1--;o1--;r1--;a2--;d2--;

if(b<0)

b=0;

if(p<0)

p=0;

if(u<0)

u=0;

if(c1<0)

c1=0;

if(o1<0)

o1=0;

if(r1<0)

r1=0;

if(a2<0)

a2=0;

if(d2<0)

d2=0;

}

else{

Page 91: NINE MEN'S MORRIS JAVA CODE

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("F2")){

if(!location[F2].equals("0")&&!location[F2].equals(onMove)){

doMill = true;

location[F2]="0";

b--;p--;s--;e1--;o1--;q1--;r1--;a2--;c2--;d2--;

if(b<0)

b=0;

if(p<0)

p=0;

if(s<0)

s=0;

if(e1<0)

e1=0;

if(o1<0)

o1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(a2<0)

a2=0;

Page 92: NINE MEN'S MORRIS JAVA CODE

if(c2<0)

c2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("C3")){

if(!location[C3].equals("0")&&!location[C3].equals(onMove)){

doMill = true;

location[C3]="0";

c--;g--;o--;w--;g1--;h1--;j1--;s1--;t1--;v1--;

if(c<0)

c=0;

if(g<0)

g=0;

if(o<0)

o=0;

if(w<0)

w=0;

if(g1<0)

g1=0;

if(h1<0)

Page 93: NINE MEN'S MORRIS JAVA CODE

h1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D3")){

if(!location[D3].equals("0")&&!location[D3].equals(onMove)){

doMill = true;

location[D3]="0";

c--;o--;u--;c1--;g1--;j1--;s1--;v1--;

if(c<0)

c=0;

if(o<0)

o=0;

if(u<0)

u=0;

Page 94: NINE MEN'S MORRIS JAVA CODE

if(c1<0)

c1=0;

if(g1<0)

g1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E3")){

if(!location[E3].equals("0")&&!location[E3].equals(onMove)){

doMill = true;

location[E3]="0";

c--;o--;t--;d1--;g1--;i1--;j1--;s1--;u1--;v1--;

if(c<0)

c=0;

if(o<0)

o=0;

Page 95: NINE MEN'S MORRIS JAVA CODE

if(t<0)

t=0;

if(d1<0)

d1=0;

if(g1<0)

g1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(s1<0)

s1=0;

if(u1<0)

u1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("A4")){

if(!location[A4].equals("0")&&!location[A4].equals(onMove)){

doMill = true;

location[A4]="0";

Page 96: NINE MEN'S MORRIS JAVA CODE

d--;i--;n--;y--;k1--;m1--;w1--;y1--;

if(d<0)

d=0;

if(i<0)

i=0;

if(n<0)

n=0;

if(y<0)

y=0;

if(k1<0)

k1=0;

if(m1<0)

m1=0;

if(w1<0)

w1=0;

if(y1<0)

y1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B4")){

if(!location[B4].equals("0")&&!location[B4].equals(onMove)){

doMill = true;

Page 97: NINE MEN'S MORRIS JAVA CODE

location[B4]="0";

d--;h--;n--;x--;o1--;p1--;a2--;b2--;

if(d<0)

d=0;

if(h<0)

h=0;

if(n<0)

n=0;

if(x<0)

x=0;

if(o1<0)

o1=0;

if(p1<0)

p1=0;

if(a2<0)

a2=0;

if(b2<0)

b2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("C4")){

if(!location[C4].equals("0")&&!location[C4].equals(onMove)){

Page 98: NINE MEN'S MORRIS JAVA CODE

doMill = true;

location[C4]="0";

d--;g--;n--;w--;g1--;h1--;s1--;t1--;

if(d<0)

d=0;

if(g<0)

g=0;

if(n<0)

n=0;

if(w<0)

w=0;

if(g1<0)

g1=0;

if(h1<0)

h1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E4")){

Page 99: NINE MEN'S MORRIS JAVA CODE

if(!location[E4].equals("0")&&!location[E4].equals(onMove)){

doMill = true;

location[E4]="0";

e--;m--;t--;d1--;i1--;j1--;u1--;v1--;

if(e<0)

e=0;

if(m<0)

m=0;

if(t<0)

t=0;

if(d1<0)

d1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(u1<0)

u1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

Page 100: NINE MEN'S MORRIS JAVA CODE

if(input.equals("F4")){

if(!location[F4].equals("0")&&!location[F4].equals(onMove)){

doMill = true;

location[F4]="0";

e--;m--;s--;e1--;q1--;r1--;c2--;d2--;

if(e<0)

e=0;

if(m<0)

m=0;

if(s<0)

s=0;

if(e1<0)

e1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(c2<0)

c2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

Page 101: NINE MEN'S MORRIS JAVA CODE

}

if(input.equals("G4")){

if(!location[G4].equals("0")&&!location[G4].equals(onMove)){

doMill = true;

location[G4]="0";

e--;m--;r--;f1--;l1--;n1--;x1--;z1--;

if(e<0)

e=0;

if(m<0)

m=0;

if(r<0)

r=0;

if(f1<0)

f1=0;

if(l1<0)

l1=0;

if(n1<0)

n1=0;

if(x1<0)

x1=0;

if(z1<0)

z1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

Page 102: NINE MEN'S MORRIS JAVA CODE

}

}

if(input.equals("C5")){

if(!location[C5].equals("0")&&!location[C5].equals(onMove)){

doMill = true;

location[C5]="0";

g--;l--;w--;b1--;g1--;h1--;i1--;s1--;t1--;u1--;

if(g<0)

g=0;

if(l<0)

l=0;

if(w<0)

w=0;

if(b1<0)

b1=0;

if(g1<0)

g1=0;

if(h1<0)

h1=0;

if(i1<0)

i1=0;

if(s1<0)

s1=0;

if(t1<0)

t1=0;

if(u1<0)

Page 103: NINE MEN'S MORRIS JAVA CODE

u1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D5")){

if(!location[D5].equals("0")&&!location[D5].equals(onMove)){

doMill = true;

location[D5]="0";

f--;l--;v--;b1--;h1--;i1--;t1--;u1--;

if(f<0)

f=0;

if(l<0)

l=0;

if(v<0)

v=0;

if(b1<0)

b1=0;

if(h1<0)

h1=0;

if(i1<0)

i1=0;

if(t1<0)

t1=0;

Page 104: NINE MEN'S MORRIS JAVA CODE

if(u1<0)

u1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("E5")){

if(!location[E5].equals("0")&&!location[E5].equals(onMove)){

doMill = true;

location[E5]="0";

l--;t--;b1--;d1--;i1--;j1--;u1--;v1--;

if(l<0)

l=0;

if(t<0)

t=0;

if(b1<0)

b1=0;

if(d1<0)

d1=0;

if(i1<0)

i1=0;

if(j1<0)

j1=0;

if(u1<0)

Page 105: NINE MEN'S MORRIS JAVA CODE

u1=0;

if(v1<0)

v1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("B6")){

if(!location[B6].equals("0")&&!location[B6].equals(onMove)){

doMill = true;

location[B6]="0";

h--;k--;x--;a1--;o1--;p1--;q1--;a2--;b2--;c2--;

if(h<0)

h=0;

if(k<0)

k=0;

if(x<0)

x=0;

if(a1<0)

a1=0;

if(o1<0)

o1=0;

if(p1<0)

Page 106: NINE MEN'S MORRIS JAVA CODE

p1=0;

if(q1<0)

q1=0;

if(a2<0)

a2=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D6")){

if(!location[D6].equals("0")&&!location[D6].equals(onMove)){

doMill = true;

location[D6]="0";

f--;k--;v--;a1--;p1--;q1--;b2--;c2--;

if(f<0)

f=0;

if(k<0)

k=0;

if(v<0)

v=0;

Page 107: NINE MEN'S MORRIS JAVA CODE

if(a1<0)

a1=0;

if(p1<0)

p1=0;

if(q1<0)

q1=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("F6")){

if(!location[F6].equals("0")&&!location[F6].equals(onMove)){

doMill = true;

location[F6]="0";

k--;s--;a1--;e1--;p1--;q1--;r1--;b2--;c2--;d2--;

if(k<0)

k=0;

if(s<0)

s=0;

Page 108: NINE MEN'S MORRIS JAVA CODE

if(a1<0)

a1=0;

if(e1<0)

e1=0;

if(p1<0)

p1=0;

if(q1<0)

q1=0;

if(r1<0)

r1=0;

if(b2<0)

b2=0;

if(c2<0)

c2=0;

if(d2<0)

d2=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("A7")){

if(!location[A7].equals("0")&&!location[A7].equals(onMove)){

doMill = true;

location[A7]="0";

Page 109: NINE MEN'S MORRIS JAVA CODE

i--;j--;y--;z--;k1--;l1--;m1--;w1--;x1--;y1--;

if(i<0)

i=0;

if(j<0)

j=0;

if(y<0)

y=0;

if(z<0)

z=0;

if(k1<0)

k1=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(x1<0)

x1=0;

if(y1<0)

y1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

if(input.equals("D7")){

Page 110: NINE MEN'S MORRIS JAVA CODE

if(!location[D7].equals("0")&&!location[D7].equals(onMove)){

doMill = true;

location[D7]="0";

f--;j--;v--;z--;l1--;m1--;x1--;y1--;

if(f<0)

f=0;

if(j<0)

j=0;

if(v<0)

v=0;

if(z<0)

z=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(x1<0)

x1=0;

if(y1<0)

y1=0;

}

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

Page 111: NINE MEN'S MORRIS JAVA CODE

if(input.equals("G7")){

if(!location[G7].equals("0")&&!location[G7].equals(onMove)){

doMill = true;

location[G7]="0";

j--;r--;z--;f1--;l1--;m1--;n1--;x1--;y1--;z1--;

if(j<0)

j=0;

if(r<0)

r=0;

if(z<0)

z=0;

if(f1<0)

f1=0;

if(l1<0)

l1=0;

if(m1<0)

m1=0;

if(n1<0)

n1=0;

if(x1<0)

x1=0;

if(y1<0)

y1=0;

if(z1<0)

z1=0;

}

Page 112: NINE MEN'S MORRIS JAVA CODE

else{

System.out.println("Location not invalid. Insert again");

doMill=false;

}

}

}while(doMill != true);

}

}