In: Computer Science
Note :- This is the main algorithem for the game Thanks.
ALGORITHM The game board consist 23 spots named as B0 to B22. Human player can choose a role as tiger/goat. Assume that the humanplayer is playing goat as G and the Android is playing tiger as T. A. Check for winning condition At the start of its turn, the Android first checks for tigers winning cases and goats winning cases. For the tiger’s winning, the number of G in the board is less than or equal five. For the goat’s winning, the moves for all three T are null. Algorithm: Let B[i] be the ith spot. So I lies between 0 and 22. Let numerically T be represented by 0 and G by 1 and empty spot by 2.
value=0
For (int i=0; i<22; i++) {
If(i==0) { //Tiger blocked in spot B0
If(B[i] == 0 && B[i+2] == 1 && B[i+3] == 1 &&
B[i+4] == 1 && B[i+5] == 1 && B[i+8] == 1 &&
B[i+9] == 1 && B[i+10] == 1 && B[i+11] == 1) {
value=value+1
}
}
If(i==1) { //Tiger blocked in spot B1
If(B[i] == 0 && B[i+1] == 1 && B[i+2] == 1 &&
B[i+6] == 1 && B[i+12] == 1) {
value=value+1
}
}
If(i==2) { //Tiger blocked in spot B2
If(B[i] == 0 && B[i+1] == 1 && B[i+2] == 1 &&
B[i-1] == 1 && B[i-2] == 1 && B[i+6] == 1 &&
B[i+12] == 1) {
value=value+1
}
}
If (i==3 || i==4) { //Tiger blocked in spot B3 or B4
If(B[i] == 0 && B[i+1] == 1 && B[i-1] == 1 &&
B[i+2] == 1 && B[i-2] == 1 && B[i+6] == 1 &&
B[i+12] == 1 && B[i-i] == 1) {
value=value+1
}
}
If(i==5) { //Tiger blocked in spot B5
If(B[i] == 0 && B[i+1] == 1 && B[i-1] == 1 && B[i-2]
== 1 && B[i+6] == 1 && B[i+12] == 1) {
value=value+1
}
}
If(i==6) { //Tiger blocked in spot B6
If(B[i] == 0 && B[i-1] == 1 && B[i-2] == 1 && B[i+6]
== 1 && B[i+12] == 1) {
value = value+1
}
}
If(i==7) { //Tiger blocked in spot B7
If(B[i] == 0 && B[i-6] == 1 && B[i+6] == 1 &&
B[i+1] == 1 && B[i+2] == 1) {
value =value+1
}}
If(i==8) { //Tiger blocked in spot B8
If(B[i] == 0 && B[i-1] == 1 && B[i+1] == 1 &&
B[i+2] == 1 && B[i-6] == 1 && B[i-i] == 1 && B[i+6]
== 1 && B[i+11] == 1) {
value= value+1
}
}
If (i==9 || i==10) { //Tiger blocked in spot B9 or B10
If(B[i] == 0 && B[i-1] == 1 && B[i-2] == 1 && B[i+1]
== 1 && B[i+2] == 1 && B[i-6] == 1 && B[i-i] == 1
&& B[i+6] == 1 && B[i+11] == 1) {
value=value+1
}
}
If(i==11) { //Tiger blocked in spot B11
If(B[i] == 0 && B[i-1] == 1 && B[i+1] == 1 && B[i-2]
== 1 && B[i-6] == 1 && B[i-i] == 1 && B[i+6] == 1
&& B[i+11] == 1) {
value=value+1
}
}
If (i==12) { //Tiger blocked in spot B12
If(B[i] == 0 && B[i-6] == 1 && B[i+6] == 1 && B[i-1]
== 1 && B[i-2] == 1) {
value=value+1
}
}
If (i==13) { //Tiger blocked in spot B13
If(B[i] == 0 && B[i+1] == 1 && B[i+2] == 1 &&
B[i-6] == 1 && B[i-12] == 1) {
value=value+1
}
}
If (i==14) { //Tiger blocked in spot B14
If(B[i] == 0 && B[i-1] == 1 && B[i+1] == 1 &&
B[i+2] == 1 && B[i-6] == 1 && B[i-12] == 1 &&
B[i+5] == 1) {
value=value+1
}
}
If (i==15 || i==16) { //Tiger blocked in spot B15 or 16
If(B[i] == 0 && B[i-1] == 1 && B[i-2] == 1 && B[i+1]
== 1 && B[i+2] == 1 && B[i-6] == 1 && B[i-12] == 1
&& B[i+5] == 1) {
value=value+1
}
}
If (i==17) { //Tiger blocked in spot B17
If(B[i] == 0 && B[i-1] == 1 && B[i+1] == 1 &&
B[i-2] == 1 && B[i-6] == 1 && B[i-12] == 1 &&
B[i+5] == 1) {
value=value+1
}
}
If (i==18) { //Tiger blocked in spot B18
If(B[i] == 0 && B[i-1] == 1 && B[i-2] == 1 && B[i-6]
== 1 && B[i-12] == 1) {
value=value+1
}
}
If(i==19) { //Tiger blocked in spot B19
If(B[i] == 0 && B[i+1] == 1 && B[i+2] == 1 &&
B[i-5] == 1 && B[i-11] == 1) {
value=value+1
}
}
If (i==20) { //Tiger blocked in spot B20
If(B[i] == 0 && B[i-1] == 1 && B[i-5] == 1 && B[i+1]
== 1 && B[i+2] == 1 && B[i-11] == 1) {
value=value+1
}
}
If (i==21) { //Tiger blocked in spot B21
If(B[i] == 0 && B[i-1] == 1 && B[i-5] == 1 && B[i+1]
== 1 && B[i-2] == 1 && B[i-11] == 1) {
value=value+1
}
}
If (i==22) { //Tiger blocked in spot B22
If(B[i] == 0 && B[i-1] == 1 && B[i-2] == 1 && B[i-5]
== 1 && B[i-11] == 1) {
value=value+1
}
}
}
Playing for Defensive Whenever the Android detects an empty spot which is followed by T, G it may insert T in the empty spot or capture the G to prevent the blocking from G.
Moves for Winning First, it is obvious that the goats have to consider the border during the placement phase - any goat that strays into the center will get eaten, or cause the demise of some other goat, without any apparent benefit in return for the sacrifice. Therefore, goatplayer strategy sounds simple: first populate the borders, and when at full strength, try to advance in unbroken formation, in the hope of suffocating the tigers. Second, tiger is moving back and forth, until near the end of the placement phase. Their goal is to stay far apart from each other, for two reasons: (1) in order to probe the full length of the goats’ front line for gaps, (2) so as to make it hard for the goats to immobilize all the three tigers at the same time.
Capture the Goats For the tigers, the objective is to ‘capture’ ten goats to win. Capturing is performed by jumping over the goats, although capturing is not obligatory. There are possible cases to capture the goat. Algorithm: Let B[i] be the ith spot. So I lies between 0 and 22. Let numerically T be represented by 0 and G by 1 and empty spot by 2.
If (i==0 && B[i]==0) {
If(B[i+2] == 1 && B[i+8] == 2) {
B[i]=2, B[i+2] =2, B[i+8] =0
}
If (B[i+3] == 1 && B[i+9] == 2) {
B[i]=2, B[i+3] =2, B[i+9] =0
}
If (B[i+4] ==1 && B[i+10] ==2) {
B[i]=2, B[i+4] =2, B[i+10] =0
}
If (B[i+5] == 1 && B[i+11] == 2) {
B[i]=2, B[i+5] =2, B[i+11] =0
}
}
If (i==1 || i==2 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i+6] == 1 && B[i+12] == 2) {
B[i]=2, B[i+6] =2, B[i+12] =0
}
}
If (i==3 || i==4 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i+6] == 1 && B[i+12] == 2) {
B[i]=2, B[i+6] =2, B[i+12] =0
}
If (B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
}
If (i==5 || i==6 && B[i]==0) {
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
If (B[i+6] == 1 && B[i+12] == 2) {
B[i]=2, B[i+6] =2, B[i+12] =0
}
}
If (i==7 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
}
If (i==8 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i+6] == 1 && B[i+11] == 2) {
B[i]=2, B[i+6] =2, B[i+11] =0
}
If (B[i-6] == 1 && B[i-i] == 2) {
B[i]=2, B[i-6] =2, B[i-i] =0
}
}
If (i==9 || i==10 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
If (B[i+6] == 1 && B[i+11] == 2) {
B[i]=2, B[i+6] =2, B[i+11] =0
}
If (B[i-6] == 1 && B[i-i] == 2) {
B[i]=2, B[i-6] =2, B[i-i] =0
}
}
If (i==11 && B[i]==0) {
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i+6] == 1 && B[i+11] == 2) {
B[i]=2, B[i+6] =2, B[i+11] =0
}
If (B[i-6] == 1 && B[i-i] == 2) {
B[i]=2, B[i-6] =2, B[i-i] =0
}
}
If (i==12 && B[i]==0) {
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
}
If (i==13 || i==14 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i-6] == 1 && B[i-12] == 2) {
B[i]=2, B[i-6] =2, B[i-12] =0
}
}
If (i==15 || i==16 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i-6] == 1 && B[i-12] == 2) {
B[i]=2, B[i-6] =2, B[i-12] =0
}
If (B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
}
If (i==17 || i==18 && B[i]==0) {
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
If (B[i-6] == 1 && B[i-12] == 2) {
B[i]=2, B[i-6] =2, B[i-12] =0
}
}
If (i==19 || i==20 && B[i]==0) {
If(B[i+1] == 1 && B[i+2] == 2) {
B[i]=2, B[i+1] =2, B[i+2] =0
}
If (B[i-5] == 1 && B[i-11] == 2) {
B[i]=2, B[i-5] =2, B[i-11] =0
}
}
If (i==21 || i==22 && B[i]==0) {
If(B[i-1] == 1 && B[i-2] == 2) {
B[i]=2, B[i-1] =2, B[i-2] =0
}
If (B[i-5] == 1 && B[i-11] == 2) {
B[i]=2, B[i-5] =2, B[i-11] =0
}
}
Thanks, Please appreciate my hard work. :-(