-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.cs
55 lines (43 loc) · 2.14 KB
/
Runner.cs
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
using Com.CodeGame.CodeWizards2016.DevKit.CSharpCgdk.Model;
namespace Com.CodeGame.CodeWizards2016.DevKit.CSharpCgdk {
public sealed class Runner {
private readonly RemoteProcessClient remoteProcessClient;
private readonly string token;
public static void Main(string[] args) {
new Runner(args.Length == 3 ? args : new[] { "127.0.0.1", "31001", "0000000000000000" }).Run();
}
private Runner(string[] args) {
remoteProcessClient = new RemoteProcessClient(args[0], int.Parse(args[1]));
token = args[2];
}
public void Run() {
try {
remoteProcessClient.WriteTokenMessage(token);
remoteProcessClient.WriteProtocolVersionMessage();
int teamSize = remoteProcessClient.ReadTeamSizeMessage();
Game game = remoteProcessClient.ReadGameContextMessage();
IStrategy[] strategies = new IStrategy[teamSize];
for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
strategies[strategyIndex] = new MyStrategy();
}
PlayerContext playerContext;
while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) {
Wizard[] playerWizards = playerContext.Wizards;
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].Move(playerWizard, playerContext.World, game, move);
}
remoteProcessClient.WriteMovesMessage(moves);
}
} finally {
remoteProcessClient.Close();
}
}
}
}