dsh-eval-guard 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -13
- package/assets/commit0/instance.json +30 -0
- package/assets/commit0/workspace.zip +0 -0
- package/assets/featurebench/hidden/test_regression.py +690 -0
- package/assets/featurebench/instance.json +16 -0
- package/assets/featurebench/workspace.zip +0 -0
- package/assets/swe-bench-pro/hidden/test.patch +36 -0
- package/assets/swe-bench-pro/instance.json +10 -0
- package/assets/swe-bench-pro/workspace.zip +0 -0
- package/eval/README.md +18 -0
- package/eval/arena/arena/README.md +21 -0
- package/eval/arena/arena/bt.py +104 -0
- package/eval/arena/arena/clock.py +15 -0
- package/eval/arena/arena/core.py +265 -0
- package/eval/arena/arena/run.cmd +24 -0
- package/eval/arena/arena/run.sh +11 -0
- package/eval/arena/arena/schedule.py +79 -0
- package/eval/arena/arena/tournament.py +183 -0
- package/eval/arena/bomberman/bots/README.md +16 -0
- package/eval/arena/bomberman/bots/deepseek-v4.1-flash.cpp +447 -0
- package/eval/arena/bomberman/bots/doubao-seed-2.1.cpp +542 -0
- package/eval/arena/bomberman/bots/glm-5.3.cpp +406 -0
- package/eval/arena/bomberman/bots/gpt-6-astra.cpp +768 -0
- package/eval/arena/bomberman/bots/gpt-6-sol.cpp +444 -0
- package/eval/arena/bomberman/bots/kimi-k3.cpp +432 -0
- package/eval/arena/bomberman/bots/mimo-v2.6-pro.cpp +529 -0
- package/eval/arena/bomberman/bots/opus-5.5.cpp +548 -0
- package/eval/arena/bomberman/bots/qwen-3.8-max.cpp +836 -0
- package/eval/arena/bomberman/tournament/README.md +11 -0
- package/eval/arena/bomberman/tournament/bt.py +56 -0
- package/eval/arena/bomberman/tournament/evaluate.py +199 -0
- package/eval/arena/bomberman/tournament/run.py +79 -0
- package/eval/arena/bomberman/tournament/schedule-2to10.json.gz +0 -0
- package/eval/arena/bomberman/workspace/MANIFEST.json +13 -0
- package/eval/arena/bomberman/workspace/README.md +29 -0
- package/eval/arena/bomberman/workspace/RULES.md +100 -0
- package/eval/arena/bomberman/workspace/baseline.cpp +240 -0
- package/eval/arena/bomberman/workspace/clock.py +25 -0
- package/eval/arena/bomberman/workspace/engine/arena.py +198 -0
- package/eval/arena/bomberman/workspace/engine/build.py +35 -0
- package/eval/arena/bomberman/workspace/engine/engine.py +256 -0
- package/eval/arena/bomberman/workspace/engine/verify_replay.py +24 -0
- package/eval/arena/bomberman/workspace/run.cmd +28 -0
- package/eval/arena/bomberman/workspace/run.sh +16 -0
- package/eval/arena/bomberman/workspace/viewer/index.html +42 -0
- package/eval/arena/ctf/bots/README.md +18 -0
- package/eval/arena/ctf/bots/deepseek-v4.1-flash.cpp +601 -0
- package/eval/arena/ctf/bots/doubao-seed-2.1-turbo.cpp +320 -0
- package/eval/arena/ctf/bots/fable-5.1.cpp +634 -0
- package/eval/arena/ctf/bots/glm-5.3.cpp +689 -0
- package/eval/arena/ctf/bots/gpt-6-astra.cpp +657 -0
- package/eval/arena/ctf/bots/gpt-6.1-sol.cpp +725 -0
- package/eval/arena/ctf/bots/kimi-k3.cpp +667 -0
- package/eval/arena/ctf/bots/mimo-v2.6-pro.cpp +533 -0
- package/eval/arena/ctf/bots/opus-5.5.cpp +645 -0
- package/eval/arena/ctf/bots/qwen-3.8-max.cpp +726 -0
- package/eval/arena/ctf/bots/sonnet-5.5.cpp +569 -0
- package/eval/arena/ctf/tournament/README.md +15 -0
- package/eval/arena/ctf/tournament/formal-2to8.json +31 -0
- package/eval/arena/ctf/tournament/formal-9to15.json +31 -0
- package/eval/arena/ctf/workspace/README.md +41 -0
- package/eval/arena/ctf/workspace/RULES.md +119 -0
- package/eval/arena/ctf/workspace/arena.py +186 -0
- package/eval/arena/ctf/workspace/baseline.cpp +257 -0
- package/eval/arena/ctf/workspace/clock.py +15 -0
- package/eval/arena/ctf/workspace/core.py +265 -0
- package/eval/arena/ctf/workspace/engine.py +389 -0
- package/eval/arena/ctf/workspace/run.cmd +24 -0
- package/eval/arena/ctf/workspace/run.sh +11 -0
- package/eval/arena/ctf/workspace/viewer.html +71 -0
- package/eval/arena/land/bots/README.md +17 -0
- package/eval/arena/land/bots/deepseek-4.1f@workbuddy#1/bot.cpp +608 -0
- package/eval/arena/land/bots/glm-5.3@workbuddy#1/bot.cpp +521 -0
- package/eval/arena/land/bots/gpt-6-astra@codex#1/bot.cpp +373 -0
- package/eval/arena/land/bots/gpt-6-sol@codex#1/bot.cpp +341 -0
- package/eval/arena/land/bots/kimi-k3@workbuddy#1/bot.cpp +492 -0
- package/eval/arena/land/bots/mimo-2.6-pro@zcode#1/bot.cpp +652 -0
- package/eval/arena/land/bots/mystery-model@zcode#1/bot.cpp +466 -0
- package/eval/arena/land/bots/opus-5.5@claude-code#1/bot.cpp +630 -0
- package/eval/arena/land/bots/sonnet-5@claude-code#1/bot.cpp +619 -0
- package/eval/arena/land/tournament/make_replay_page.py +17 -0
- package/eval/arena/land/tournament/rate.py +290 -0
- package/eval/arena/land/tournament/round_robin.py +172 -0
- package/eval/arena/land/tournament/sparring.cpp +356 -0
- package/eval/arena/land/workspace/RULES.md +114 -0
- package/eval/arena/land/workspace/TASK.md +46 -0
- package/eval/arena/land/workspace/anchors/.build/greedy_f2e6d2dea5ca +0 -0
- package/eval/arena/land/workspace/anchors/greedy.cpp +194 -0
- package/eval/arena/land/workspace/anchors/random.cpp +80 -0
- package/eval/arena/land/workspace/clock.py +64 -0
- package/eval/arena/land/workspace/engine/build.py +33 -0
- package/eval/arena/land/workspace/engine/game.py +273 -0
- package/eval/arena/land/workspace/engine/referee.py +308 -0
- package/eval/arena/land/workspace/starter/.build/bot_be32b45b4699 +0 -0
- package/eval/arena/land/workspace/starter/bot.cpp +82 -0
- package/eval/arena/land/workspace/viewer/viewer.html +210 -0
- package/eval/arena/tank/bots/README.md +24 -0
- package/eval/arena/tank/bots/half1/deepseek-v4.1-flash.cpp +367 -0
- package/eval/arena/tank/bots/half1/doubao-seed-evolving.cpp +402 -0
- package/eval/arena/tank/bots/half1/gemini-4-argon.cpp +1132 -0
- package/eval/arena/tank/bots/half1/glm-5.3.cpp +551 -0
- package/eval/arena/tank/bots/half1/gpt-6-astra.cpp +233 -0
- package/eval/arena/tank/bots/half1/gpt-6.1-sol-ultrafast.cpp +350 -0
- package/eval/arena/tank/bots/half1/gpt-6.1-sol.cpp +78 -0
- package/eval/arena/tank/bots/half1/grok-4.7.cpp +1099 -0
- package/eval/arena/tank/bots/half1/haiku-5.5.cpp +210 -0
- package/eval/arena/tank/bots/half1/kimi-k3.cpp +353 -0
- package/eval/arena/tank/bots/half1/mimo-v2.6-pro.cpp +336 -0
- package/eval/arena/tank/bots/half1/muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/bots/half1/opus-5.5.cpp +435 -0
- package/eval/arena/tank/bots/half1/qwen-3.8-max.cpp +537 -0
- package/eval/arena/tank/bots/half2/deepseek-v4.1-flash.cpp +425 -0
- package/eval/arena/tank/bots/half2/doubao-seed-evolving.cpp +308 -0
- package/eval/arena/tank/bots/half2/gemini-4-argon.cpp +1390 -0
- package/eval/arena/tank/bots/half2/glm-5.3.cpp +651 -0
- package/eval/arena/tank/bots/half2/gpt-6-astra.cpp +241 -0
- package/eval/arena/tank/bots/half2/gpt-6.1-sol-ultrafast.cpp +356 -0
- package/eval/arena/tank/bots/half2/gpt-6.1-sol.cpp +87 -0
- package/eval/arena/tank/bots/half2/grok-4.7.cpp +1205 -0
- package/eval/arena/tank/bots/half2/haiku-5.5.cpp +210 -0
- package/eval/arena/tank/bots/half2/kimi-k3.cpp +487 -0
- package/eval/arena/tank/bots/half2/mimo-v2.6-pro.cpp +336 -0
- package/eval/arena/tank/bots/half2/muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/bots/half2/opus-5.5.cpp +476 -0
- package/eval/arena/tank/bots/half2/qwen-3.8-max.cpp +392 -0
- package/eval/arena/tank/tournament/README.md +24 -0
- package/eval/arena/tank/tournament/bt.py +218 -0
- package/eval/arena/tank/tournament/final.json +202 -0
- package/eval/arena/tank/tournament/halftime.json +146 -0
- package/eval/arena/tank/tournament/progress.json +911 -0
- package/eval/arena/tank/tournament/schedule.py +100 -0
- package/eval/arena/tank/tournament/sparring.cpp +928 -0
- package/eval/arena/tank/tournament/tournament.py +1426 -0
- package/eval/arena/tank/workspace/README.md +169 -0
- package/eval/arena/tank/workspace/RULES.md +443 -0
- package/eval/arena/tank/workspace/arena.py +862 -0
- package/eval/arena/tank/workspace/baseline.cpp +259 -0
- package/eval/arena/tank/workspace/clock.py +103 -0
- package/eval/arena/tank/workspace/core.py +712 -0
- package/eval/arena/tank/workspace/engine.py +573 -0
- package/eval/arena/tank/workspace/history/.lock +0 -0
- package/eval/arena/tank/workspace/history/20261017-193610-08715287f91f-bot.cpp +109 -0
- package/eval/arena/tank/workspace/history/20261017-193619-f00b2d5635fa-gpt-6-astra.cpp +241 -0
- package/eval/arena/tank/workspace/history/20261017-193643-63319e0a2b1a-gpt-6_1-sol-ultrafast.cpp +356 -0
- package/eval/arena/tank/workspace/history/20261017-193647-41c1341d0a8a-gemini-4-argon.cpp +1390 -0
- package/eval/arena/tank/workspace/history/20261017-193652-e34c0f45539a-gpt-6_1-sol.cpp +87 -0
- package/eval/arena/tank/workspace/history/20261017-193654-c026348ce96e-opus-5_5.cpp +476 -0
- package/eval/arena/tank/workspace/history/20261017-193655-4a21366e94d1-muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/workspace/history/20261017-193657-dbc4e9969c52-mimo-v2_6-pro.cpp +336 -0
- package/eval/arena/tank/workspace/history/20261017-193703-723cd036eb31-grok-4_7.cpp +1205 -0
- package/eval/arena/tank/workspace/history/20261017-193707-1ebbb227be68-deepseek-v4_1-flash.cpp +425 -0
- package/eval/arena/tank/workspace/history/20261017-193709-aeb0e7202ad5-doubao-seed-evolving.cpp +308 -0
- package/eval/arena/tank/workspace/history/20261017-193710-b21ebeb9bc76-kimi-k3.cpp +487 -0
- package/eval/arena/tank/workspace/history/20261017-193712-54cd86531905-haiku-5_5.cpp +210 -0
- package/eval/arena/tank/workspace/history/20261017-193714-efdb8e35c0bf-qwen-3_8-max.cpp +392 -0
- package/eval/arena/tank/workspace/history/20261017-193715-681423c23fdb-glm-5_3.cpp +651 -0
- package/eval/arena/tank/workspace/history/20261017-193717-1a8b3c75181d-sparring.cpp +928 -0
- package/eval/arena/tank/workspace/history/20261017-193720-1e0803a541e8-baseline.cpp +259 -0
- package/eval/arena/tank/workspace/history/log.jsonl +103 -0
- package/eval/arena/tank/workspace/judge/cycles.hpp +53 -0
- package/eval/arena/tank/workspace/judge/fast.cpp +337 -0
- package/eval/arena/tank/workspace/judge/referee.cpp +125 -0
- package/eval/arena/tank/workspace/judge/speed.cpp +99 -0
- package/eval/arena/tank/workspace/run.cmd +31 -0
- package/eval/arena/tank/workspace/run.sh +23 -0
- package/eval/arena/tank/workspace/tank.hpp +1762 -0
- package/eval/arena/tank/workspace/tank_main.cpp +215 -0
- package/eval/arena/tank/workspace/viewer.html +1150 -0
- package/eval/arena/warehouse/workspace/SPEC.md +130 -0
- package/eval/arena/warehouse/workspace/TASK.md +71 -0
- package/eval/arena/warehouse/workspace/baseline/common.h +88 -0
- package/eval/arena/warehouse/workspace/baseline/main.cpp +27 -0
- package/eval/arena/warehouse/workspace/baseline/old_stuff.cpp +87 -0
- package/eval/arena/warehouse/workspace/baseline/sim.cpp +427 -0
- package/eval/arena/warehouse/workspace/baseline/util.cpp +220 -0
- package/eval/arena/warehouse/workspace/clock.py +42 -0
- package/eval/arena/warehouse/workspace/src/common.h +88 -0
- package/eval/arena/warehouse/workspace/src/main.cpp +27 -0
- package/eval/arena/warehouse/workspace/src/old_stuff.cpp +87 -0
- package/eval/arena/warehouse/workspace/src/sim.cpp +427 -0
- package/eval/arena/warehouse/workspace/src/util.cpp +220 -0
- package/eval/arena/warehouse/workspace/tools/bench.py +119 -0
- package/eval/arena/warehouse/workspace/tools/check_input.py +161 -0
- package/eval/arena/warehouse/workspace/tools/gen.py +132 -0
- package/eval/arena/warehouse/workspace/tools/measure.py +107 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.in +1420 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.out +9162 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.in +1465 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.out +3439 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_flood.in +2757 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_flood.out +3126 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_small.in +731 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_small.out +2578 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_wide.in +528 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_wide.out +2026 -0
- package/eval/bomberman.py +20 -0
- package/eval/commit0.py +21 -0
- package/eval/common.py +61 -0
- package/eval/ctf.py +20 -0
- package/eval/featurebench.py +25 -0
- package/eval/land.py +20 -0
- package/eval/legacy/bomberman-prices.json +4 -0
- package/eval/legacy/bomberman.py +161 -0
- package/eval/legacy/commit0.py +91 -0
- package/eval/legacy/ctf-prices.json +4 -0
- package/eval/legacy/ctf.py +178 -0
- package/eval/legacy/featurebench.py +103 -0
- package/eval/legacy/land-prices.json +4 -0
- package/eval/legacy/land.py +177 -0
- package/eval/legacy/swe_bench_pro.py +116 -0
- package/eval/legacy/tank-prices.json +3 -0
- package/eval/legacy/tank.py +408 -0
- package/eval/legacy/warehouse-prices.json +4 -0
- package/eval/legacy/warehouse.py +365 -0
- package/eval/swe-bench-pro.py +25 -0
- package/eval/tank.py +20 -0
- package/eval/warehouse.py +20 -0
- package/lib/client/index.js +376 -63
- package/lib/client/index.js.map +1 -1
- package/lib/index.js +684 -27
- package/package.json +2 -1
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
// Territory bot: plan-based rectangle loop capture with dynamic cut-race safety.
|
|
2
|
+
// Duel (N=2) and melee (N=4) capable.
|
|
3
|
+
#include <bits/stdc++.h>
|
|
4
|
+
using namespace std;
|
|
5
|
+
|
|
6
|
+
const int DX[4] = {0, 0, -1, 1};
|
|
7
|
+
const int DY[4] = {-1, 1, 0, 0};
|
|
8
|
+
const char DC[4] = {'U', 'D', 'L', 'R'};
|
|
9
|
+
const int INF = 1000000000;
|
|
10
|
+
|
|
11
|
+
int W, H, MAX_TURNS, N, ME;
|
|
12
|
+
|
|
13
|
+
struct Player { int x, y, dir, trailLen, area, deaths; };
|
|
14
|
+
Player pl[4];
|
|
15
|
+
int curTurn = 0;
|
|
16
|
+
vector<int8_t> owner, trailg, prot;
|
|
17
|
+
int lastX[4], lastY[4], staticTurns[4];
|
|
18
|
+
bool haveLast = false;
|
|
19
|
+
|
|
20
|
+
deque<int> plan;
|
|
21
|
+
bool wasOutside = false;
|
|
22
|
+
int huntE = -1, huntK = -1; // active hunt target (enemy id, cell)
|
|
23
|
+
int spawnX[4], spawnY[4];
|
|
24
|
+
mt19937 rng(0xC0FFEE);
|
|
25
|
+
|
|
26
|
+
inline bool inb(int x, int y) { return x >= 0 && x < W && y >= 0 && y < H; }
|
|
27
|
+
inline int id(int x, int y) { return y * W + x; }
|
|
28
|
+
inline int opp(int d) { return d ^ 1; }
|
|
29
|
+
|
|
30
|
+
bool readState() {
|
|
31
|
+
string tok;
|
|
32
|
+
if (!(cin >> tok)) return false;
|
|
33
|
+
cin >> curTurn;
|
|
34
|
+
for (int i = 0; i < N; i++) {
|
|
35
|
+
int idn; char d;
|
|
36
|
+
cin >> tok >> idn >> pl[idn].x >> pl[idn].y >> d >> pl[idn].trailLen >> pl[idn].area >> pl[idn].deaths;
|
|
37
|
+
pl[idn].dir = (int)string("UDLR").find(d);
|
|
38
|
+
}
|
|
39
|
+
cin >> tok; // OWNER
|
|
40
|
+
owner.assign(W * H, -1);
|
|
41
|
+
{
|
|
42
|
+
string row;
|
|
43
|
+
for (int y = 0; y < H; y++) {
|
|
44
|
+
cin >> row;
|
|
45
|
+
for (int x = 0; x < W; x++) owner[id(x, y)] = (row[x] == '.') ? (int8_t)-1 : (int8_t)(row[x] - '0');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
cin >> tok; // TRAIL
|
|
49
|
+
trailg.assign(W * H, -1);
|
|
50
|
+
{
|
|
51
|
+
string row;
|
|
52
|
+
for (int y = 0; y < H; y++) {
|
|
53
|
+
cin >> row;
|
|
54
|
+
for (int x = 0; x < W; x++) trailg[id(x, y)] = (row[x] == '.') ? (int8_t)-1 : (int8_t)(row[x] - '0');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
cin >> tok; // END
|
|
58
|
+
if (!haveLast) {
|
|
59
|
+
for (int i = 0; i < N; i++) { lastX[i] = pl[i].x; lastY[i] = pl[i].y; staticTurns[i] = 0; }
|
|
60
|
+
haveLast = true;
|
|
61
|
+
} else {
|
|
62
|
+
for (int i = 0; i < N; i++) {
|
|
63
|
+
if (pl[i].x == lastX[i] && pl[i].y == lastY[i]) staticTurns[i]++;
|
|
64
|
+
else { staticTurns[i] = 0; lastX[i] = pl[i].x; lastY[i] = pl[i].y; }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// BFS distance field from (sx,sy); blocked(k) = cannot enter cell k.
|
|
71
|
+
template <class Block>
|
|
72
|
+
vector<int> bfsFrom(int sx, int sy, Block blocked) {
|
|
73
|
+
vector<int> dist(W * H, -1);
|
|
74
|
+
if (!inb(sx, sy)) return dist;
|
|
75
|
+
int s = id(sx, sy);
|
|
76
|
+
dist[s] = 0;
|
|
77
|
+
deque<int> q; q.push_back(s);
|
|
78
|
+
while (!q.empty()) {
|
|
79
|
+
int k = q.front(); q.pop_front();
|
|
80
|
+
int x = k % W, y = k / W;
|
|
81
|
+
for (int d = 0; d < 4; d++) {
|
|
82
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
83
|
+
if (!inb(nx, ny)) continue;
|
|
84
|
+
int nk = id(nx, ny);
|
|
85
|
+
if (dist[nk] != -1 || blocked(nk)) continue;
|
|
86
|
+
dist[nk] = dist[k] + 1;
|
|
87
|
+
q.push_back(nk);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return dist;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Shortest path (dirs) from head to first popped cell satisfying goal; first step cannot reverse.
|
|
94
|
+
template <class Goal, class Block>
|
|
95
|
+
vector<int> bfsPath(int sx, int sy, int curdir, Goal goal, Block blocked) {
|
|
96
|
+
vector<int> par(W * H, -1), pdir(W * H, -1);
|
|
97
|
+
int s = id(sx, sy);
|
|
98
|
+
par[s] = s;
|
|
99
|
+
deque<int> q;
|
|
100
|
+
for (int d = 0; d < 4; d++) {
|
|
101
|
+
if (d == opp(curdir)) continue;
|
|
102
|
+
int nx = sx + DX[d], ny = sy + DY[d];
|
|
103
|
+
if (!inb(nx, ny)) continue;
|
|
104
|
+
int nk = id(nx, ny);
|
|
105
|
+
if (blocked(nk)) continue;
|
|
106
|
+
if (par[nk] != -1) continue;
|
|
107
|
+
par[nk] = s; pdir[nk] = d; q.push_back(nk);
|
|
108
|
+
}
|
|
109
|
+
while (!q.empty()) {
|
|
110
|
+
int k = q.front(); q.pop_front();
|
|
111
|
+
if (goal(k)) {
|
|
112
|
+
vector<int> path;
|
|
113
|
+
for (int c = k; c != s; c = par[c]) path.push_back(pdir[c]);
|
|
114
|
+
reverse(path.begin(), path.end());
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
int x = k % W, y = k / W;
|
|
118
|
+
for (int d = 0; d < 4; d++) {
|
|
119
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
120
|
+
if (!inb(nx, ny)) continue;
|
|
121
|
+
int nk = id(nx, ny);
|
|
122
|
+
if (par[nk] != -1 || blocked(nk)) continue;
|
|
123
|
+
par[nk] = k; pdir[nk] = d; q.push_back(nk);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int anySafeMove(int x, int y, int curdir) {
|
|
130
|
+
int best = -1, bestScore = -1;
|
|
131
|
+
for (int d = 0; d < 4; d++) {
|
|
132
|
+
if (d == opp(curdir)) continue;
|
|
133
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
134
|
+
if (!inb(nx, ny)) continue;
|
|
135
|
+
if (trailg[id(nx, ny)] == ME) continue;
|
|
136
|
+
int sc = (d == curdir) ? 2 : 0;
|
|
137
|
+
for (int e = 0; e < 4; e++) {
|
|
138
|
+
int ox = nx + DX[e], oy = ny + DY[e];
|
|
139
|
+
if (inb(ox, oy) && trailg[id(ox, oy)] != ME) sc++;
|
|
140
|
+
}
|
|
141
|
+
if (sc > bestScore) { bestScore = sc; best = d; }
|
|
142
|
+
}
|
|
143
|
+
return best >= 0 ? best : curdir;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
void makePlan() {
|
|
147
|
+
Player& me = pl[ME];
|
|
148
|
+
int remaining = MAX_TURNS - curTurn;
|
|
149
|
+
int s = id(me.x, me.y);
|
|
150
|
+
// parent BFS from head, first step no reverse, no blocks (we are inside, trail empty)
|
|
151
|
+
vector<int> par(W * H, -1), pdirv(W * H, -1), distH(W * H, -1);
|
|
152
|
+
par[s] = s; distH[s] = 0;
|
|
153
|
+
deque<int> q;
|
|
154
|
+
for (int d = 0; d < 4; d++) {
|
|
155
|
+
if (d == opp(me.dir)) continue;
|
|
156
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
157
|
+
if (!inb(nx, ny)) continue;
|
|
158
|
+
int nk = id(nx, ny);
|
|
159
|
+
if (par[nk] != -1) continue;
|
|
160
|
+
par[nk] = s; pdirv[nk] = d; q.push_back(nk);
|
|
161
|
+
}
|
|
162
|
+
while (!q.empty()) {
|
|
163
|
+
int k = q.front(); q.pop_front();
|
|
164
|
+
distH[k] = distH[par[k]] + 1;
|
|
165
|
+
int x = k % W, y = k / W;
|
|
166
|
+
for (int d = 0; d < 4; d++) {
|
|
167
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
168
|
+
if (!inb(nx, ny)) continue;
|
|
169
|
+
int nk = id(nx, ny);
|
|
170
|
+
if (par[nk] != -1) continue;
|
|
171
|
+
par[nk] = k; pdirv[nk] = d; q.push_back(nk);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// enemy threat fields (blocked by their own trail: entering own trail kills them)
|
|
175
|
+
vector<vector<int>> ef(N);
|
|
176
|
+
for (int e = 0; e < N; e++) {
|
|
177
|
+
if (e == ME || staticTurns[e] >= 40) continue;
|
|
178
|
+
ef[e] = bfsFrom(pl[e].x, pl[e].y, [&](int k) { return trailg[k] == (int8_t)e; });
|
|
179
|
+
}
|
|
180
|
+
auto enemyAt = [&](int k) {
|
|
181
|
+
int m = INF;
|
|
182
|
+
for (int e = 0; e < N; e++) {
|
|
183
|
+
if (e == ME || staticTurns[e] >= 40) continue;
|
|
184
|
+
if (ef[e][k] >= 0) m = min(m, ef[e][k]);
|
|
185
|
+
}
|
|
186
|
+
return m;
|
|
187
|
+
};
|
|
188
|
+
// prefix sums: neutral gainable, enemy gainable (excl. protected)
|
|
189
|
+
vector<int> pN((W + 1) * (H + 1), 0), pE((W + 1) * (H + 1), 0);
|
|
190
|
+
for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) {
|
|
191
|
+
int k = id(x, y), o = owner[k];
|
|
192
|
+
int cN = (o == -1) ? 1 : 0;
|
|
193
|
+
int cE = (o != -1 && o != ME && (int)prot[k] != o) ? 1 : 0;
|
|
194
|
+
int r = (y + 1) * (W + 1) + (x + 1);
|
|
195
|
+
pN[r] = pN[r - 1] + pN[r - (W + 1)] - pN[r - (W + 1) - 1] + cN;
|
|
196
|
+
pE[r] = pE[r - 1] + pE[r - (W + 1)] - pE[r - (W + 1) - 1] + cE;
|
|
197
|
+
}
|
|
198
|
+
auto rectN = [&](int x0, int y0, int x1, int y1) {
|
|
199
|
+
return pN[(y1 + 1) * (W + 1) + x1 + 1] - pN[y0 * (W + 1) + x1 + 1]
|
|
200
|
+
- pN[(y1 + 1) * (W + 1) + x0] + pN[y0 * (W + 1) + x0];
|
|
201
|
+
};
|
|
202
|
+
auto rectE = [&](int x0, int y0, int x1, int y1) {
|
|
203
|
+
return pE[(y1 + 1) * (W + 1) + x1 + 1] - pE[y0 * (W + 1) + x1 + 1]
|
|
204
|
+
- pE[(y1 + 1) * (W + 1) + x0] + pE[y0 * (W + 1) + x0];
|
|
205
|
+
};
|
|
206
|
+
// exit candidates: non-mine cells adjacent to my territory
|
|
207
|
+
vector<int> exits;
|
|
208
|
+
for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) {
|
|
209
|
+
int k = id(x, y);
|
|
210
|
+
if (owner[k] == ME) continue;
|
|
211
|
+
for (int d = 0; d < 4; d++) {
|
|
212
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
213
|
+
if (inb(nx, ny) && owner[id(nx, ny)] == ME) { exits.push_back(k); break; }
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
shuffle(exits.begin(), exits.end(), rng);
|
|
217
|
+
if ((int)exits.size() > 40) exits.resize(40);
|
|
218
|
+
|
|
219
|
+
const int maxTrail = (N == 2) ? 52 : 28;
|
|
220
|
+
const int safetyMargin = (N == 2) ? 0 : 4;
|
|
221
|
+
const int amax = 16, bmax = 16;
|
|
222
|
+
|
|
223
|
+
double bestScore = 0.0;
|
|
224
|
+
vector<int> bestPlan;
|
|
225
|
+
|
|
226
|
+
for (int E : exits) {
|
|
227
|
+
int ex = E % W, ey = E / W;
|
|
228
|
+
int Tk = -1, d0 = -1, distT = -1;
|
|
229
|
+
vector<int> pathT;
|
|
230
|
+
for (int d = 0; d < 4 && d0 < 0; d++) {
|
|
231
|
+
int tx = ex - DX[d], ty = ey - DY[d]; // T + dir d -> E
|
|
232
|
+
if (!inb(tx, ty)) continue;
|
|
233
|
+
int tk = id(tx, ty);
|
|
234
|
+
if (owner[tk] != ME || par[tk] == -1) continue;
|
|
235
|
+
int lastdir = (tk == s) ? me.dir : pdirv[tk];
|
|
236
|
+
if (d == opp(lastdir)) continue;
|
|
237
|
+
d0 = d; Tk = tk; distT = distH[tk];
|
|
238
|
+
vector<int> p;
|
|
239
|
+
for (int c = tk; c != s; c = par[c]) p.push_back(pdirv[c]);
|
|
240
|
+
reverse(p.begin(), p.end());
|
|
241
|
+
pathT = p;
|
|
242
|
+
}
|
|
243
|
+
if (d0 < 0 || distT > 22) continue;
|
|
244
|
+
for (int si = 0; si < 2; si++) {
|
|
245
|
+
int sd = (d0 < 2) ? (2 + si) : si;
|
|
246
|
+
int cx = DX[d0], cy = DY[d0], vx = DX[sd], vy = DY[sd];
|
|
247
|
+
|
|
248
|
+
// ---- U-shaped loop: territory border acts as the 4th side ----
|
|
249
|
+
// territory side cells: E - d0 + j*s (j=0..b) must all be mine
|
|
250
|
+
int maxB = 0;
|
|
251
|
+
while (maxB < bmax) {
|
|
252
|
+
int px = ex - cx + (maxB + 1) * vx, py = ey - cy + (maxB + 1) * vy;
|
|
253
|
+
if (!inb(px, py) || owner[id(px, py)] != ME) break;
|
|
254
|
+
maxB++;
|
|
255
|
+
}
|
|
256
|
+
for (int a = 1; a <= amax; a++) {
|
|
257
|
+
for (int b = 1; b <= maxB; b++) {
|
|
258
|
+
int steps = distT + 2 * a + b + 2; // total moves incl. capture step
|
|
259
|
+
if (steps + 3 > remaining) continue;
|
|
260
|
+
// box bounds: i=0..a (d0 axis), j=0..b (s axis) from E
|
|
261
|
+
int xA = ex + a * cx, yA = ey + a * cy;
|
|
262
|
+
int xB2 = ex + b * vx, yB2 = ey + b * vy;
|
|
263
|
+
int x0 = min(min(ex, xA), xB2), x1 = max(max(ex, xA), xB2);
|
|
264
|
+
int y0 = min(min(ey, yA), yB2), y1 = max(max(ey, yA), yB2);
|
|
265
|
+
// full box corner for gain: E + a*d0 + b*s
|
|
266
|
+
int xC = ex + a * cx + b * vx, yC = ey + a * cy + b * vy;
|
|
267
|
+
x0 = min(x0, min(ex, xC)); x1 = max(x1, max(ex, xC));
|
|
268
|
+
y0 = min(y0, min(ey, yC)); y1 = max(y1, max(ey, yC));
|
|
269
|
+
if (x0 < 0 || y0 < 0 || x1 >= W || y1 >= H) continue;
|
|
270
|
+
// walk path cells: leg1 (j=0, i=0..a), leg2 (i=a, j=1..b), leg3 (j=b, i=a-1..0)
|
|
271
|
+
int trailCount = 0;
|
|
272
|
+
int minEnemy = INF;
|
|
273
|
+
bool pathOk = true;
|
|
274
|
+
auto chk = [&](int px, int py) {
|
|
275
|
+
int k = id(px, py);
|
|
276
|
+
if (owner[k] == ME) { pathOk = false; return; }
|
|
277
|
+
trailCount++;
|
|
278
|
+
minEnemy = min(minEnemy, enemyAt(k));
|
|
279
|
+
};
|
|
280
|
+
for (int i = 0; i <= a; i++) chk(ex + i * cx, ey + i * cy);
|
|
281
|
+
if (!pathOk) break; // bigger a only adds more of the same
|
|
282
|
+
for (int j = 1; j <= b; j++) chk(ex + a * cx + j * vx, ey + a * cy + j * vy);
|
|
283
|
+
if (!pathOk) continue;
|
|
284
|
+
for (int i = a - 1; i >= 0; i--) chk(ex + i * cx + b * vx, ey + i * cy + b * vy);
|
|
285
|
+
if (!pathOk) continue;
|
|
286
|
+
int need = steps;
|
|
287
|
+
int slackOk = (N == 2) ? 8 : 2;
|
|
288
|
+
if (minEnemy < 4 || minEnemy < need - slackOk) continue;
|
|
289
|
+
if (trailCount > maxTrail) continue;
|
|
290
|
+
double gain = rectN(x0, y0, x1, y1) + 2.0 * rectE(x0, y0, x1, y1);
|
|
291
|
+
if (gain < 3.0) continue;
|
|
292
|
+
double score = gain - 0.12 * steps
|
|
293
|
+
+ 0.5 * (double)max(0, minEnemy - need)
|
|
294
|
+
+ (double)(rng() % 1000) * 1e-6 + 0.001;
|
|
295
|
+
if (score > bestScore) {
|
|
296
|
+
bestScore = score;
|
|
297
|
+
bestPlan = pathT;
|
|
298
|
+
bestPlan.push_back(d0); // T -> E
|
|
299
|
+
for (int i = 0; i < a; i++) bestPlan.push_back(d0);
|
|
300
|
+
for (int j = 0; j < b; j++) bestPlan.push_back(sd);
|
|
301
|
+
for (int i = 0; i < a; i++) bestPlan.push_back(opp(d0));
|
|
302
|
+
// now at E + b*s ; step into territory
|
|
303
|
+
bestPlan.push_back(opp(d0));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ---- closed rectangle loop ----
|
|
309
|
+
for (int a = 2; a <= amax; a++) {
|
|
310
|
+
for (int b = 2; b <= bmax; b++) {
|
|
311
|
+
int L = 2 * (a + b);
|
|
312
|
+
int cost = distT + L + 2;
|
|
313
|
+
if (cost + 3 > remaining) continue;
|
|
314
|
+
int xB = ex + a * cx + b * vx, yB = ey + a * cy + b * vy;
|
|
315
|
+
int x0 = min(ex, xB), x1 = max(ex, xB), y0 = min(ey, yB), y1 = max(ey, yB);
|
|
316
|
+
if (x0 < 0 || y0 < 0 || x1 >= W || y1 >= H) continue;
|
|
317
|
+
int trailCount = 0;
|
|
318
|
+
int minEnemy = INF;
|
|
319
|
+
auto chk = [&](int px, int py) {
|
|
320
|
+
int k = id(px, py);
|
|
321
|
+
if (owner[k] != ME) trailCount++;
|
|
322
|
+
minEnemy = min(minEnemy, enemyAt(k));
|
|
323
|
+
};
|
|
324
|
+
for (int i = 0; i <= a; i++) chk(ex + i * cx, ey + i * cy);
|
|
325
|
+
for (int j = 1; j <= b; j++) chk(ex + a * cx + j * vx, ey + a * cy + j * vy);
|
|
326
|
+
for (int i = 1; i <= a; i++) chk(ex + (a - i) * cx + b * vx, ey + (a - i) * cy + b * vy);
|
|
327
|
+
for (int j = 1; j < b; j++) chk(ex + (b - j) * vx, ey + (b - j) * vy);
|
|
328
|
+
if (trailCount > maxTrail || trailCount == 0) continue;
|
|
329
|
+
double gain = rectN(x0, y0, x1, y1) + 2.0 * rectE(x0, y0, x1, y1);
|
|
330
|
+
if (gain < 3.0) continue;
|
|
331
|
+
int need = distT + L + 2;
|
|
332
|
+
int slackOk = (N == 2) ? 8 : 2;
|
|
333
|
+
if (minEnemy < 4 || minEnemy < need - slackOk) continue;
|
|
334
|
+
double score = gain - 0.12 * cost
|
|
335
|
+
+ 0.5 * (double)max(0, minEnemy - need)
|
|
336
|
+
+ (double)(rng() % 1000) * 1e-6;
|
|
337
|
+
if (score > bestScore) {
|
|
338
|
+
bestScore = score;
|
|
339
|
+
bestPlan = pathT;
|
|
340
|
+
bestPlan.push_back(d0); // T -> E
|
|
341
|
+
for (int i = 0; i < a; i++) bestPlan.push_back(d0);
|
|
342
|
+
for (int j = 0; j < b; j++) bestPlan.push_back(sd);
|
|
343
|
+
for (int i = 0; i < a; i++) bestPlan.push_back(opp(d0));
|
|
344
|
+
for (int j = 0; j < b; j++) bestPlan.push_back(opp(sd));
|
|
345
|
+
bestPlan.push_back(opp(d0)); // E -> T : capture
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (!bestPlan.empty()) {
|
|
352
|
+
plan.assign(bestPlan.begin(), bestPlan.end());
|
|
353
|
+
fprintf(stderr, "T%d PLAN len=%zu score=%.3f\n", curTurn, plan.size(), bestScore);
|
|
354
|
+
} else {
|
|
355
|
+
fprintf(stderr, "T%d NOPLAN exits=%zu\n", curTurn, exits.size());
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
int decide() {
|
|
360
|
+
Player& me = pl[ME];
|
|
361
|
+
int hx = me.x, hy = me.y, hd = me.dir;
|
|
362
|
+
int hk = id(hx, hy);
|
|
363
|
+
bool inside = (owner[hk] == ME);
|
|
364
|
+
int remaining = MAX_TURNS - curTurn;
|
|
365
|
+
|
|
366
|
+
if (inside && wasOutside) plan.clear(); // captured or respawned
|
|
367
|
+
wasOutside = !inside;
|
|
368
|
+
|
|
369
|
+
// invalidate stale hunt target
|
|
370
|
+
if (huntE >= 0 && (plan.empty() || trailg[huntK] != (int8_t)huntE)) {
|
|
371
|
+
if (!plan.empty()) plan.clear();
|
|
372
|
+
huntE = -1;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
auto validMove = [&](int d) {
|
|
376
|
+
if (d == opp(hd)) return false;
|
|
377
|
+
int nx = hx + DX[d], ny = hy + DY[d];
|
|
378
|
+
return inb(nx, ny) && trailg[id(nx, ny)] != ME;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// A. immediate adjacent cut of an enemy trail (entering it kills its owner)
|
|
382
|
+
for (int d = 0; d < 4; d++) {
|
|
383
|
+
if (!validMove(d)) continue;
|
|
384
|
+
int nk = id(hx + DX[d], hy + DY[d]);
|
|
385
|
+
int e = trailg[nk];
|
|
386
|
+
if (e >= 0 && e != ME && pl[e].trailLen >= 2) {
|
|
387
|
+
bool ok = true;
|
|
388
|
+
if (N > 2) {
|
|
389
|
+
for (int o = 0; o < N && ok; o++) {
|
|
390
|
+
if (o == ME || o == e || staticTurns[o] >= 40) continue;
|
|
391
|
+
if (abs(pl[o].x - (hx + DX[d])) + abs(pl[o].y - (hy + DY[d])) < 8) ok = false;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (ok) { plan.clear(); return d; }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (!inside) {
|
|
399
|
+
vector<int> home = bfsPath(hx, hy, hd, [&](int k) { return owner[k] == ME; },
|
|
400
|
+
[&](int k) { return trailg[k] == ME; });
|
|
401
|
+
if (home.empty()) return anySafeMove(hx, hy, hd);
|
|
402
|
+
int homeDist = (int)home.size();
|
|
403
|
+
vector<int> myf = bfsFrom(hx, hy, [&](int k) { return trailg[k] == ME; });
|
|
404
|
+
int minThreat = INF;
|
|
405
|
+
int bestCut = INF, cutE = -1;
|
|
406
|
+
for (int e = 0; e < N; e++) {
|
|
407
|
+
if (e == ME || staticTurns[e] >= 40) continue;
|
|
408
|
+
vector<int> ef = bfsFrom(pl[e].x, pl[e].y, [&](int k) { return trailg[k] == (int8_t)e; });
|
|
409
|
+
int t = INF;
|
|
410
|
+
for (int k = 0; k < W * H; k++)
|
|
411
|
+
if (trailg[k] == ME && ef[k] >= 0 && ef[k] < t) t = ef[k];
|
|
412
|
+
minThreat = min(minThreat, t);
|
|
413
|
+
if (pl[e].trailLen > 0) {
|
|
414
|
+
int c = INF;
|
|
415
|
+
for (int k = 0; k < W * H; k++)
|
|
416
|
+
if (trailg[k] == (int8_t)e && myf[k] >= 0 && myf[k] < c) c = myf[k];
|
|
417
|
+
if (c < bestCut) { bestCut = c; cutE = e; }
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
int margin = (minThreat == INF) ? INF : minThreat - homeDist;
|
|
421
|
+
int retreatAt = (N == 2) ? 1 : 2;
|
|
422
|
+
if (margin <= retreatAt) {
|
|
423
|
+
fprintf(stderr, "T%d DANGER margin=%d home=%d threat=%d planlen=%zu\n", curTurn, margin, homeDist, minThreat, plan.size());
|
|
424
|
+
// counter-cut if the race is clearly won
|
|
425
|
+
if (cutE >= 0 && bestCut <= 25 && bestCut + 1 <= minThreat) {
|
|
426
|
+
vector<int> cp = bfsPath(hx, hy, hd, [&](int k) { return trailg[k] == (int8_t)cutE; },
|
|
427
|
+
[&](int k) { return trailg[k] == ME; });
|
|
428
|
+
if (!cp.empty() && (int)cp.size() + 1 <= minThreat) { plan.clear(); return cp[0]; }
|
|
429
|
+
}
|
|
430
|
+
// if we cannot outrun them anyway, race to complete the loop instead of retreating
|
|
431
|
+
if (margin < 0 && !plan.empty()) {
|
|
432
|
+
int d = plan.front();
|
|
433
|
+
if (validMove(d)) { plan.pop_front(); return d; }
|
|
434
|
+
}
|
|
435
|
+
plan.clear();
|
|
436
|
+
return home[0]; // bank what we can
|
|
437
|
+
}
|
|
438
|
+
// endgame: make sure we capture before the clock runs out
|
|
439
|
+
if ((int)plan.size() + 1 > remaining || homeDist + 2 > remaining) {
|
|
440
|
+
plan.clear();
|
|
441
|
+
return home[0];
|
|
442
|
+
}
|
|
443
|
+
if (!plan.empty()) {
|
|
444
|
+
int d = plan.front();
|
|
445
|
+
if (validMove(d)) { plan.pop_front(); return d; }
|
|
446
|
+
plan.clear();
|
|
447
|
+
}
|
|
448
|
+
return home[0];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// inside
|
|
452
|
+
// hunt: walk out and cut a nearby enemy trail (we have no trail => low risk)
|
|
453
|
+
if (plan.empty() && huntE < 0) {
|
|
454
|
+
int maxHunt = (N == 2) ? 15 : 11;
|
|
455
|
+
int minLen = (N == 2) ? 10 : 8;
|
|
456
|
+
vector<int> hp;
|
|
457
|
+
int bd = INF;
|
|
458
|
+
for (int e = 0; e < N; e++) {
|
|
459
|
+
if (e == ME || staticTurns[e] >= 40 || pl[e].trailLen < minLen) continue;
|
|
460
|
+
// melee: skip if some other enemy is close to us
|
|
461
|
+
if (N > 2) {
|
|
462
|
+
bool crowded = false;
|
|
463
|
+
for (int o = 0; o < N; o++) {
|
|
464
|
+
if (o == ME || o == e || staticTurns[o] >= 40) continue;
|
|
465
|
+
if (abs(pl[o].x - hx) + abs(pl[o].y - hy) < 6) crowded = true;
|
|
466
|
+
}
|
|
467
|
+
if (crowded) continue;
|
|
468
|
+
}
|
|
469
|
+
vector<int> p = bfsPath(hx, hy, hd, [&](int k) { return trailg[k] == (int8_t)e; },
|
|
470
|
+
[&](int k) { return false; });
|
|
471
|
+
if (p.empty() || (int)p.size() > maxHunt) continue;
|
|
472
|
+
int tx = hx, ty = hy;
|
|
473
|
+
for (int d : p) { tx += DX[d]; ty += DY[d]; }
|
|
474
|
+
if (abs(tx - spawnX[e]) <= 3 && abs(ty - spawnY[e]) <= 3) continue; // pointless kill near their spawn
|
|
475
|
+
if ((int)p.size() < bd) { bd = (int)p.size(); hp = p; huntE = e; huntK = id(tx, ty); }
|
|
476
|
+
}
|
|
477
|
+
if (!hp.empty()) {
|
|
478
|
+
plan.assign(hp.begin(), hp.end());
|
|
479
|
+
fprintf(stderr, "T%d HUNT e=%d dist=%d\n", curTurn, huntE, bd);
|
|
480
|
+
int d = plan.front(); plan.pop_front();
|
|
481
|
+
return d;
|
|
482
|
+
}
|
|
483
|
+
huntE = -1;
|
|
484
|
+
}
|
|
485
|
+
if (plan.empty() && remaining > 12) makePlan();
|
|
486
|
+
if (!plan.empty()) {
|
|
487
|
+
int d = plan.front();
|
|
488
|
+
if (validMove(d)) { plan.pop_front(); return d; }
|
|
489
|
+
plan.clear();
|
|
490
|
+
}
|
|
491
|
+
// patrol inside territory
|
|
492
|
+
if (validMove(hd) && owner[id(hx + DX[hd], hy + DY[hd])] == ME) return hd;
|
|
493
|
+
for (int d = 0; d < 4; d++) {
|
|
494
|
+
if (!validMove(d)) continue;
|
|
495
|
+
if (owner[id(hx + DX[d], hy + DY[d])] == ME) return d;
|
|
496
|
+
}
|
|
497
|
+
return anySafeMove(hx, hy, hd);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
int main() {
|
|
501
|
+
ios::sync_with_stdio(false);
|
|
502
|
+
cin.tie(nullptr);
|
|
503
|
+
string tok;
|
|
504
|
+
int mv, im;
|
|
505
|
+
cin >> tok; // INIT
|
|
506
|
+
cin >> W >> H >> MAX_TURNS >> N >> ME >> mv >> im;
|
|
507
|
+
prot.assign(W * H, -1);
|
|
508
|
+
for (int i = 0; i < N; i++) {
|
|
509
|
+
int idn, x, y;
|
|
510
|
+
cin >> tok >> idn >> x >> y;
|
|
511
|
+
spawnX[idn] = x; spawnY[idn] = y;
|
|
512
|
+
for (int dy = -1; dy <= 1; dy++)
|
|
513
|
+
for (int dx = -1; dx <= 1; dx++)
|
|
514
|
+
if (inb(x + dx, y + dy)) prot[id(x + dx, y + dy)] = idn;
|
|
515
|
+
}
|
|
516
|
+
while (readState()) {
|
|
517
|
+
int d = decide();
|
|
518
|
+
cout << curTurn << ' ' << DC[d] << endl;
|
|
519
|
+
}
|
|
520
|
+
return 0;
|
|
521
|
+
}
|