-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.java
More file actions
57 lines (44 loc) · 1.97 KB
/
Runner.java
File metadata and controls
57 lines (44 loc) · 1.97 KB
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
import model.*;
import java.io.IOException;
public final class Runner {
private final RemoteProcessClient remoteProcessClient;
private final String token;
public static void main(String[] args) throws IOException {
new Runner(args.length == 3 ? args : new String[]{"127.0.0.1", "31001", "0000000000000000"}).run();
}
private Runner(String[] args) throws IOException {
remoteProcessClient = new RemoteProcessClient(args[0], Integer.parseInt(args[1]));
token = args[2];
}
public void run() throws IOException {
try {
remoteProcessClient.writeToken(token);
remoteProcessClient.writeProtocolVersion();
int teamSize = remoteProcessClient.readTeamSize();
Game game = remoteProcessClient.readGameContext();
Strategy[] strategies = new Strategy[teamSize];
for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
strategies[strategyIndex] = new MyStrategy();
}
PlayerContext playerContext;
while ((playerContext = remoteProcessClient.readPlayerContext()) != null) {
Wizard[] playerWizards = playerContext.getWizards();
if (playerWizards == null || playerWizards.length != teamSize) {
break;
}
Move[] moves = new Move[teamSize];
for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) {
Wizard playerWizard = playerWizards[wizardIndex];
Move move = new Move();
moves[wizardIndex] = move;
strategies[wizardIndex /*playerWizard.getTeammateIndex()*/].move(
playerWizard, playerContext.getWorld(), game, move
);
}
remoteProcessClient.writeMoves(moves);
}
} finally {
remoteProcessClient.close();
}
}
}