dsh-eval-guard 0.2.2 → 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/bomberman/workspace.zip +0 -0
- package/assets/commit0/instance.json +30 -0
- package/assets/commit0/workspace.zip +0 -0
- package/assets/ctf/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/assets/tank/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,652 @@
|
|
|
1
|
+
// 圈地对战 bot:威胁感知的圈地规划器
|
|
2
|
+
// 核心:候选回路(矩形/封口路径)+ 精确围地收益评估 + 对手可达性风险模型 + 切断/追击战术
|
|
3
|
+
#include <bits/stdc++.h>
|
|
4
|
+
using namespace std;
|
|
5
|
+
|
|
6
|
+
static const int DX[4] = {0, 0, -1, 1};
|
|
7
|
+
static const int DY[4] = {-1, 1, 0, 0};
|
|
8
|
+
static const char DC[4] = {'U', 'D', 'L', 'R'};
|
|
9
|
+
static const int INF = 1 << 28;
|
|
10
|
+
|
|
11
|
+
// ---- tuning ----
|
|
12
|
+
static int MARGIN = 1; // 安全余量(回合)
|
|
13
|
+
static double LEN_W = 1.05; // 权重:回合成本
|
|
14
|
+
static double RISK_W = 1.15; // 权重:风险
|
|
15
|
+
static int AMAX = 16, BMAX = 14;
|
|
16
|
+
static const int PURSUIT_MAX = 6;
|
|
17
|
+
|
|
18
|
+
int W, H, MAX_TURNS, N, ME, MOVE_MS, INIT_MS;
|
|
19
|
+
vector<pair<int, int>> spawnPos;
|
|
20
|
+
vector<int> spawnDir;
|
|
21
|
+
vector<signed char> own, trl, prot;
|
|
22
|
+
int curTurn;
|
|
23
|
+
|
|
24
|
+
struct PInfo { int x, y, dir, trailLen, area, deaths; };
|
|
25
|
+
vector<PInfo> P;
|
|
26
|
+
|
|
27
|
+
inline int IDX(int x, int y) { return y * W + x; }
|
|
28
|
+
inline bool inb(int x, int y) { return x >= 0 && x < W && y >= 0 && y < H; }
|
|
29
|
+
|
|
30
|
+
// ---------------- protocol ----------------
|
|
31
|
+
bool readState() {
|
|
32
|
+
string tok;
|
|
33
|
+
if (!(cin >> tok)) return false;
|
|
34
|
+
cin >> curTurn;
|
|
35
|
+
P.assign(N, {});
|
|
36
|
+
for (int i = 0; i < N; i++) {
|
|
37
|
+
int id; char d; PInfo q;
|
|
38
|
+
cin >> tok >> id >> q.x >> q.y >> d >> q.trailLen >> q.area >> q.deaths;
|
|
39
|
+
q.dir = string("UDLR").find(d);
|
|
40
|
+
P[id] = q;
|
|
41
|
+
}
|
|
42
|
+
cin >> tok; // OWNER
|
|
43
|
+
own.assign(W * H, -1);
|
|
44
|
+
string row;
|
|
45
|
+
for (int y = 0; y < H; y++) {
|
|
46
|
+
cin >> row;
|
|
47
|
+
for (int x = 0; x < W; x++) own[IDX(x, y)] = (row[x] == '.') ? -1 : (row[x] - '0');
|
|
48
|
+
}
|
|
49
|
+
cin >> tok; // TRAIL
|
|
50
|
+
trl.assign(W * H, -1);
|
|
51
|
+
for (int y = 0; y < H; y++) {
|
|
52
|
+
cin >> row;
|
|
53
|
+
for (int x = 0; x < W; x++) trl[IDX(x, y)] = (row[x] == '.') ? -1 : (row[x] - '0');
|
|
54
|
+
}
|
|
55
|
+
cin >> tok; // END
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---------------- BFS ----------------
|
|
60
|
+
void bfsBlocked(const vector<signed char>& blocked, int src,
|
|
61
|
+
vector<int>& dist, vector<int>* par, vector<int>* pdir) {
|
|
62
|
+
int n = W * H;
|
|
63
|
+
dist.assign(n, INF);
|
|
64
|
+
if (par) par->assign(n, -1);
|
|
65
|
+
if (pdir) pdir->assign(n, -1);
|
|
66
|
+
static vector<int> q;
|
|
67
|
+
q.clear();
|
|
68
|
+
dist[src] = 0;
|
|
69
|
+
q.push_back(src);
|
|
70
|
+
for (size_t i = 0; i < q.size(); i++) {
|
|
71
|
+
int k = q[i];
|
|
72
|
+
int x = k % W, y = k / W;
|
|
73
|
+
for (int d = 0; d < 4; d++) {
|
|
74
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
75
|
+
if (!inb(nx, ny)) continue;
|
|
76
|
+
int nk = IDX(nx, ny);
|
|
77
|
+
if (blocked[nk] || dist[nk] < INF) continue;
|
|
78
|
+
dist[nk] = dist[k] + 1;
|
|
79
|
+
if (par) (*par)[nk] = k;
|
|
80
|
+
if (pdir) (*pdir)[nk] = d;
|
|
81
|
+
q.push_back(nk);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---------------- per-turn fields ----------------
|
|
87
|
+
vector<int> threat; // 任一对手到达该格的最少步数
|
|
88
|
+
vector<vector<int>> oppD; // 每个对手的到达距离
|
|
89
|
+
vector<int> myDist;
|
|
90
|
+
|
|
91
|
+
void computeFields() {
|
|
92
|
+
int n = W * H;
|
|
93
|
+
vector<signed char> blk(n);
|
|
94
|
+
for (int k = 0; k < n; k++) blk[k] = (trl[k] == ME) ? 1 : 0;
|
|
95
|
+
bfsBlocked(blk, IDX(P[ME].x, P[ME].y), myDist, nullptr, nullptr);
|
|
96
|
+
threat.assign(n, INF);
|
|
97
|
+
oppD.assign(N, {});
|
|
98
|
+
for (int p = 0; p < N; p++) {
|
|
99
|
+
if (p == ME) continue;
|
|
100
|
+
oppD[p].assign(n, INF);
|
|
101
|
+
for (int k = 0; k < n; k++) blk[k] = (trl[k] == p) ? 1 : 0;
|
|
102
|
+
bfsBlocked(blk, IDX(P[p].x, P[p].y), oppD[p], nullptr, nullptr);
|
|
103
|
+
for (int k = 0; k < n; k++) if (oppD[p][k] < threat[k]) threat[k] = oppD[p][k];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---------------- 路径模拟 ----------------
|
|
108
|
+
struct PathInfo {
|
|
109
|
+
vector<pair<int, int>> trailCells; // (格, 第几步踩上)
|
|
110
|
+
int captureLen = -1;
|
|
111
|
+
int cutVal = 0;
|
|
112
|
+
int endX = 0, endY = 0, endDir = 0;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
bool walkPath(const vector<int>& dirs, PathInfo& info, vector<uint8_t>& used) {
|
|
116
|
+
const PInfo& me = P[ME];
|
|
117
|
+
used.assign(W * H, 0);
|
|
118
|
+
used[IDX(me.x, me.y)] = 1;
|
|
119
|
+
int x = me.x, y = me.y, dir = me.dir;
|
|
120
|
+
info.trailCells.clear();
|
|
121
|
+
info.captureLen = -1;
|
|
122
|
+
info.cutVal = 0;
|
|
123
|
+
for (int i = 0; i < (int)dirs.size(); i++) {
|
|
124
|
+
int d = dirs[i];
|
|
125
|
+
if (d == (dir ^ 1)) return false;
|
|
126
|
+
dir = d;
|
|
127
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
128
|
+
if (!inb(nx, ny)) return false;
|
|
129
|
+
int k = IDX(nx, ny);
|
|
130
|
+
if (trl[k] == ME) return false;
|
|
131
|
+
if (used[k]) return false;
|
|
132
|
+
used[k] = 1;
|
|
133
|
+
x = nx; y = ny;
|
|
134
|
+
if (trl[k] >= 0 && trl[k] != ME) {
|
|
135
|
+
info.cutVal += 20 + 3 * P[trl[k]].trailLen;
|
|
136
|
+
}
|
|
137
|
+
if (own[k] == ME) {
|
|
138
|
+
if (me.trailLen > 0 || !info.trailCells.empty()) {
|
|
139
|
+
info.captureLen = i;
|
|
140
|
+
info.endX = x; info.endY = y; info.endDir = dir;
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
info.trailCells.push_back({k, i});
|
|
146
|
+
}
|
|
147
|
+
info.endX = x; info.endY = y; info.endDir = dir;
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 从路径末端补一条回到领地的最短路(不穿自己轨迹)
|
|
152
|
+
int closePath(vector<int>& dirs, PathInfo& info, vector<uint8_t>& used) {
|
|
153
|
+
int n = W * H;
|
|
154
|
+
int start = IDX(info.endX, info.endY);
|
|
155
|
+
if (own[start] == ME && (P[ME].trailLen > 0 || !info.trailCells.empty())) {
|
|
156
|
+
info.captureLen = (int)dirs.size() - 1;
|
|
157
|
+
return info.captureLen;
|
|
158
|
+
}
|
|
159
|
+
vector<signed char> blk(n);
|
|
160
|
+
for (int k = 0; k < n; k++) blk[k] = (trl[k] == ME || used[k]) ? 1 : 0;
|
|
161
|
+
vector<int> dist, par, pdir;
|
|
162
|
+
bfsBlocked(blk, start, dist, &par, &pdir);
|
|
163
|
+
int goal = -1, best = INF;
|
|
164
|
+
for (int k = 0; k < n; k++) {
|
|
165
|
+
if (own[k] == ME && dist[k] < best && dist[k] > 0) { best = dist[k]; goal = k; }
|
|
166
|
+
}
|
|
167
|
+
if (goal < 0) return -1;
|
|
168
|
+
vector<int> rev;
|
|
169
|
+
for (int k = goal; k != start; k = par[k]) rev.push_back(pdir[k]);
|
|
170
|
+
reverse(rev.begin(), rev.end());
|
|
171
|
+
for (int d : rev) dirs.push_back(d);
|
|
172
|
+
PathInfo info2;
|
|
173
|
+
if (!walkPath(dirs, info2, used)) return -1;
|
|
174
|
+
info = info2;
|
|
175
|
+
return info.captureLen;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------------- 圈地收益(模拟引擎的围地泛洪) ----------------
|
|
179
|
+
int computeCapture(const vector<pair<int, int>>& newTrail) {
|
|
180
|
+
int n = W * H;
|
|
181
|
+
static vector<uint8_t> wall, seen;
|
|
182
|
+
static vector<int> st;
|
|
183
|
+
wall.assign(n, 0);
|
|
184
|
+
for (int k = 0; k < n; k++) wall[k] = (own[k] == ME || trl[k] == ME) ? 1 : 0;
|
|
185
|
+
for (auto& pr : newTrail) wall[pr.first] = 1;
|
|
186
|
+
seen.assign(n, 0);
|
|
187
|
+
st.clear();
|
|
188
|
+
auto push = [&](int k) {
|
|
189
|
+
if (!wall[k] && !seen[k]) { seen[k] = 1; st.push_back(k); }
|
|
190
|
+
};
|
|
191
|
+
for (int x = 0; x < W; x++) { push(x); push((H - 1) * W + x); }
|
|
192
|
+
for (int y = 0; y < H; y++) { push(y * W); push(y * W + W - 1); }
|
|
193
|
+
while (!st.empty()) {
|
|
194
|
+
int k = st.back(); st.pop_back();
|
|
195
|
+
int x = k % W, y = k / W;
|
|
196
|
+
if (x > 0) push(k - 1);
|
|
197
|
+
if (x + 1 < W) push(k + 1);
|
|
198
|
+
if (y > 0) push(k - W);
|
|
199
|
+
if (y + 1 < H) push(k + W);
|
|
200
|
+
}
|
|
201
|
+
int gain = 0;
|
|
202
|
+
for (int k = 0; k < n; k++) {
|
|
203
|
+
if (own[k] == ME) continue;
|
|
204
|
+
if (prot[k] >= 0 && prot[k] != ME) continue;
|
|
205
|
+
if (wall[k] || !seen[k]) gain++;
|
|
206
|
+
}
|
|
207
|
+
return gain;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ---------------- 风险 ----------------
|
|
211
|
+
// 撞头预测:stepIdx 时我从 fromK 走到 toK
|
|
212
|
+
int headonRisk(int fromK, int toK, int stepIdx) {
|
|
213
|
+
int risk = 0;
|
|
214
|
+
for (int p = 0; p < N; p++) {
|
|
215
|
+
if (p == ME) continue;
|
|
216
|
+
int t = oppD[p][toK];
|
|
217
|
+
if (stepIdx == 0) {
|
|
218
|
+
int tx = P[p].x + DX[P[p].dir], ty = P[p].y + DY[P[p].dir];
|
|
219
|
+
int tgt = IDX(tx, ty);
|
|
220
|
+
if (t == 1) {
|
|
221
|
+
risk += (tgt == toK) ? 12 : 3; // 对方正走向我的目标格 → 同目标撞头
|
|
222
|
+
} else if (t == 0) {
|
|
223
|
+
if (tgt == fromK) risk += 12; // 互换位置
|
|
224
|
+
else risk -= 6; // 对方离开原格(若在其领地外我反而切断它)
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
if (t == stepIdx + 1) risk += 8; // 同目标
|
|
228
|
+
else if (t == stepIdx) risk += 3; // 可能互换
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return risk;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
int evalRisk(const PathInfo& info, int C, int& minTh) {
|
|
235
|
+
int sum = 0, mx = 0;
|
|
236
|
+
minTh = INF;
|
|
237
|
+
auto consider = [&](int k) {
|
|
238
|
+
int t = threat[k];
|
|
239
|
+
minTh = min(minTh, t);
|
|
240
|
+
// 只有真正贴近的对手才算风险:远处对手要绕路来切代价很高
|
|
241
|
+
if (t <= C + MARGIN && t <= 18) {
|
|
242
|
+
int v = C + MARGIN - t + 1;
|
|
243
|
+
sum += v;
|
|
244
|
+
mx = max(mx, v);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
for (int k = 0; k < W * H; k++) if (trl[k] == ME) consider(k);
|
|
248
|
+
int head = IDX(P[ME].x, P[ME].y);
|
|
249
|
+
int prev = head;
|
|
250
|
+
for (auto& pr : info.trailCells) {
|
|
251
|
+
int k = pr.first, step = pr.second;
|
|
252
|
+
consider(k);
|
|
253
|
+
sum += headonRisk(prev, k, step);
|
|
254
|
+
prev = k;
|
|
255
|
+
}
|
|
256
|
+
// 最危险的格主导,格数只占少量权重(否则大回路被系统性低估)
|
|
257
|
+
return (int)(mx * 2.2 + 0.08 * sum);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ---------------- 候选 ----------------
|
|
261
|
+
struct Cand {
|
|
262
|
+
vector<int> dirs;
|
|
263
|
+
int gain = 0, risk = 0, len = 0, cutVal = 0, minThreat = INF;
|
|
264
|
+
double score = -1e18;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
static vector<Cand> candPool;
|
|
268
|
+
|
|
269
|
+
int maxOppArea() {
|
|
270
|
+
int m = 0;
|
|
271
|
+
for (int p = 0; p < N; p++) if (p != ME) m = max(m, P[p].area);
|
|
272
|
+
return m;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
double riskWeight() {
|
|
276
|
+
double riskW = RISK_W;
|
|
277
|
+
const PInfo& me = P[ME];
|
|
278
|
+
int turnsLeft = MAX_TURNS - curTurn;
|
|
279
|
+
if (N == 2) {
|
|
280
|
+
int myA = me.area, oppA = P[1 - ME].area;
|
|
281
|
+
if (myA + 25 < oppA) riskW *= 0.72;
|
|
282
|
+
else if (myA > oppA + 70) riskW *= 1.35;
|
|
283
|
+
} else {
|
|
284
|
+
riskW *= 0.75;
|
|
285
|
+
int lead = maxOppArea();
|
|
286
|
+
if (me.area + 30 < lead) riskW *= 0.85;
|
|
287
|
+
else if (me.area > lead + 80) riskW *= 1.35;
|
|
288
|
+
}
|
|
289
|
+
// 终局:领先保平安,落后放手一搏
|
|
290
|
+
if (turnsLeft < 40) {
|
|
291
|
+
bool ahead = (N == 2) ? (me.area > P[1 - ME].area) : (me.area >= maxOppArea());
|
|
292
|
+
riskW *= ahead ? 1.5 : 0.85;
|
|
293
|
+
}
|
|
294
|
+
return riskW;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
void genCandidates(vector<Cand>& out) {
|
|
298
|
+
out.clear();
|
|
299
|
+
const PInfo& me = P[ME];
|
|
300
|
+
int n = W * H;
|
|
301
|
+
int turnsLeft = MAX_TURNS - curTurn;
|
|
302
|
+
int head = IDX(me.x, me.y);
|
|
303
|
+
bool inside = (own[head] == ME);
|
|
304
|
+
double riskW = riskWeight();
|
|
305
|
+
auto t0 = chrono::steady_clock::now();
|
|
306
|
+
|
|
307
|
+
struct RawCand {
|
|
308
|
+
vector<int> dirs;
|
|
309
|
+
double cheap;
|
|
310
|
+
int len;
|
|
311
|
+
bool needClose;
|
|
312
|
+
};
|
|
313
|
+
vector<RawCand> raw;
|
|
314
|
+
|
|
315
|
+
auto cheapScore = [&](const PathInfo& info, int len) {
|
|
316
|
+
int minx = W, maxx = 0, miny = H, maxy = 0;
|
|
317
|
+
for (auto& pr : info.trailCells) {
|
|
318
|
+
int k = pr.first;
|
|
319
|
+
int x = k % W, y = k / W;
|
|
320
|
+
minx = min(minx, x); maxx = max(maxx, x);
|
|
321
|
+
miny = min(miny, y); maxy = max(maxy, y);
|
|
322
|
+
}
|
|
323
|
+
double area = (info.trailCells.empty() ? 0 : (maxx - minx + 1) * (maxy - miny + 1));
|
|
324
|
+
return area * 0.55 - LEN_W * len + 0.6 * info.cutVal;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
PathInfo tmpInfo;
|
|
328
|
+
vector<uint8_t> tmpUsed;
|
|
329
|
+
|
|
330
|
+
if (inside && me.trailLen == 0) {
|
|
331
|
+
// --- 新回路:在自己领地内走到出口,出去画矩形,回来封口 ---
|
|
332
|
+
vector<signed char> blk(n);
|
|
333
|
+
for (int k = 0; k < n; k++) blk[k] = (own[k] == ME) ? 0 : 1;
|
|
334
|
+
vector<int> dist, par, pdir;
|
|
335
|
+
bfsBlocked(blk, head, dist, &par, &pdir);
|
|
336
|
+
vector<array<int, 3>> exits; // {dist, T, e}
|
|
337
|
+
for (int k = 0; k < n; k++) {
|
|
338
|
+
if (dist[k] == INF) continue;
|
|
339
|
+
int x = k % W, y = k / W;
|
|
340
|
+
for (int d = 0; d < 4; d++) {
|
|
341
|
+
int nx = x + DX[d], ny = y + DY[d];
|
|
342
|
+
if (!inb(nx, ny)) continue;
|
|
343
|
+
if (own[IDX(nx, ny)] == ME) continue;
|
|
344
|
+
exits.push_back({dist[k], k, d});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
sort(exits.begin(), exits.end());
|
|
348
|
+
vector<uint8_t> cellTaken(n, 0);
|
|
349
|
+
int perDir[4] = {0, 0, 0, 0};
|
|
350
|
+
int usedExits = 0;
|
|
351
|
+
for (auto& ex : exits) {
|
|
352
|
+
if (usedExits >= 8) break;
|
|
353
|
+
int T = ex[1], e = ex[2];
|
|
354
|
+
if (cellTaken[T] || perDir[e] >= 3) continue;
|
|
355
|
+
cellTaken[T] = 1; perDir[e]++; usedExits++;
|
|
356
|
+
vector<int> path0;
|
|
357
|
+
for (int k = T; k != head; k = par[k]) path0.push_back(pdir[k]);
|
|
358
|
+
reverse(path0.begin(), path0.end());
|
|
359
|
+
for (int a = 2; a <= AMAX; a++) {
|
|
360
|
+
for (int b = 1; b <= BMAX; b++) {
|
|
361
|
+
for (int si = 0; si < 2; si++) {
|
|
362
|
+
int s = (e < 2) ? 2 + si : si;
|
|
363
|
+
vector<int> dirs = path0;
|
|
364
|
+
for (int i = 0; i < a; i++) dirs.push_back(e);
|
|
365
|
+
for (int i = 0; i < b; i++) dirs.push_back(s);
|
|
366
|
+
for (int i = 0; i < a; i++) dirs.push_back(e ^ 1);
|
|
367
|
+
if (!walkPath(dirs, tmpInfo, tmpUsed)) continue;
|
|
368
|
+
int len = (tmpInfo.captureLen >= 0 ? tmpInfo.captureLen + 1
|
|
369
|
+
: (int)dirs.size() + 6);
|
|
370
|
+
raw.push_back({move(dirs), cheapScore(tmpInfo, len), len,
|
|
371
|
+
tmpInfo.captureLen < 0});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
// --- 在外带轨迹:封口回路,必要时先延伸再封 ---
|
|
378
|
+
for (int d = 0; d < 4; d++) {
|
|
379
|
+
if (d == (me.dir ^ 1)) continue;
|
|
380
|
+
for (int x = 1; x <= 8; x++) {
|
|
381
|
+
vector<int> base(x, d);
|
|
382
|
+
if (!walkPath(base, tmpInfo, tmpUsed) || tmpInfo.captureLen >= 0) break;
|
|
383
|
+
for (int si = 0; si < 2; si++) {
|
|
384
|
+
int s = (d < 2) ? 2 + si : si;
|
|
385
|
+
for (int y = 1; y <= 8; y++) {
|
|
386
|
+
vector<int> dirs = base;
|
|
387
|
+
for (int i = 0; i < y; i++) dirs.push_back(s);
|
|
388
|
+
if (!walkPath(dirs, tmpInfo, tmpUsed)) break;
|
|
389
|
+
int len = (tmpInfo.captureLen >= 0 ? tmpInfo.captureLen + 1
|
|
390
|
+
: (int)dirs.size() + 6);
|
|
391
|
+
raw.push_back({move(dirs), cheapScore(tmpInfo, len), len,
|
|
392
|
+
tmpInfo.captureLen < 0});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 便宜排序,只对前 K 名做精确评估
|
|
400
|
+
sort(raw.begin(), raw.end(), [](const RawCand& a, const RawCand& b) {
|
|
401
|
+
return a.cheap > b.cheap;
|
|
402
|
+
});
|
|
403
|
+
const int TOPK = 140;
|
|
404
|
+
for (int i = 0; i < (int)raw.size() && i < TOPK; i++) {
|
|
405
|
+
if ((i & 15) == 15) {
|
|
406
|
+
auto ms = chrono::duration<double, milli>(chrono::steady_clock::now() - t0).count();
|
|
407
|
+
if (ms > 16.0) break;
|
|
408
|
+
}
|
|
409
|
+
vector<int> dirs = move(raw[i].dirs);
|
|
410
|
+
PathInfo info;
|
|
411
|
+
vector<uint8_t> used2;
|
|
412
|
+
if (!walkPath(dirs, info, used2)) continue;
|
|
413
|
+
int C;
|
|
414
|
+
if (info.captureLen >= 0) {
|
|
415
|
+
C = info.captureLen;
|
|
416
|
+
dirs.resize(C + 1);
|
|
417
|
+
} else {
|
|
418
|
+
C = closePath(dirs, info, used2);
|
|
419
|
+
if (C < 0) continue;
|
|
420
|
+
dirs.resize(C + 1);
|
|
421
|
+
}
|
|
422
|
+
int len = C + 1;
|
|
423
|
+
int gain = computeCapture(info.trailCells);
|
|
424
|
+
if (gain <= 0 && info.cutVal == 0) continue;
|
|
425
|
+
int minTh = INF;
|
|
426
|
+
int risk = evalRisk(info, C, minTh);
|
|
427
|
+
Cand cd;
|
|
428
|
+
cd.dirs = move(dirs);
|
|
429
|
+
cd.gain = gain; cd.risk = risk; cd.len = len;
|
|
430
|
+
cd.cutVal = info.cutVal; cd.minThreat = minTh;
|
|
431
|
+
cd.score = gain + 0.85 * info.cutVal - LEN_W * len - riskW * risk;
|
|
432
|
+
if (len > turnsLeft) cd.score -= (turnsLeft < 40 ? 25.0 : 8.0) * (len - turnsLeft + 1);
|
|
433
|
+
out.push_back(move(cd));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// ---------------- 决策 ----------------
|
|
438
|
+
vector<int> plan;
|
|
439
|
+
int lastDeaths = -1;
|
|
440
|
+
int planRisk0 = INF; // 计划采纳时的风险基准
|
|
441
|
+
|
|
442
|
+
int tryImmediateCut() {
|
|
443
|
+
const PInfo& me = P[ME];
|
|
444
|
+
int bestD = -1, bestVal = -1;
|
|
445
|
+
int leadArea = maxOppArea();
|
|
446
|
+
for (int d = 0; d < 4; d++) {
|
|
447
|
+
if (d == (me.dir ^ 1)) continue;
|
|
448
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
449
|
+
if (!inb(nx, ny)) continue;
|
|
450
|
+
int k = IDX(nx, ny);
|
|
451
|
+
if (trl[k] == ME || trl[k] < 0) continue;
|
|
452
|
+
int p = trl[k];
|
|
453
|
+
// 对方头部就在该格且正走向我 → 互换同亡,不划算
|
|
454
|
+
if (P[p].x == nx && P[p].y == ny) {
|
|
455
|
+
int tx = P[p].x + DX[P[p].dir], ty = P[p].y + DY[P[p].dir];
|
|
456
|
+
if (tx == me.x && ty == me.y) continue;
|
|
457
|
+
}
|
|
458
|
+
// 该格上其他人能下一回合到达 → 撞头风险
|
|
459
|
+
int th = INF;
|
|
460
|
+
for (int q = 0; q < N; q++) {
|
|
461
|
+
if (q == ME || q == p) continue;
|
|
462
|
+
th = min(th, oppD[q][k]);
|
|
463
|
+
}
|
|
464
|
+
if (th <= 1) continue;
|
|
465
|
+
int val = 20 + 3 * P[p].trailLen;
|
|
466
|
+
if (N == 4 && P[p].area >= leadArea) val = val * 3 / 2;
|
|
467
|
+
if (val > bestVal) { bestVal = val; bestD = d; }
|
|
468
|
+
}
|
|
469
|
+
return bestD;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// 追击对手轨迹(含其暴露的头部),距离内且路径安全时出击
|
|
473
|
+
int tryCutPursuit() {
|
|
474
|
+
const PInfo& me = P[ME];
|
|
475
|
+
if (me.trailLen > 8) return -1; // 自己拖着长尾时先顾自己
|
|
476
|
+
int n = W * H;
|
|
477
|
+
vector<signed char> blk(n);
|
|
478
|
+
for (int k = 0; k < n; k++) blk[k] = (trl[k] == ME) ? 1 : 0;
|
|
479
|
+
vector<int> dist, par, pdir;
|
|
480
|
+
bfsBlocked(blk, IDX(me.x, me.y), dist, &par, &pdir);
|
|
481
|
+
int goal = -1, best = INF, victim = -1;
|
|
482
|
+
for (int k = 0; k < n; k++) {
|
|
483
|
+
if (trl[k] < 0 || trl[k] == ME) continue;
|
|
484
|
+
if (dist[k] <= 0 || dist[k] > PURSUIT_MAX) continue;
|
|
485
|
+
int p = trl[k];
|
|
486
|
+
int val = 20 + 3 * P[p].trailLen;
|
|
487
|
+
if (N == 4 && P[p].area >= maxOppArea()) val = val * 3 / 2;
|
|
488
|
+
// 略偏好更近的
|
|
489
|
+
int key = val - 2 * dist[k];
|
|
490
|
+
if (goal < 0 || key > best) { best = key; goal = k; victim = p; }
|
|
491
|
+
}
|
|
492
|
+
if (goal < 0) return -1;
|
|
493
|
+
// 还原路径并检查安全性
|
|
494
|
+
vector<int> rev;
|
|
495
|
+
for (int k = goal; k != IDX(me.x, me.y); k = par[k]) rev.push_back(pdir[k]);
|
|
496
|
+
reverse(rev.begin(), rev.end());
|
|
497
|
+
int x = me.x, y = me.y;
|
|
498
|
+
for (int i = 0; i < (int)rev.size(); i++) {
|
|
499
|
+
x += DX[rev[i]]; y += DY[rev[i]];
|
|
500
|
+
int k = IDX(x, y);
|
|
501
|
+
// 撞头/被其他人切的风险
|
|
502
|
+
for (int p = 0; p < N; p++) {
|
|
503
|
+
if (p == ME || p == victim) continue;
|
|
504
|
+
if (oppD[p][k] <= i + 1) return -1;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
int d = rev[0];
|
|
508
|
+
if (d == (me.dir ^ 1)) return -1;
|
|
509
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
510
|
+
if (!inb(nx, ny) || trl[IDX(nx, ny)] == ME) return -1;
|
|
511
|
+
return d;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
int safeFallback() {
|
|
515
|
+
const PInfo& me = P[ME];
|
|
516
|
+
int bestD = -1, bestScore = -INF;
|
|
517
|
+
for (int d = 0; d < 4; d++) {
|
|
518
|
+
if (d == (me.dir ^ 1)) continue;
|
|
519
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
520
|
+
if (!inb(nx, ny)) continue;
|
|
521
|
+
int k = IDX(nx, ny);
|
|
522
|
+
if (trl[k] == ME) continue;
|
|
523
|
+
int sc = 0;
|
|
524
|
+
if (own[k] == ME) sc += 20;
|
|
525
|
+
if (threat[k] <= 1) sc -= 60;
|
|
526
|
+
if (threat[k] <= 2) sc -= 10;
|
|
527
|
+
if (trl[k] >= 0 && trl[k] != ME) sc += 40;
|
|
528
|
+
if (sc > bestScore) { bestScore = sc; bestD = d; }
|
|
529
|
+
}
|
|
530
|
+
return bestD >= 0 ? bestD : me.dir;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// 撞头过滤器:即将撞头时改为更安全的合法移动
|
|
534
|
+
int applyCollisionFilter(int d) {
|
|
535
|
+
const PInfo& me = P[ME];
|
|
536
|
+
int cur = IDX(me.x, me.y);
|
|
537
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
538
|
+
if (!inb(nx, ny)) return d;
|
|
539
|
+
int risk = headonRisk(cur, IDX(nx, ny), 0);
|
|
540
|
+
if (risk < 8) return d;
|
|
541
|
+
int bestD = -1, bestScore = INF;
|
|
542
|
+
for (int dd = 0; dd < 4; dd++) {
|
|
543
|
+
if (dd == (me.dir ^ 1)) continue;
|
|
544
|
+
int tx = me.x + DX[dd], ty = me.y + DY[dd];
|
|
545
|
+
if (!inb(tx, ty)) continue;
|
|
546
|
+
int k = IDX(tx, ty);
|
|
547
|
+
if (trl[k] == ME) continue;
|
|
548
|
+
int sc = headonRisk(cur, k, 0) * 10;
|
|
549
|
+
if (dd == me.dir) sc -= 3;
|
|
550
|
+
if (own[k] == ME) sc -= 6;
|
|
551
|
+
if (threat[k] <= 1) sc += 25;
|
|
552
|
+
if (sc < bestScore) { bestScore = sc; bestD = dd; }
|
|
553
|
+
}
|
|
554
|
+
return bestD >= 0 ? bestD : d;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
int decide() {
|
|
558
|
+
const PInfo& me = P[ME];
|
|
559
|
+
int turnsLeft = MAX_TURNS - curTurn;
|
|
560
|
+
|
|
561
|
+
if (me.deaths != lastDeaths) {
|
|
562
|
+
plan.clear();
|
|
563
|
+
lastDeaths = me.deaths;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
computeFields();
|
|
567
|
+
|
|
568
|
+
int chosen = -1;
|
|
569
|
+
|
|
570
|
+
// 1) 立即切断机会
|
|
571
|
+
int cutDir = tryImmediateCut();
|
|
572
|
+
if (cutDir >= 0) {
|
|
573
|
+
plan.clear();
|
|
574
|
+
chosen = cutDir;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// 2) 校验并执行既有计划
|
|
578
|
+
if (chosen < 0 && !plan.empty()) {
|
|
579
|
+
PathInfo info;
|
|
580
|
+
vector<uint8_t> used;
|
|
581
|
+
bool okPath = walkPath(plan, info, used) && info.captureLen == (int)plan.size() - 1;
|
|
582
|
+
if (okPath) {
|
|
583
|
+
int C = (int)plan.size() - 1;
|
|
584
|
+
int d = plan[0];
|
|
585
|
+
int nx = me.x + DX[d], ny = me.y + DY[d];
|
|
586
|
+
bool legal = (d != (me.dir ^ 1)) && inb(nx, ny) && trl[IDX(nx, ny)] != ME;
|
|
587
|
+
int minTh = INF;
|
|
588
|
+
int risk = evalRisk(info, C, minTh);
|
|
589
|
+
// 风险没有显著恶化就继续执行;恶化才重新规划
|
|
590
|
+
bool safe = legal && (risk <= planRisk0 * 1.5 + 10) && risk <= 400;
|
|
591
|
+
if (safe) {
|
|
592
|
+
plan.erase(plan.begin());
|
|
593
|
+
chosen = d;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (chosen < 0) plan.clear();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// 2b) 追击对手轨迹
|
|
600
|
+
if (chosen < 0) {
|
|
601
|
+
int pursuitDir = tryCutPursuit();
|
|
602
|
+
if (pursuitDir >= 0) chosen = pursuitDir;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// 3) 重新规划
|
|
606
|
+
if (chosen < 0) {
|
|
607
|
+
candPool.clear();
|
|
608
|
+
genCandidates(candPool);
|
|
609
|
+
if (!candPool.empty()) {
|
|
610
|
+
Cand* best = &candPool[0];
|
|
611
|
+
for (auto& c : candPool) if (c.score > best->score) best = &c;
|
|
612
|
+
plan = best->dirs;
|
|
613
|
+
planRisk0 = best->risk;
|
|
614
|
+
chosen = plan.front();
|
|
615
|
+
plan.erase(plan.begin());
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// 4) 兜底
|
|
620
|
+
if (chosen < 0) chosen = safeFallback();
|
|
621
|
+
|
|
622
|
+
int finalD = applyCollisionFilter(chosen);
|
|
623
|
+
if (finalD != chosen) plan.clear();
|
|
624
|
+
return finalD;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
int main() {
|
|
628
|
+
ios::sync_with_stdio(false);
|
|
629
|
+
cin.tie(nullptr);
|
|
630
|
+
string tok;
|
|
631
|
+
cin >> tok; // INIT
|
|
632
|
+
cin >> W >> H >> MAX_TURNS >> N >> ME >> MOVE_MS >> INIT_MS;
|
|
633
|
+
spawnPos.resize(N);
|
|
634
|
+
spawnDir.assign(N, 0);
|
|
635
|
+
for (int i = 0; i < N; i++) {
|
|
636
|
+
int id, x, y;
|
|
637
|
+
cin >> tok >> id >> x >> y;
|
|
638
|
+
spawnPos[id] = {x, y};
|
|
639
|
+
}
|
|
640
|
+
prot.assign(W * H, -1);
|
|
641
|
+
for (int i = 0; i < N; i++) {
|
|
642
|
+
int sx = spawnPos[i].first, sy = spawnPos[i].second;
|
|
643
|
+
for (int y = sy - 1; y <= sy + 1; y++)
|
|
644
|
+
for (int x = sx - 1; x <= sx + 1; x++)
|
|
645
|
+
if (inb(x, y)) prot[IDX(x, y)] = i;
|
|
646
|
+
}
|
|
647
|
+
while (readState()) {
|
|
648
|
+
int d = decide();
|
|
649
|
+
cout << curTurn << ' ' << DC[d] << endl;
|
|
650
|
+
}
|
|
651
|
+
return 0;
|
|
652
|
+
}
|