-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_a2.cpp
More file actions
53 lines (48 loc) · 1.68 KB
/
client_a2.cpp
File metadata and controls
53 lines (48 loc) · 1.68 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
#include "kakomimasu.h"
int main() {
// 自分のbearerTokenを書く
KakomimasuClient kc("");
kc.waitMatching();
kc.getGameInfo();
const int pno = kc.getPlayerNumber();
const vector<vector<int>> points = kc.getPoints();
const int w = kc.getWidth();
const int h = kc.getHeight();
const int nagents = kc.getAgentCount();
// ポイントの高い順ソート
vector<tuple<int, int, int>> pntall;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
pntall.emplace_back(points[i][j], j, i);
}
}
sort(pntall.rbegin(), pntall.rend());
// ↓ここからがAIの中身↓
while (kc.getGameInfo()) {
// ランダムにずらしつつ置けるだけおく
// 置いたものはランダムに8方向に動かす
// 画面外にはでない判定を追加(a1 → a2)
vector<Action> action;
const int offset = rnd(nagents);
for (int i = 0; i < nagents; i++) {
const Agent agent = kc.getAgent()[i];
if (agent.x == -1) {
const auto [point, x, y] = pntall[i + offset];
action.push_back({i, "PUT", x, y});
} else {
while (true) {
const auto [dx, dy] = DIR[rnd(8)];
const int x = agent.x + dx;
const int y = agent.y + dy;
if (x < 0 || x >= w || y < 0 || y >= h)
continue;
action.push_back({i, "MOVE", agent.x + dx, agent.y + dy});
break;
}
}
}
kc.setAction(action);
kc.waitNextTurn();
}
return 0;
}