forked from ccase/Cowboys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYellowBart.java
45 lines (27 loc) · 823 Bytes
/
YellowBart.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
import java.util.Random;
public class YellowBart extends Shooter {
public String play(String me, String him){
int myAmmo = findAmmo(me);
int hisAmmo = findAmmo(him);
//Start
if(me.length() == 0){ return "R";}
if(me.length() == 1 || me.length() == 2){ return "B"; }
if(me.length() == 3){ return "R"; }
//reload if empty, and just shot at
if(myAmmo < 1 && him.charAt(him.length() - 1) == 'S'){
return "R";
}
//If you're about to get shot, shoot
if((hisAmmo + myAmmo) > 5 && myAmmo > 0){ return "S";}
//Otherwise, play it safe partner
return "B";
}
int findAmmo(String hist){
int Ammo = 0;
for(char c : hist.toCharArray()){
if(c == 'R'){ Ammo++; }
else if (c == 'S'){ Ammo--;}
}
return Ammo;
}
}