forked from ccase/Cowboys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HappyHobo.java
61 lines (46 loc) · 2.45 KB
/
HappyHobo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class HappyHobo extends Shooter {
int tieCounter = 0;
public String play(String mine, String other){
if(mine.equals("")){ tieCounter=0; return "R"; } //Always reload the first move
char hisLastMove = other.charAt(other.length()-1);
char myLastMove = mine.charAt(mine.length()-1);
int myRCount = mine.length() - mine.replace("R", "").length();
int hisRCount = other.length() - other.replace("R", "").length();
int mySCount = mine.length() - mine.replace("S", "").length();
int hisSCount = other.length() - other.replace("S", "").length();
int myBullets = myRCount - mySCount;
int hisBullets = hisRCount - hisSCount;
if (myBullets < 0) {myBullets = 0;}
if (hisBullets < 0) {hisBullets = 0;}
if ( (mine.length()>5) && (mine.charAt(mine.length()-6)=='S') && (mine.charAt(mine.length()-5)=='R') && (mine.charAt(mine.length()-4)=='S') && (mine.charAt(mine.length()-3)=='R') && (mine.charAt(mine.length()-2)=='S') && (myLastMove=='R')) {
return "R";
}
if (myBullets > 5) {return "S";}
if (hisBullets > 5) {
if (myBullets > 0) {return "S";}
else {return "R";}
}
if (hisBullets == 5) {
if (hisLastMove == 'R') { return "R";}
else {
if (myLastMove != 'S') {return "S";}
else {return "R";}
}
}
if (myBullets > 3) {
if (myLastMove == 'R') { return "B"; }
}
if (myBullets > 0) {
if ( (other.length() > 3) && (other.charAt(other.length()-4)=='B') && (other.charAt(other.length()-3)=='B') && (other.charAt(other.length()-2)== 'B') && (hisLastMove == 'B') ) { return "R"; }
//if ( (other.length() > 2) && (other.charAt(other.length()-3)=='B') && (other.charAt(other.length()-2)== 'B') && (yourLastMove == 'B') ) {return "S";}
if ( (other.length() > 3) && ((other.charAt(other.length()-4)) == 'R') && ((other.charAt(other.length()-3)) == 'R') && ((other.charAt(other.length()-2)) == 'B') && (hisLastMove == 'R') ) {return "S";}
if ( (other.length() > 2) && ((other.charAt(other.length()-3)) == 'R') && ((other.charAt(other.length()-2)) == 'R') && (hisLastMove == 'R') ) {return "S";}
}
if (hisBullets > 0) {
if ( (other.length() > 3) && (other.charAt(other.length()-4)=='B') && (other.charAt(other.length()-3)=='B') && (other.charAt(other.length()-2)== 'B') && (hisLastMove == 'B') ) { return "R"; }
else {return "B";}
}
if (hisBullets == 0) { return "R"; }
return "R";
}
}