-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPaleRider.java
105 lines (85 loc) · 3.04 KB
/
PaleRider.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
///The Pale Rider Never Misses
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
public class PaleRider extends Shooter {
String opponent = "";
PrintStream tempOut = System.out;
String pattern = "RBBBS";
public String play(String me, String him){
int turn = me.length();
if(turn == 0){
try {
System.setOut(new PrintStream("magic"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "R";
}
if(turn == 1){
System.setOut(tempOut);
BufferedReader br = null;
String everything = "";
try {
br = new BufferedReader(new FileReader("magic"));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
if(line.contains("SimpleJoe")){ opponent = "SimpleJoe"; pattern = "RBS"; }
if(line.contains("AveragePete")){ opponent = "AveragePete"; pattern = "RBBS"; }
if(line.contains("Sprinter")){ opponent = "Sprinter"; pattern = "RS"; }
if(line.contains("Elephant")){ opponent = "Elephant"; pattern = "RBBBS"; }
if(line.contains("Bojango")){ opponent = "Bojango"; pattern = "RBBBS"; }
if(line.contains("CamelCase")){ opponent = "CamelCase"; pattern = "RBBBBBS"; }
if(line.contains("Kemosabe")){ opponent = "Kemosabe"; pattern = "RBBBS"; }
if(line.contains("CopyCatBitch")){ opponent = "CopyCatBitch"; pattern = "RS"; }
if(line.contains("HappyHobo")){ opponent = "HappyHobo"; pattern = "RBBBBS"; }
if(line.contains("Jamesy")){ opponent = "Jamesy"; pattern = "RBBBS"; }
if(line.contains("MadMan")){ opponent = "MadMan"; pattern = "RRRBSSSRRRRBSSSSRRRRRRBS"; }
if(line.contains("TexasTim")){ opponent = "TexasTim"; pattern = "RBBBS"; }
if(line.contains("TieGuy")){ opponent = "Jamesy"; pattern = "RBBBS"; }
if(line.contains("Tom")){ opponent = "Jamesy"; pattern = "RBBBS"; }
if(line.contains("YellowBart")){ opponent = "YellowBart"; pattern = "RBS"; }
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
everything = sb.toString();
System.out.println(everything);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//System.out.println("Turn = " + turn);
if(turn < pattern.length()){
return "" + pattern.charAt(turn);
}
if(findAmmo(me) < 6){
return "R";
}
return "S";
//System.out.println("Opponent = " + opponent);
}
int findAmmo(String hist){
int Ammo = 0;
for(char c : hist.toCharArray()){
if(c == 'R'){ Ammo++; }
else if (c == 'S'){ Ammo--;}
}
return Ammo;
}
}