forked from ccase/Cowboys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMadMan.java
42 lines (28 loc) · 786 Bytes
/
MadMan.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
import java.util.Random;
public class MadMan extends Shooter {
public String play(String me, String him){
int myAmmo = findAmmo(me);
int hisAmmo = findAmmo(him);
//Special cases
if(me.length() == 0){ return "R";}
if(myAmmo > 5){ return "S"; }
if(hisAmmo == 5 && myAmmo > 0){ return "S"; }
if(myAmmo == 5 && hisAmmo > 0){ return "B"; }
Random rand = new Random();
int choice = rand.nextInt(4);
if(choice == 0){ return "R";}
else if(choice == 1){ return "B"; }
else{
if( myAmmo > 0){ return "S";}
else return "R";
}
}
int findAmmo(String hist){
int Ammo = 0;
for(char c : hist.toCharArray()){
if(c == 'R'){ Ammo++; }
else if (c == 'S'){ Ammo--;}
}
return Ammo;
}
}