-
Notifications
You must be signed in to change notification settings - Fork 0
/
Runner.cs
46 lines (36 loc) · 1.56 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
using System.Collections.Generic;
using Com.CodeGame.CodeWars2017.DevKit.CSharpCgdk.Model;
namespace Com.CodeGame.CodeWars2017.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", "31002", "0000000000000000"}).Run();
}
private Runner(IReadOnlyList<string> args) {
remoteProcessClient = new RemoteProcessClient(args[0], int.Parse(args[1]));
token = args[2];
}
public void Run() {
try {
remoteProcessClient.WriteTokenMessage(token);
remoteProcessClient.WriteProtocolVersionMessage();
remoteProcessClient.ReadTeamSizeMessage();
Game game = remoteProcessClient.ReadGameContextMessage();
IStrategy strategy = new MyStrategy();
PlayerContext playerContext;
while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) {
Player player = playerContext.Player;
if (player == null) {
break;
}
Move move = new Move();
strategy.Move(player, playerContext.World, game, move);
remoteProcessClient.WriteMoveMessage(move);
}
} finally {
remoteProcessClient.Close();
}
}
}
}