-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.cpp
44 lines (36 loc) · 1.07 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 <memory>
#include "Runner.h"
#include "MyStrategy.h"
using namespace model;
using namespace std;
#ifndef CUSTOM_RUNNER
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;
}
#endif
Runner::Runner(const char* host, const char* port, const char* token)
: remoteProcessClient(host, atoi(port)), token(token) {
}
void Runner::run() {
unique_ptr<Strategy> strategy(new MyStrategy);
unique_ptr<Game> game;
unordered_map<int, Action> actions;
remoteProcessClient.write_token(token);
unique_ptr<Rules> rules = remoteProcessClient.read_rules();
while ((game = remoteProcessClient.read_game()) != nullptr) {
actions.clear();
for (const Robot& robot : game->robots) {
if (robot.is_teammate) {
strategy->act(robot, *rules, *game, actions[robot.id]);
}
}
remoteProcessClient.write(actions);
}
}