-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunner.cpp
44 lines (32 loc) · 1.1 KB
/
Runner.cpp
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
#include "Runner.h"
#include <memory>
#include "MyStrategy.h"
using namespace model;
using namespace std;
int main(int argc, char* argv[]) {
if (argc == 4) {
Runner runner(argv[1], argv[2], argv[3]);
runner.run();
} else {
Runner runner("127.0.0.1", "31001", "0000000000000000");
runner.run();
}
return 0;
}
Runner::Runner(const char* host, const char* port, const char* token)
: remoteProcessClient(host, atoi(port)), token(token) {
}
void Runner::run() {
remoteProcessClient.writeTokenMessage(token);
remoteProcessClient.writeProtocolVersionMessage();
remoteProcessClient.readTeamSizeMessage();
Game game = remoteProcessClient.readGameContextMessage();
unique_ptr<Strategy> strategy(new MyStrategy);
shared_ptr<PlayerContext> playerContext;
while ((playerContext = remoteProcessClient.readPlayerContextMessage()) != nullptr) {
Player player = playerContext->getPlayer();
Move move;
strategy->move(player, playerContext->getWorld(), game, move);
remoteProcessClient.writeMoveMessage(move);
}
}