dsh-eval-guard 0.2.3 → 0.3.1
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,608 @@
|
|
|
1
|
+
// Territory game bot.
|
|
2
|
+
//
|
|
3
|
+
// Core idea
|
|
4
|
+
// ---------
|
|
5
|
+
// `Game._enclosed(i)` floods inward from every *border* cell that is not a wall,
|
|
6
|
+
// where a wall is any cell owned by i or carrying i's trail. If EVERY border
|
|
7
|
+
// cell is a wall, the flood has no seed at all, so `enclosed` degenerates to
|
|
8
|
+
// "every non-wall cell on the board". Capturing then hands over the whole map
|
|
9
|
+
// (minus opponents' protected squares).
|
|
10
|
+
//
|
|
11
|
+
// So every strong plan is: walk out, lay a wall along a stretch of the border,
|
|
12
|
+
// come back home. The longer the wall the more we take - but the longer our
|
|
13
|
+
// trail lives, and ANY opponent head stepping on it kills us. So the bot
|
|
14
|
+
// enumerates a handful of candidate loops (a full lap, four half-plane
|
|
15
|
+
// sweeps, and a generic "close the remaining gap in the ring" route),
|
|
16
|
+
// simulates the exact capture for each, and picks the best
|
|
17
|
+
// gain / (length x length-penalty).
|
|
18
|
+
#include <bits/stdc++.h>
|
|
19
|
+
using namespace std;
|
|
20
|
+
|
|
21
|
+
static const int DX[4] = {0, 0, -1, 1}; // U D L R
|
|
22
|
+
static const int DY[4] = {-1, 1, 0, 0};
|
|
23
|
+
static const char DC[4] = {'U', 'D', 'L', 'R'};
|
|
24
|
+
static inline int oppd(int d) { return d ^ 1; }
|
|
25
|
+
|
|
26
|
+
int W, H, MAXT, N, ME, MOVE_MS, INIT_MS;
|
|
27
|
+
int CX, CY;
|
|
28
|
+
int PX[8], PY[8], PD[8], TL[8], AR[8], DT[8];
|
|
29
|
+
vector<string> OWN, TR;
|
|
30
|
+
int TURN = 0;
|
|
31
|
+
int tx0, tx1, ty0, ty1; // bounding box of my territory
|
|
32
|
+
|
|
33
|
+
vector<pair<int, int> > ring;
|
|
34
|
+
vector<vector<int> > ridx;
|
|
35
|
+
|
|
36
|
+
static inline bool inB(int x, int y) { return x >= 0 && x < W && y >= 0 && y < H; }
|
|
37
|
+
static inline bool isMine(int x, int y) { return OWN[y][x] == (char)('0' + ME); }
|
|
38
|
+
|
|
39
|
+
void buildRing() {
|
|
40
|
+
ring.clear();
|
|
41
|
+
for (int x = 0; x < W; x++) ring.push_back(make_pair(x, 0));
|
|
42
|
+
for (int y = 1; y < H; y++) ring.push_back(make_pair(W - 1, y));
|
|
43
|
+
for (int x = W - 2; x >= 0; x--) ring.push_back(make_pair(x, H - 1));
|
|
44
|
+
for (int y = H - 2; y >= 1; y--) ring.push_back(make_pair(0, y));
|
|
45
|
+
ridx.assign(W, vector<int>(H, -1));
|
|
46
|
+
for (int i = 0; i < (int)ring.size(); i++) ridx[ring[i].first][ring[i].second] = i;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void computeBBox() {
|
|
50
|
+
tx0 = W; tx1 = -1; ty0 = H; ty1 = -1;
|
|
51
|
+
for (int y = 0; y < H; y++)
|
|
52
|
+
for (int x = 0; x < W; x++)
|
|
53
|
+
if (isMine(x, y)) {
|
|
54
|
+
tx0 = min(tx0, x); tx1 = max(tx1, x);
|
|
55
|
+
ty0 = min(ty0, y); ty1 = max(ty1, y);
|
|
56
|
+
}
|
|
57
|
+
if (tx1 < 0) { tx0 = tx1 = CX; ty0 = ty1 = CY; }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
int dirOf(int ax, int ay, int bx, int by) {
|
|
61
|
+
if (bx > ax) return 3;
|
|
62
|
+
if (bx < ax) return 2;
|
|
63
|
+
if (by > ay) return 1;
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
bool readState() {
|
|
68
|
+
string tok;
|
|
69
|
+
if (!(cin >> tok)) return false;
|
|
70
|
+
if (tok != "TURN") return false;
|
|
71
|
+
cin >> TURN;
|
|
72
|
+
for (int i = 0; i < N; i++) {
|
|
73
|
+
int id, x, y, tl, ar, dt;
|
|
74
|
+
char d;
|
|
75
|
+
cin >> tok >> id >> x >> y >> d >> tl >> ar >> dt;
|
|
76
|
+
int di = (d == 'U') ? 0 : (d == 'D') ? 1 : (d == 'L') ? 2 : 3;
|
|
77
|
+
if (id < 0 || id >= N) return false;
|
|
78
|
+
PX[id] = x; PY[id] = y; PD[id] = di; TL[id] = tl; AR[id] = ar; DT[id] = dt;
|
|
79
|
+
}
|
|
80
|
+
cin >> tok;
|
|
81
|
+
OWN.assign(H, "");
|
|
82
|
+
for (int y = 0; y < H; y++) cin >> OWN[y];
|
|
83
|
+
cin >> tok;
|
|
84
|
+
TR.assign(H, "");
|
|
85
|
+
for (int y = 0; y < H; y++) cin >> TR[y];
|
|
86
|
+
cin >> tok;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Candidate route construction
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
void addLine(vector<pair<int, int> >& r, int& x, int& y, int dir, int steps) {
|
|
94
|
+
for (int i = 0; i < steps; i++) {
|
|
95
|
+
x += DX[dir]; y += DY[dir];
|
|
96
|
+
r.push_back(make_pair(x, y));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Walk from (sx,sy) inside my territory to (gx,gy), staying on my cells.
|
|
101
|
+
// Returns the cell sequence (including start) or empty.
|
|
102
|
+
vector<pair<int, int> > walkInside(int sx, int sy, int gx, int gy, int sd, int forbidLast) {
|
|
103
|
+
vector<int> from(W * H, -1), fdir(W * H, -1);
|
|
104
|
+
deque<int> q;
|
|
105
|
+
int st = sy * W + sx;
|
|
106
|
+
from[st] = st;
|
|
107
|
+
fdir[st] = -2;
|
|
108
|
+
q.push_back(st);
|
|
109
|
+
int goal = -1;
|
|
110
|
+
while (!q.empty()) {
|
|
111
|
+
int k = q.front(); q.pop_front();
|
|
112
|
+
int x = k % W, y = k / W;
|
|
113
|
+
if (x == gx && y == gy) { goal = k; break; }
|
|
114
|
+
for (int d = 0; d < 4; d++) {
|
|
115
|
+
if (k == st && d == oppd(sd)) continue; // cannot reverse on the first step
|
|
116
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
117
|
+
if (!inB(nx, ny) || !isMine(nx, ny)) continue;
|
|
118
|
+
int nk = ny * W + nx;
|
|
119
|
+
if (from[nk] != -1) continue;
|
|
120
|
+
from[nk] = k; fdir[nk] = d;
|
|
121
|
+
q.push_back(nk);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (goal < 0) return vector<pair<int, int> >();
|
|
125
|
+
vector<int> path;
|
|
126
|
+
int c = goal;
|
|
127
|
+
while (c != st) { path.push_back(fdir[c]); c = from[c]; }
|
|
128
|
+
reverse(path.begin(), path.end());
|
|
129
|
+
if (!path.empty() && path.back() == oppd(forbidLast)) return vector<pair<int, int> >();
|
|
130
|
+
vector<pair<int, int> > r;
|
|
131
|
+
r.push_back(make_pair(sx, sy));
|
|
132
|
+
int x = sx, y = sy;
|
|
133
|
+
for (size_t i = 0; i < path.size(); i++) {
|
|
134
|
+
x += DX[path[i]]; y += DY[path[i]];
|
|
135
|
+
r.push_back(make_pair(x, y));
|
|
136
|
+
}
|
|
137
|
+
return r;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Full lap: out to the border, all the way round the ring, back home.
|
|
141
|
+
vector<pair<int, int> > buildLap(int sx, int sy, int D, int P) {
|
|
142
|
+
vector<pair<int, int> > r;
|
|
143
|
+
r.push_back(make_pair(sx, sy));
|
|
144
|
+
int x = sx, y = sy;
|
|
145
|
+
while (true) {
|
|
146
|
+
int nx = x + DX[D], ny = y + DY[D];
|
|
147
|
+
if (!inB(nx, ny)) break;
|
|
148
|
+
x = nx; y = ny;
|
|
149
|
+
r.push_back(make_pair(x, y));
|
|
150
|
+
}
|
|
151
|
+
int B = ridx[x][y];
|
|
152
|
+
if (B < 0) return vector<pair<int, int> >();
|
|
153
|
+
int pd;
|
|
154
|
+
if (D == 0 || D == 1) pd = (P > 0) ? 3 : 2;
|
|
155
|
+
else pd = (P > 0) ? 1 : 0;
|
|
156
|
+
int bx = x + DX[pd], by = y + DY[pd];
|
|
157
|
+
if (!inB(bx, by)) return vector<pair<int, int> >();
|
|
158
|
+
int B2 = ridx[bx][by];
|
|
159
|
+
if (B2 < 0) return vector<pair<int, int> >();
|
|
160
|
+
int Sz = (int)ring.size();
|
|
161
|
+
vector<int> order;
|
|
162
|
+
if ((B + 1) % Sz == B2) {
|
|
163
|
+
int i = B;
|
|
164
|
+
do { i = (i - 1 + Sz) % Sz; order.push_back(i); } while (i != B2);
|
|
165
|
+
} else if ((B - 1 + Sz) % Sz == B2) {
|
|
166
|
+
int i = B;
|
|
167
|
+
do { i = (i + 1) % Sz; order.push_back(i); } while (i != B2);
|
|
168
|
+
} else return vector<pair<int, int> >();
|
|
169
|
+
for (size_t k = 0; k < order.size(); k++) {
|
|
170
|
+
int c = order[k];
|
|
171
|
+
int cx = ring[c].first, cy = ring[c].second;
|
|
172
|
+
if (cx == x && cy == y) continue;
|
|
173
|
+
if (abs(cx - x) + abs(cy - y) != 1) return vector<pair<int, int> >();
|
|
174
|
+
x = cx; y = cy;
|
|
175
|
+
r.push_back(make_pair(x, y));
|
|
176
|
+
}
|
|
177
|
+
int RD = oppd(D), guard = 0;
|
|
178
|
+
while (true) {
|
|
179
|
+
int nx = x + DX[RD], ny = y + DY[RD];
|
|
180
|
+
if (!inB(nx, ny)) return vector<pair<int, int> >();
|
|
181
|
+
x = nx; y = ny;
|
|
182
|
+
r.push_back(make_pair(x, y));
|
|
183
|
+
if (isMine(x, y)) break;
|
|
184
|
+
if (++guard > W + H + 4) return vector<pair<int, int> >();
|
|
185
|
+
}
|
|
186
|
+
return r;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Half-plane sweep: cut along one edge of my bounding box, wall off the whole
|
|
190
|
+
// border on that side, and walk back home.
|
|
191
|
+
vector<pair<int, int> > buildAnnex(int D) {
|
|
192
|
+
int X0, Y0, FD;
|
|
193
|
+
if (D == 0) { X0 = tx0; Y0 = ty0; FD = 2; } // north
|
|
194
|
+
else if (D == 1) { X0 = tx0; Y0 = ty1; FD = 2; } // south
|
|
195
|
+
else if (D == 2) { X0 = tx0; Y0 = ty0; FD = 0; } // west
|
|
196
|
+
else { X0 = tx1; Y0 = ty0; FD = 0; } // east
|
|
197
|
+
if (!isMine(X0, Y0)) return vector<pair<int, int> >();
|
|
198
|
+
|
|
199
|
+
for (int ord = 0; ord < 2; ord++) {
|
|
200
|
+
int sx = PX[ME], sy = PY[ME];
|
|
201
|
+
int dxs = (X0 > sx) ? 3 : (X0 < sx ? 2 : -1);
|
|
202
|
+
int dys = (Y0 > sy) ? 1 : (Y0 < sy ? 0 : -1);
|
|
203
|
+
vector<pair<int, int> > pre;
|
|
204
|
+
bool ok = true;
|
|
205
|
+
int x = sx, y = sy;
|
|
206
|
+
int seq[2][2] = {{dxs, dys}, {dys, dxs}};
|
|
207
|
+
pre.push_back(make_pair(x, y));
|
|
208
|
+
for (int s = 0; s < 2 && ok; s++) {
|
|
209
|
+
int d = seq[ord][s];
|
|
210
|
+
if (d < 0) continue;
|
|
211
|
+
int steps = (d == 2 || d == 3) ? abs(X0 - x) : abs(Y0 - y);
|
|
212
|
+
for (int i = 0; i < steps; i++) {
|
|
213
|
+
x += DX[d]; y += DY[d];
|
|
214
|
+
if (!isMine(x, y)) { ok = false; break; }
|
|
215
|
+
pre.push_back(make_pair(x, y));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!ok || x != X0 || y != Y0) continue;
|
|
219
|
+
int lastD = -1;
|
|
220
|
+
if (pre.size() >= 2)
|
|
221
|
+
lastD = dirOf(pre[pre.size() - 2].first, pre[pre.size() - 2].second,
|
|
222
|
+
pre[pre.size() - 1].first, pre[pre.size() - 1].second);
|
|
223
|
+
if (lastD == oppd(FD)) continue;
|
|
224
|
+
|
|
225
|
+
vector<pair<int, int> > r = pre;
|
|
226
|
+
int cx = X0, cy = Y0;
|
|
227
|
+
if (D == 0) {
|
|
228
|
+
addLine(r, cx, cy, 2, X0);
|
|
229
|
+
addLine(r, cx, cy, 0, cy);
|
|
230
|
+
addLine(r, cx, cy, 3, W - 1 - cx);
|
|
231
|
+
addLine(r, cx, cy, 1, ty0);
|
|
232
|
+
} else if (D == 1) {
|
|
233
|
+
addLine(r, cx, cy, 2, X0);
|
|
234
|
+
addLine(r, cx, cy, 1, H - 1 - cy);
|
|
235
|
+
addLine(r, cx, cy, 3, W - 1 - cx);
|
|
236
|
+
addLine(r, cx, cy, 0, cy - ty1);
|
|
237
|
+
} else if (D == 2) {
|
|
238
|
+
addLine(r, cx, cy, 0, cy);
|
|
239
|
+
addLine(r, cx, cy, 2, cx);
|
|
240
|
+
addLine(r, cx, cy, 1, H - 1 - cy);
|
|
241
|
+
addLine(r, cx, cy, 3, X0);
|
|
242
|
+
} else {
|
|
243
|
+
addLine(r, cx, cy, 0, cy);
|
|
244
|
+
addLine(r, cx, cy, 3, W - 1 - cx);
|
|
245
|
+
addLine(r, cx, cy, 1, H - 1 - cy);
|
|
246
|
+
addLine(r, cx, cy, 2, W - 1 - X0);
|
|
247
|
+
}
|
|
248
|
+
// final segment: straight back into my territory
|
|
249
|
+
int RD = (D == 0 || D == 1) ? 2 : 0;
|
|
250
|
+
int guard = 0;
|
|
251
|
+
while (true) {
|
|
252
|
+
int nx = cx + DX[RD], ny = cy + DY[RD];
|
|
253
|
+
if (!inB(nx, ny)) { ok = false; break; }
|
|
254
|
+
cx = nx; cy = ny;
|
|
255
|
+
r.push_back(make_pair(cx, cy));
|
|
256
|
+
if (isMine(cx, cy)) break;
|
|
257
|
+
if (++guard > W + H + 4) { ok = false; break; }
|
|
258
|
+
}
|
|
259
|
+
if (ok) return r;
|
|
260
|
+
}
|
|
261
|
+
return vector<pair<int, int> >();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Interior sweep: enclose a band next to my bounding box. The cut side is my
|
|
265
|
+
// own territory, so the loop never has to reach the border at all - short trail,
|
|
266
|
+
// little exposure.
|
|
267
|
+
vector<pair<int, int> > buildSweep(int D) {
|
|
268
|
+
int X0, Y0, FD;
|
|
269
|
+
if (D == 0) { X0 = tx0; Y0 = ty0; FD = 0; }
|
|
270
|
+
else if (D == 1) { X0 = tx0; Y0 = ty1; FD = 1; }
|
|
271
|
+
else if (D == 2) { X0 = tx0; Y0 = ty0; FD = 2; }
|
|
272
|
+
else { X0 = tx1; Y0 = ty0; FD = 3; }
|
|
273
|
+
if (!isMine(X0, Y0)) return vector<pair<int, int> >();
|
|
274
|
+
vector<pair<int, int> > pre = walkInside(PX[ME], PY[ME], X0, Y0, PD[ME], oppd(FD));
|
|
275
|
+
if (pre.empty()) return vector<pair<int, int> >();
|
|
276
|
+
vector<pair<int, int> > r = pre;
|
|
277
|
+
int cx = X0, cy = Y0;
|
|
278
|
+
if (D == 0) {
|
|
279
|
+
addLine(r, cx, cy, 0, cy);
|
|
280
|
+
addLine(r, cx, cy, 3, tx1 - cx);
|
|
281
|
+
addLine(r, cx, cy, 1, ty0);
|
|
282
|
+
} else if (D == 1) {
|
|
283
|
+
addLine(r, cx, cy, 1, H - 1 - cy);
|
|
284
|
+
addLine(r, cx, cy, 3, tx1 - cx);
|
|
285
|
+
addLine(r, cx, cy, 0, H - 1 - ty1);
|
|
286
|
+
} else if (D == 2) {
|
|
287
|
+
addLine(r, cx, cy, 2, cx);
|
|
288
|
+
addLine(r, cx, cy, 1, ty1 - cy);
|
|
289
|
+
addLine(r, cx, cy, 3, tx0);
|
|
290
|
+
} else {
|
|
291
|
+
addLine(r, cx, cy, 3, W - 1 - cx);
|
|
292
|
+
addLine(r, cx, cy, 1, ty1 - cy);
|
|
293
|
+
addLine(r, cx, cy, 2, W - 1 - tx1);
|
|
294
|
+
}
|
|
295
|
+
return r;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
vector<pair<int, int> > buildSweepD(int D, int d) {
|
|
299
|
+
int X0, Y0, FD;
|
|
300
|
+
if (D == 0) { X0 = tx0; Y0 = ty0; FD = 0; }
|
|
301
|
+
else if (D == 1) { X0 = tx0; Y0 = ty1; FD = 1; }
|
|
302
|
+
else if (D == 2) { X0 = tx0; Y0 = ty0; FD = 2; }
|
|
303
|
+
else { X0 = tx1; Y0 = ty0; FD = 3; }
|
|
304
|
+
if (!isMine(X0, Y0)) return vector<pair<int, int> >();
|
|
305
|
+
if (d <= 0) return vector<pair<int, int> >();
|
|
306
|
+
int w = (D < 2) ? (tx1 - tx0) : (ty1 - ty0); // perpendicular span
|
|
307
|
+
int maxd;
|
|
308
|
+
if (D == 0) maxd = Y0;
|
|
309
|
+
else if (D == 1) maxd = H - 1 - Y0;
|
|
310
|
+
else if (D == 2) maxd = X0;
|
|
311
|
+
else maxd = W - 1 - X0;
|
|
312
|
+
if (d > maxd) d = maxd;
|
|
313
|
+
if (d <= 0 || w <= 0) return vector<pair<int, int> >();
|
|
314
|
+
vector<pair<int, int> > pre = walkInside(PX[ME], PY[ME], X0, Y0, PD[ME], oppd(FD));
|
|
315
|
+
if (pre.empty()) return vector<pair<int, int> >();
|
|
316
|
+
vector<pair<int, int> > r = pre;
|
|
317
|
+
int cx = X0, cy = Y0;
|
|
318
|
+
if (D == 0) {
|
|
319
|
+
addLine(r, cx, cy, 0, d);
|
|
320
|
+
addLine(r, cx, cy, 3, w);
|
|
321
|
+
addLine(r, cx, cy, 1, d);
|
|
322
|
+
} else if (D == 1) {
|
|
323
|
+
addLine(r, cx, cy, 1, d);
|
|
324
|
+
addLine(r, cx, cy, 3, w);
|
|
325
|
+
addLine(r, cx, cy, 0, d);
|
|
326
|
+
} else if (D == 2) {
|
|
327
|
+
addLine(r, cx, cy, 2, d);
|
|
328
|
+
addLine(r, cx, cy, 1, ty1 - ty0);
|
|
329
|
+
addLine(r, cx, cy, 3, d);
|
|
330
|
+
} else {
|
|
331
|
+
addLine(r, cx, cy, 3, d);
|
|
332
|
+
addLine(r, cx, cy, 1, ty1 - ty0);
|
|
333
|
+
addLine(r, cx, cy, 2, d);
|
|
334
|
+
}
|
|
335
|
+
return r;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Generic: close whatever stretch of the ring is still not mine.
|
|
339
|
+
vector<pair<int, int> > buildCover() {
|
|
340
|
+
int Sz = (int)ring.size();
|
|
341
|
+
int i1 = -1;
|
|
342
|
+
for (int i = 0; i < Sz; i++)
|
|
343
|
+
if (!isMine(ring[i].first, ring[i].second) &&
|
|
344
|
+
isMine(ring[(i - 1 + Sz) % Sz].first, ring[(i - 1 + Sz) % Sz].second)) { i1 = i; break; }
|
|
345
|
+
if (i1 < 0) return vector<pair<int, int> >();
|
|
346
|
+
int i2 = i1;
|
|
347
|
+
while (!isMine(ring[(i2 + 1) % Sz].first, ring[(i2 + 1) % Sz].second)) i2 = (i2 + 1) % Sz;
|
|
348
|
+
int a = (i1 - 1 + Sz) % Sz;
|
|
349
|
+
int ax = ring[a].first, ay = ring[a].second;
|
|
350
|
+
vector<pair<int, int> > pre = walkInside(PX[ME], PY[ME], ax, ay, PD[ME],
|
|
351
|
+
dirOf(ring[a].first, ring[a].second,
|
|
352
|
+
ring[i1].first, ring[i1].second));
|
|
353
|
+
if (pre.empty()) return vector<pair<int, int> >();
|
|
354
|
+
vector<pair<int, int> > r = pre;
|
|
355
|
+
int x = ax, y = ay;
|
|
356
|
+
int i = a;
|
|
357
|
+
while (true) {
|
|
358
|
+
i = (i + 1) % Sz;
|
|
359
|
+
int nx = ring[i].first, ny = ring[i].second;
|
|
360
|
+
if (abs(nx - x) + abs(ny - y) != 1) return vector<pair<int, int> >();
|
|
361
|
+
x = nx; y = ny;
|
|
362
|
+
r.push_back(make_pair(x, y));
|
|
363
|
+
if (isMine(x, y)) break;
|
|
364
|
+
}
|
|
365
|
+
return r;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
bool routeValid(const vector<pair<int, int> >& r) {
|
|
370
|
+
int n = (int)r.size();
|
|
371
|
+
if (n < 4) return false;
|
|
372
|
+
if (r[0].first != PX[ME] || r[0].second != PY[ME]) return false;
|
|
373
|
+
for (int i = 0; i < n; i++) {
|
|
374
|
+
if (!inB(r[i].first, r[i].second)) return false;
|
|
375
|
+
if (i) {
|
|
376
|
+
int dx = abs(r[i].first - r[i - 1].first), dy = abs(r[i].second - r[i - 1].second);
|
|
377
|
+
if (dx + dy != 1) return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (dirOf(r[0].first, r[0].second, r[1].first, r[1].second) == oppd(PD[ME])) return false;
|
|
381
|
+
for (int i = 1; i + 1 < n; i++) {
|
|
382
|
+
int a = dirOf(r[i - 1].first, r[i - 1].second, r[i].first, r[i].second);
|
|
383
|
+
int b = dirOf(r[i].first, r[i].second, r[i + 1].first, r[i + 1].second);
|
|
384
|
+
if (b == oppd(a)) return false;
|
|
385
|
+
}
|
|
386
|
+
int k = -1;
|
|
387
|
+
for (int i = 1; i < n; i++) if (!isMine(r[i].first, r[i].second)) { k = i; break; }
|
|
388
|
+
if (k < 0) return false;
|
|
389
|
+
for (int i = k; i < n - 1; i++) if (isMine(r[i].first, r[i].second)) return false;
|
|
390
|
+
if (!isMine(r[n - 1].first, r[n - 1].second)) return false;
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Exact capture simulation: walls = my land + the trail this route would lay.
|
|
395
|
+
long long simulateGain(const vector<pair<int, int> >& r) {
|
|
396
|
+
vector<char> wall(W * H, 0);
|
|
397
|
+
for (int y = 0; y < H; y++)
|
|
398
|
+
for (int x = 0; x < W; x++)
|
|
399
|
+
if (isMine(x, y)) wall[y * W + x] = 1;
|
|
400
|
+
long long trailCells = 0;
|
|
401
|
+
for (size_t i = 1; i < r.size(); i++) {
|
|
402
|
+
int k = r[i].second * W + r[i].first;
|
|
403
|
+
if (!wall[k]) { wall[k] = 1; trailCells++; }
|
|
404
|
+
}
|
|
405
|
+
vector<char> seen(W * H, 0);
|
|
406
|
+
deque<int> q;
|
|
407
|
+
for (int x = 0; x < W; x++) {
|
|
408
|
+
int a = x, b = (H - 1) * W + x;
|
|
409
|
+
if (!wall[a] && !seen[a]) { seen[a] = 1; q.push_back(a); }
|
|
410
|
+
if (!wall[b] && !seen[b]) { seen[b] = 1; q.push_back(b); }
|
|
411
|
+
}
|
|
412
|
+
for (int y = 0; y < H; y++) {
|
|
413
|
+
int a = y * W, b = y * W + W - 1;
|
|
414
|
+
if (!wall[a] && !seen[a]) { seen[a] = 1; q.push_back(a); }
|
|
415
|
+
if (!wall[b] && !seen[b]) { seen[b] = 1; q.push_back(b); }
|
|
416
|
+
}
|
|
417
|
+
while (!q.empty()) {
|
|
418
|
+
int k = q.front(); q.pop_front();
|
|
419
|
+
int x = k % W;
|
|
420
|
+
int nb[4] = {k - W, k + W, k - 1, k + 1};
|
|
421
|
+
bool okb[4] = {k >= W, k < W * (H - 1), x > 0, x < W - 1};
|
|
422
|
+
for (int t = 0; t < 4; t++)
|
|
423
|
+
if (okb[t] && !wall[nb[t]] && !seen[nb[t]]) { seen[nb[t]] = 1; q.push_back(nb[t]); }
|
|
424
|
+
}
|
|
425
|
+
long long enclosed = 0;
|
|
426
|
+
for (int k = 0; k < W * H; k++) if (!wall[k] && !seen[k]) enclosed++;
|
|
427
|
+
return trailCells + enclosed;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ---------------------------------------------------------------------------
|
|
431
|
+
vector<pair<int, int> > route;
|
|
432
|
+
int rstep = 0;
|
|
433
|
+
int wanderPhase = 0;
|
|
434
|
+
|
|
435
|
+
double scoreRoute(long long gain, int len) {
|
|
436
|
+
if (len <= 0) return -1;
|
|
437
|
+
double penalty = 1.0 + max(0, len - 60) / 25.0;
|
|
438
|
+
return (double)gain / (len * penalty);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
void replan() {
|
|
442
|
+
route.clear();
|
|
443
|
+
rstep = 0;
|
|
444
|
+
if (!isMine(PX[ME], PY[ME]) || TL[ME] != 0) return;
|
|
445
|
+
computeBBox();
|
|
446
|
+
|
|
447
|
+
vector<pair<int, int> > best;
|
|
448
|
+
double bestScore = -1;
|
|
449
|
+
int md = PD[ME];
|
|
450
|
+
|
|
451
|
+
vector<vector<pair<int, int> > > cands;
|
|
452
|
+
for (int D = 0; D < 4; D++) {
|
|
453
|
+
if (D == oppd(md)) continue;
|
|
454
|
+
for (int P = -1; P <= 1; P += 2) {
|
|
455
|
+
vector<pair<int, int> > r = buildLap(PX[ME], PY[ME], D, P);
|
|
456
|
+
if (routeValid(r)) cands.push_back(r);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
for (int D = 0; D < 4; D++) {
|
|
460
|
+
vector<pair<int, int> > r = buildAnnex(D);
|
|
461
|
+
if (routeValid(r)) cands.push_back(r);
|
|
462
|
+
}
|
|
463
|
+
for (int D = 0; D < 4; D++) {
|
|
464
|
+
vector<pair<int, int> > r = buildSweep(D);
|
|
465
|
+
if (routeValid(r)) cands.push_back(r);
|
|
466
|
+
static const int depths[12] = {1, 2, 3, 4, 6, 8, 11, 15, 20, 26, 34, 44};
|
|
467
|
+
for (int t = 0; t < 12; t++) {
|
|
468
|
+
vector<pair<int, int> > q = buildSweepD(D, depths[t]);
|
|
469
|
+
if (routeValid(q)) cands.push_back(q);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
{
|
|
473
|
+
vector<pair<int, int> > r = buildCover();
|
|
474
|
+
if (routeValid(r)) cands.push_back(r);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
int cap = getenv("TCAP") ? atoi(getenv("TCAP")) : (N >= 4 ? 150 : 400);
|
|
478
|
+
double L0 = getenv("TL0") ? atof(getenv("TL0")) : (N >= 4 ? 60.0 : 170.0);
|
|
479
|
+
vector<pair<int, int> > bestAny;
|
|
480
|
+
double anyScore = -1;
|
|
481
|
+
for (size_t i = 0; i < cands.size(); i++) {
|
|
482
|
+
int L = (int)cands[i].size();
|
|
483
|
+
if (L > cap) continue;
|
|
484
|
+
long long gain = simulateGain(cands[i]);
|
|
485
|
+
// extra safety: discount routes whose trail runs right past an opponent
|
|
486
|
+
double near = 0;
|
|
487
|
+
for (int k = 1; k < L; k++) {
|
|
488
|
+
int dm = 1000000;
|
|
489
|
+
for (int o = 0; o < N; o++) {
|
|
490
|
+
if (o == ME) continue;
|
|
491
|
+
dm = min(dm, abs(PX[o] - cands[i][k].first) + abs(PY[o] - cands[i][k].second));
|
|
492
|
+
}
|
|
493
|
+
if (dm <= 5) near += 1;
|
|
494
|
+
}
|
|
495
|
+
near = L > 1 ? near / (L - 1) : 0.0;
|
|
496
|
+
double x = L / L0;
|
|
497
|
+
double pen = 1.0 + x * x * x;
|
|
498
|
+
double sc = (double)gain / (L + 1) / pen * (1.0 - 0.85 * near);
|
|
499
|
+
if (sc > bestScore) { bestScore = sc; best = cands[i]; }
|
|
500
|
+
double raw = (double)gain / (L + 1);
|
|
501
|
+
if (raw > anyScore) { anyScore = raw; bestAny = cands[i]; }
|
|
502
|
+
}
|
|
503
|
+
if (best.empty()) best = bestAny; // never stall: take the best raw route
|
|
504
|
+
route = best;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
int wanderDir() {
|
|
508
|
+
int mx = PX[ME], my = PY[ME], md = PD[ME];
|
|
509
|
+
char mt = (char)('0' + ME);
|
|
510
|
+
static const int cyc[4] = {3, 1, 2, 0};
|
|
511
|
+
for (int k = 0; k < 4; k++) {
|
|
512
|
+
int d = cyc[(wanderPhase + k) % 4];
|
|
513
|
+
if (d == oppd(md)) continue;
|
|
514
|
+
int nx = mx + DX[d], ny = my + DY[d];
|
|
515
|
+
if (!inB(nx, ny)) continue;
|
|
516
|
+
if (TR[ny][nx] == mt) continue;
|
|
517
|
+
wanderPhase = (wanderPhase + k + 1) % 4;
|
|
518
|
+
return d;
|
|
519
|
+
}
|
|
520
|
+
return md;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
bool legalMove(int d) {
|
|
524
|
+
if (d < 0 || d > 3) return false;
|
|
525
|
+
if (d == oppd(PD[ME])) return false;
|
|
526
|
+
int nx = PX[ME] + DX[d], ny = PY[ME] + DY[d];
|
|
527
|
+
if (!inB(nx, ny)) return false;
|
|
528
|
+
if (TR[ny][nx] == (char)('0' + ME)) return false;
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
int fallbackDir() {
|
|
533
|
+
int mx = PX[ME], my = PY[ME], md = PD[ME];
|
|
534
|
+
char mt = (char)('0' + ME);
|
|
535
|
+
vector<int> from(W * H, -1), fdir(W * H, -1);
|
|
536
|
+
deque<int> q;
|
|
537
|
+
int st = my * W + mx;
|
|
538
|
+
from[st] = st;
|
|
539
|
+
q.push_back(st);
|
|
540
|
+
int goal = -1;
|
|
541
|
+
while (!q.empty()) {
|
|
542
|
+
int k = q.front(); q.pop_front();
|
|
543
|
+
int x = k % W, y = k / W;
|
|
544
|
+
if (!(x == mx && y == my) && isMine(x, y)) { goal = k; break; }
|
|
545
|
+
for (int d = 0; d < 4; d++) {
|
|
546
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
547
|
+
if (!inB(nx, ny)) continue;
|
|
548
|
+
if (TR[ny][nx] == mt) continue;
|
|
549
|
+
int nk = ny * W + nx;
|
|
550
|
+
if (from[nk] != -1) continue;
|
|
551
|
+
from[nk] = k; fdir[nk] = d;
|
|
552
|
+
q.push_back(nk);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (goal >= 0) {
|
|
556
|
+
vector<int> path;
|
|
557
|
+
int c = goal;
|
|
558
|
+
while (c != st) { path.push_back(fdir[c]); c = from[c]; }
|
|
559
|
+
reverse(path.begin(), path.end());
|
|
560
|
+
if (!path.empty() && legalMove(path[0])) return path[0];
|
|
561
|
+
}
|
|
562
|
+
for (int d = 0; d < 4; d++) if (legalMove(d)) return d;
|
|
563
|
+
return md;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
int routeDir() {
|
|
567
|
+
int mx = PX[ME], my = PY[ME];
|
|
568
|
+
if (!route.empty() && rstep < (int)route.size() &&
|
|
569
|
+
route[rstep].first == mx && route[rstep].second == my &&
|
|
570
|
+
rstep + 1 < (int)route.size()) {
|
|
571
|
+
int d = dirOf(mx, my, route[rstep + 1].first, route[rstep + 1].second);
|
|
572
|
+
if (legalMove(d)) { rstep++; return d; }
|
|
573
|
+
}
|
|
574
|
+
replan();
|
|
575
|
+
if ((int)route.size() >= 2 && route[0].first == mx && route[0].second == my) {
|
|
576
|
+
int d = dirOf(mx, my, route[1].first, route[1].second);
|
|
577
|
+
if (legalMove(d)) { rstep = 1; return d; }
|
|
578
|
+
}
|
|
579
|
+
route.clear();
|
|
580
|
+
return fallbackDir();
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
int main() {
|
|
584
|
+
ios::sync_with_stdio(false);
|
|
585
|
+
cin.tie(nullptr);
|
|
586
|
+
|
|
587
|
+
string tok;
|
|
588
|
+
if (!(cin >> tok)) return 0;
|
|
589
|
+
cin >> W >> H >> MAXT >> N >> ME >> MOVE_MS >> INIT_MS;
|
|
590
|
+
if (N > 8) N = 8;
|
|
591
|
+
for (int i = 0; i < N; i++) {
|
|
592
|
+
int id, x, y;
|
|
593
|
+
cin >> tok >> id >> x >> y;
|
|
594
|
+
if (id >= 0 && id < N) { PX[id] = x; PY[id] = y; }
|
|
595
|
+
}
|
|
596
|
+
CX = PX[ME]; CY = PY[ME];
|
|
597
|
+
buildRing();
|
|
598
|
+
|
|
599
|
+
while (readState()) {
|
|
600
|
+
int d;
|
|
601
|
+
long long big = (long long)W * H * 6 / 10;
|
|
602
|
+
if (AR[ME] > big) d = wanderDir();
|
|
603
|
+
else d = routeDir();
|
|
604
|
+
if (!legalMove(d)) d = PD[ME];
|
|
605
|
+
cout << TURN << ' ' << DC[d] << endl;
|
|
606
|
+
}
|
|
607
|
+
return 0;
|
|
608
|
+
}
|