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.
Files changed (221) hide show
  1. package/README.md +91 -13
  2. package/assets/commit0/instance.json +30 -0
  3. package/assets/commit0/workspace.zip +0 -0
  4. package/assets/featurebench/hidden/test_regression.py +690 -0
  5. package/assets/featurebench/instance.json +16 -0
  6. package/assets/featurebench/workspace.zip +0 -0
  7. package/assets/swe-bench-pro/hidden/test.patch +36 -0
  8. package/assets/swe-bench-pro/instance.json +10 -0
  9. package/assets/swe-bench-pro/workspace.zip +0 -0
  10. package/eval/README.md +18 -0
  11. package/eval/arena/arena/README.md +21 -0
  12. package/eval/arena/arena/bt.py +104 -0
  13. package/eval/arena/arena/clock.py +15 -0
  14. package/eval/arena/arena/core.py +265 -0
  15. package/eval/arena/arena/run.cmd +24 -0
  16. package/eval/arena/arena/run.sh +11 -0
  17. package/eval/arena/arena/schedule.py +79 -0
  18. package/eval/arena/arena/tournament.py +183 -0
  19. package/eval/arena/bomberman/bots/README.md +16 -0
  20. package/eval/arena/bomberman/bots/deepseek-v4.1-flash.cpp +447 -0
  21. package/eval/arena/bomberman/bots/doubao-seed-2.1.cpp +542 -0
  22. package/eval/arena/bomberman/bots/glm-5.3.cpp +406 -0
  23. package/eval/arena/bomberman/bots/gpt-6-astra.cpp +768 -0
  24. package/eval/arena/bomberman/bots/gpt-6-sol.cpp +444 -0
  25. package/eval/arena/bomberman/bots/kimi-k3.cpp +432 -0
  26. package/eval/arena/bomberman/bots/mimo-v2.6-pro.cpp +529 -0
  27. package/eval/arena/bomberman/bots/opus-5.5.cpp +548 -0
  28. package/eval/arena/bomberman/bots/qwen-3.8-max.cpp +836 -0
  29. package/eval/arena/bomberman/tournament/README.md +11 -0
  30. package/eval/arena/bomberman/tournament/bt.py +56 -0
  31. package/eval/arena/bomberman/tournament/evaluate.py +199 -0
  32. package/eval/arena/bomberman/tournament/run.py +79 -0
  33. package/eval/arena/bomberman/tournament/schedule-2to10.json.gz +0 -0
  34. package/eval/arena/bomberman/workspace/MANIFEST.json +13 -0
  35. package/eval/arena/bomberman/workspace/README.md +29 -0
  36. package/eval/arena/bomberman/workspace/RULES.md +100 -0
  37. package/eval/arena/bomberman/workspace/baseline.cpp +240 -0
  38. package/eval/arena/bomberman/workspace/clock.py +25 -0
  39. package/eval/arena/bomberman/workspace/engine/arena.py +198 -0
  40. package/eval/arena/bomberman/workspace/engine/build.py +35 -0
  41. package/eval/arena/bomberman/workspace/engine/engine.py +256 -0
  42. package/eval/arena/bomberman/workspace/engine/verify_replay.py +24 -0
  43. package/eval/arena/bomberman/workspace/run.cmd +28 -0
  44. package/eval/arena/bomberman/workspace/run.sh +16 -0
  45. package/eval/arena/bomberman/workspace/viewer/index.html +42 -0
  46. package/eval/arena/ctf/bots/README.md +18 -0
  47. package/eval/arena/ctf/bots/deepseek-v4.1-flash.cpp +601 -0
  48. package/eval/arena/ctf/bots/doubao-seed-2.1-turbo.cpp +320 -0
  49. package/eval/arena/ctf/bots/fable-5.1.cpp +634 -0
  50. package/eval/arena/ctf/bots/glm-5.3.cpp +689 -0
  51. package/eval/arena/ctf/bots/gpt-6-astra.cpp +657 -0
  52. package/eval/arena/ctf/bots/gpt-6.1-sol.cpp +725 -0
  53. package/eval/arena/ctf/bots/kimi-k3.cpp +667 -0
  54. package/eval/arena/ctf/bots/mimo-v2.6-pro.cpp +533 -0
  55. package/eval/arena/ctf/bots/opus-5.5.cpp +645 -0
  56. package/eval/arena/ctf/bots/qwen-3.8-max.cpp +726 -0
  57. package/eval/arena/ctf/bots/sonnet-5.5.cpp +569 -0
  58. package/eval/arena/ctf/tournament/README.md +15 -0
  59. package/eval/arena/ctf/tournament/formal-2to8.json +31 -0
  60. package/eval/arena/ctf/tournament/formal-9to15.json +31 -0
  61. package/eval/arena/ctf/workspace/README.md +41 -0
  62. package/eval/arena/ctf/workspace/RULES.md +119 -0
  63. package/eval/arena/ctf/workspace/arena.py +186 -0
  64. package/eval/arena/ctf/workspace/baseline.cpp +257 -0
  65. package/eval/arena/ctf/workspace/clock.py +15 -0
  66. package/eval/arena/ctf/workspace/core.py +265 -0
  67. package/eval/arena/ctf/workspace/engine.py +389 -0
  68. package/eval/arena/ctf/workspace/run.cmd +24 -0
  69. package/eval/arena/ctf/workspace/run.sh +11 -0
  70. package/eval/arena/ctf/workspace/viewer.html +71 -0
  71. package/eval/arena/land/bots/README.md +17 -0
  72. package/eval/arena/land/bots/deepseek-4.1f@workbuddy#1/bot.cpp +608 -0
  73. package/eval/arena/land/bots/glm-5.3@workbuddy#1/bot.cpp +521 -0
  74. package/eval/arena/land/bots/gpt-6-astra@codex#1/bot.cpp +373 -0
  75. package/eval/arena/land/bots/gpt-6-sol@codex#1/bot.cpp +341 -0
  76. package/eval/arena/land/bots/kimi-k3@workbuddy#1/bot.cpp +492 -0
  77. package/eval/arena/land/bots/mimo-2.6-pro@zcode#1/bot.cpp +652 -0
  78. package/eval/arena/land/bots/mystery-model@zcode#1/bot.cpp +466 -0
  79. package/eval/arena/land/bots/opus-5.5@claude-code#1/bot.cpp +630 -0
  80. package/eval/arena/land/bots/sonnet-5@claude-code#1/bot.cpp +619 -0
  81. package/eval/arena/land/tournament/make_replay_page.py +17 -0
  82. package/eval/arena/land/tournament/rate.py +290 -0
  83. package/eval/arena/land/tournament/round_robin.py +172 -0
  84. package/eval/arena/land/tournament/sparring.cpp +356 -0
  85. package/eval/arena/land/workspace/RULES.md +114 -0
  86. package/eval/arena/land/workspace/TASK.md +46 -0
  87. package/eval/arena/land/workspace/anchors/.build/greedy_f2e6d2dea5ca +0 -0
  88. package/eval/arena/land/workspace/anchors/greedy.cpp +194 -0
  89. package/eval/arena/land/workspace/anchors/random.cpp +80 -0
  90. package/eval/arena/land/workspace/clock.py +64 -0
  91. package/eval/arena/land/workspace/engine/build.py +33 -0
  92. package/eval/arena/land/workspace/engine/game.py +273 -0
  93. package/eval/arena/land/workspace/engine/referee.py +308 -0
  94. package/eval/arena/land/workspace/starter/.build/bot_be32b45b4699 +0 -0
  95. package/eval/arena/land/workspace/starter/bot.cpp +82 -0
  96. package/eval/arena/land/workspace/viewer/viewer.html +210 -0
  97. package/eval/arena/tank/bots/README.md +24 -0
  98. package/eval/arena/tank/bots/half1/deepseek-v4.1-flash.cpp +367 -0
  99. package/eval/arena/tank/bots/half1/doubao-seed-evolving.cpp +402 -0
  100. package/eval/arena/tank/bots/half1/gemini-4-argon.cpp +1132 -0
  101. package/eval/arena/tank/bots/half1/glm-5.3.cpp +551 -0
  102. package/eval/arena/tank/bots/half1/gpt-6-astra.cpp +233 -0
  103. package/eval/arena/tank/bots/half1/gpt-6.1-sol-ultrafast.cpp +350 -0
  104. package/eval/arena/tank/bots/half1/gpt-6.1-sol.cpp +78 -0
  105. package/eval/arena/tank/bots/half1/grok-4.7.cpp +1099 -0
  106. package/eval/arena/tank/bots/half1/haiku-5.5.cpp +210 -0
  107. package/eval/arena/tank/bots/half1/kimi-k3.cpp +353 -0
  108. package/eval/arena/tank/bots/half1/mimo-v2.6-pro.cpp +336 -0
  109. package/eval/arena/tank/bots/half1/muse-wonder-full.cpp +560 -0
  110. package/eval/arena/tank/bots/half1/opus-5.5.cpp +435 -0
  111. package/eval/arena/tank/bots/half1/qwen-3.8-max.cpp +537 -0
  112. package/eval/arena/tank/bots/half2/deepseek-v4.1-flash.cpp +425 -0
  113. package/eval/arena/tank/bots/half2/doubao-seed-evolving.cpp +308 -0
  114. package/eval/arena/tank/bots/half2/gemini-4-argon.cpp +1390 -0
  115. package/eval/arena/tank/bots/half2/glm-5.3.cpp +651 -0
  116. package/eval/arena/tank/bots/half2/gpt-6-astra.cpp +241 -0
  117. package/eval/arena/tank/bots/half2/gpt-6.1-sol-ultrafast.cpp +356 -0
  118. package/eval/arena/tank/bots/half2/gpt-6.1-sol.cpp +87 -0
  119. package/eval/arena/tank/bots/half2/grok-4.7.cpp +1205 -0
  120. package/eval/arena/tank/bots/half2/haiku-5.5.cpp +210 -0
  121. package/eval/arena/tank/bots/half2/kimi-k3.cpp +487 -0
  122. package/eval/arena/tank/bots/half2/mimo-v2.6-pro.cpp +336 -0
  123. package/eval/arena/tank/bots/half2/muse-wonder-full.cpp +560 -0
  124. package/eval/arena/tank/bots/half2/opus-5.5.cpp +476 -0
  125. package/eval/arena/tank/bots/half2/qwen-3.8-max.cpp +392 -0
  126. package/eval/arena/tank/tournament/README.md +24 -0
  127. package/eval/arena/tank/tournament/bt.py +218 -0
  128. package/eval/arena/tank/tournament/final.json +202 -0
  129. package/eval/arena/tank/tournament/halftime.json +146 -0
  130. package/eval/arena/tank/tournament/progress.json +911 -0
  131. package/eval/arena/tank/tournament/schedule.py +100 -0
  132. package/eval/arena/tank/tournament/sparring.cpp +928 -0
  133. package/eval/arena/tank/tournament/tournament.py +1426 -0
  134. package/eval/arena/tank/workspace/README.md +169 -0
  135. package/eval/arena/tank/workspace/RULES.md +443 -0
  136. package/eval/arena/tank/workspace/arena.py +862 -0
  137. package/eval/arena/tank/workspace/baseline.cpp +259 -0
  138. package/eval/arena/tank/workspace/clock.py +103 -0
  139. package/eval/arena/tank/workspace/core.py +712 -0
  140. package/eval/arena/tank/workspace/engine.py +573 -0
  141. package/eval/arena/tank/workspace/history/.lock +0 -0
  142. package/eval/arena/tank/workspace/history/20261017-193610-08715287f91f-bot.cpp +109 -0
  143. package/eval/arena/tank/workspace/history/20261017-193619-f00b2d5635fa-gpt-6-astra.cpp +241 -0
  144. package/eval/arena/tank/workspace/history/20261017-193643-63319e0a2b1a-gpt-6_1-sol-ultrafast.cpp +356 -0
  145. package/eval/arena/tank/workspace/history/20261017-193647-41c1341d0a8a-gemini-4-argon.cpp +1390 -0
  146. package/eval/arena/tank/workspace/history/20261017-193652-e34c0f45539a-gpt-6_1-sol.cpp +87 -0
  147. package/eval/arena/tank/workspace/history/20261017-193654-c026348ce96e-opus-5_5.cpp +476 -0
  148. package/eval/arena/tank/workspace/history/20261017-193655-4a21366e94d1-muse-wonder-full.cpp +560 -0
  149. package/eval/arena/tank/workspace/history/20261017-193657-dbc4e9969c52-mimo-v2_6-pro.cpp +336 -0
  150. package/eval/arena/tank/workspace/history/20261017-193703-723cd036eb31-grok-4_7.cpp +1205 -0
  151. package/eval/arena/tank/workspace/history/20261017-193707-1ebbb227be68-deepseek-v4_1-flash.cpp +425 -0
  152. package/eval/arena/tank/workspace/history/20261017-193709-aeb0e7202ad5-doubao-seed-evolving.cpp +308 -0
  153. package/eval/arena/tank/workspace/history/20261017-193710-b21ebeb9bc76-kimi-k3.cpp +487 -0
  154. package/eval/arena/tank/workspace/history/20261017-193712-54cd86531905-haiku-5_5.cpp +210 -0
  155. package/eval/arena/tank/workspace/history/20261017-193714-efdb8e35c0bf-qwen-3_8-max.cpp +392 -0
  156. package/eval/arena/tank/workspace/history/20261017-193715-681423c23fdb-glm-5_3.cpp +651 -0
  157. package/eval/arena/tank/workspace/history/20261017-193717-1a8b3c75181d-sparring.cpp +928 -0
  158. package/eval/arena/tank/workspace/history/20261017-193720-1e0803a541e8-baseline.cpp +259 -0
  159. package/eval/arena/tank/workspace/history/log.jsonl +103 -0
  160. package/eval/arena/tank/workspace/judge/cycles.hpp +53 -0
  161. package/eval/arena/tank/workspace/judge/fast.cpp +337 -0
  162. package/eval/arena/tank/workspace/judge/referee.cpp +125 -0
  163. package/eval/arena/tank/workspace/judge/speed.cpp +99 -0
  164. package/eval/arena/tank/workspace/run.cmd +31 -0
  165. package/eval/arena/tank/workspace/run.sh +23 -0
  166. package/eval/arena/tank/workspace/tank.hpp +1762 -0
  167. package/eval/arena/tank/workspace/tank_main.cpp +215 -0
  168. package/eval/arena/tank/workspace/viewer.html +1150 -0
  169. package/eval/arena/warehouse/workspace/SPEC.md +130 -0
  170. package/eval/arena/warehouse/workspace/TASK.md +71 -0
  171. package/eval/arena/warehouse/workspace/baseline/common.h +88 -0
  172. package/eval/arena/warehouse/workspace/baseline/main.cpp +27 -0
  173. package/eval/arena/warehouse/workspace/baseline/old_stuff.cpp +87 -0
  174. package/eval/arena/warehouse/workspace/baseline/sim.cpp +427 -0
  175. package/eval/arena/warehouse/workspace/baseline/util.cpp +220 -0
  176. package/eval/arena/warehouse/workspace/clock.py +42 -0
  177. package/eval/arena/warehouse/workspace/src/common.h +88 -0
  178. package/eval/arena/warehouse/workspace/src/main.cpp +27 -0
  179. package/eval/arena/warehouse/workspace/src/old_stuff.cpp +87 -0
  180. package/eval/arena/warehouse/workspace/src/sim.cpp +427 -0
  181. package/eval/arena/warehouse/workspace/src/util.cpp +220 -0
  182. package/eval/arena/warehouse/workspace/tools/bench.py +119 -0
  183. package/eval/arena/warehouse/workspace/tools/check_input.py +161 -0
  184. package/eval/arena/warehouse/workspace/tools/gen.py +132 -0
  185. package/eval/arena/warehouse/workspace/tools/measure.py +107 -0
  186. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.in +1420 -0
  187. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.out +9162 -0
  188. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.in +1465 -0
  189. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.out +3439 -0
  190. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.in +2757 -0
  191. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.out +3126 -0
  192. package/eval/arena/warehouse/workspace/workloads/public/pub_small.in +731 -0
  193. package/eval/arena/warehouse/workspace/workloads/public/pub_small.out +2578 -0
  194. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.in +528 -0
  195. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.out +2026 -0
  196. package/eval/bomberman.py +20 -0
  197. package/eval/commit0.py +21 -0
  198. package/eval/common.py +61 -0
  199. package/eval/ctf.py +20 -0
  200. package/eval/featurebench.py +25 -0
  201. package/eval/land.py +20 -0
  202. package/eval/legacy/bomberman-prices.json +4 -0
  203. package/eval/legacy/bomberman.py +161 -0
  204. package/eval/legacy/commit0.py +91 -0
  205. package/eval/legacy/ctf-prices.json +4 -0
  206. package/eval/legacy/ctf.py +178 -0
  207. package/eval/legacy/featurebench.py +103 -0
  208. package/eval/legacy/land-prices.json +4 -0
  209. package/eval/legacy/land.py +177 -0
  210. package/eval/legacy/swe_bench_pro.py +116 -0
  211. package/eval/legacy/tank-prices.json +3 -0
  212. package/eval/legacy/tank.py +408 -0
  213. package/eval/legacy/warehouse-prices.json +4 -0
  214. package/eval/legacy/warehouse.py +365 -0
  215. package/eval/swe-bench-pro.py +25 -0
  216. package/eval/tank.py +20 -0
  217. package/eval/warehouse.py +20 -0
  218. package/lib/client/index.js +376 -63
  219. package/lib/client/index.js.map +1 -1
  220. package/lib/index.js +684 -27
  221. package/package.json +2 -1
@@ -0,0 +1,667 @@
1
+ // 夺旗 bot:统一控制 3 个角色,支持 2-15 方。
2
+ // 策略:任务分配(取旗/拦截/护送/占位)+ Dijkstra 代价寻路 + 集火战斗 + 卡住检测与争夺处理。
3
+ #include <bits/stdc++.h>
4
+ using namespace std;
5
+
6
+ struct Unit { int id, team, x, y, hp, flag, respawn_at; };
7
+ struct Flag { int id; string status; int x, y, holder, return_at; };
8
+ struct Event { string type; vector<int> args; };
9
+
10
+ struct Game {
11
+ int teams = 0, me = 0, size = 0, turns = 0, hp = 0, damage = 0, respawn = 0, flag_return = 0, flag_cooldown = 0;
12
+ vector<string> map;
13
+ vector<pair<int, int>> bases;
14
+ vector<pair<int, int>> spots;
15
+ int turn = 0;
16
+ vector<int> score;
17
+ vector<Unit> units;
18
+ vector<Flag> flags;
19
+ vector<Event> events;
20
+ };
21
+
22
+ bool read_turn(Game& g) {
23
+ string w;
24
+ while (cin >> w) {
25
+ if (w == "INIT") {
26
+ cin >> g.teams >> g.me >> g.size >> g.turns >> g.hp >> g.damage >> g.respawn >> g.flag_return >> g.flag_cooldown;
27
+ } else if (w == "MAP") {
28
+ g.map.assign(g.size, "");
29
+ for (auto& row : g.map) cin >> row;
30
+ } else if (w == "BASES") {
31
+ int k; cin >> k; g.bases.resize(k);
32
+ for (auto& b : g.bases) cin >> b.first >> b.second;
33
+ } else if (w == "SPOTS") {
34
+ int k; cin >> k; g.spots.resize(k);
35
+ for (auto& s : g.spots) cin >> s.first >> s.second;
36
+ } else if (w == "TURN") {
37
+ cin >> g.turn;
38
+ } else if (w == "SCORE") {
39
+ g.score.resize(g.teams);
40
+ for (auto& s : g.score) cin >> s;
41
+ } else if (w == "UNITS") {
42
+ int k; cin >> k; g.units.resize(k);
43
+ for (auto& u : g.units) { string tag; cin >> tag >> u.id >> u.team >> u.x >> u.y >> u.hp >> u.flag >> u.respawn_at; }
44
+ } else if (w == "FLAGS") {
45
+ int k; cin >> k; g.flags.resize(k);
46
+ for (auto& f : g.flags) { string tag; cin >> tag >> f.id >> f.status >> f.x >> f.y >> f.holder >> f.return_at; }
47
+ } else if (w == "EVENTS") {
48
+ int k; cin >> k; g.events.assign(k, {});
49
+ string line; getline(cin, line);
50
+ for (auto& e : g.events) {
51
+ getline(cin, line);
52
+ istringstream in(line);
53
+ string tag; in >> tag >> e.type;
54
+ for (int v; in >> v;) e.args.push_back(v);
55
+ }
56
+ } else if (w == "END") {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+
63
+ static const int DX[5] = {0, 0, -1, 1, 0};
64
+ static const int DY[5] = {-1, 1, 0, 0, 0};
65
+ static const char MVC[5] = {'U', 'D', 'L', 'R', 'S'};
66
+
67
+ struct Solver {
68
+ Game g;
69
+ int N, S, CELLS;
70
+ vector<int> wall;
71
+ vector<vector<int>> teamBaseDist;
72
+ vector<vector<int>> spawnOrder;
73
+ int centerx, centery;
74
+ // 跨回合状态
75
+ int prevPred[3][2] = {{-1, -1}, {-1, -1}, {-1, -1}};
76
+ int stuck[3] = {0, 0, 0};
77
+ int banCell[3] = {-1, -1, -1}; // 上回合想进但没进成的格
78
+
79
+ int cid(int x, int y) const { return y * S + x; }
80
+ bool isWall(int x, int y) const { return x < 0 || y < 0 || x >= S || y >= S || wall[cid(x, y)]; }
81
+
82
+ bool canAtk(int ax, int ay, int bx, int by) const {
83
+ int dx = bx - ax, dy = by - ay;
84
+ if (abs(dx) + abs(dy) > 2) return false;
85
+ if (abs(dx) == 2 && dy == 0) return !isWall(ax + dx / 2, ay);
86
+ if (abs(dy) == 2 && dx == 0) return !isWall(ax, ay + dy / 2);
87
+ if (abs(dx) == 1 && abs(dy) == 1) return !isWall(ax + dx, ay) || !isWall(ax, ay + dy);
88
+ return true;
89
+ }
90
+
91
+ vector<int> bfsFromCells(const vector<int>& src) {
92
+ vector<int> d(CELLS, -1);
93
+ queue<int> q;
94
+ for (int c : src) { d[c] = 0; q.push(c); }
95
+ while (!q.empty()) {
96
+ int c = q.front(); q.pop();
97
+ int x = c % S, y = c / S;
98
+ for (int k = 0; k < 4; k++) {
99
+ int nx = x + DX[k], ny = y + DY[k];
100
+ if (isWall(nx, ny)) continue;
101
+ int nc = cid(nx, ny);
102
+ if (d[nc] == -1) { d[nc] = d[c] + 1; q.push(nc); }
103
+ }
104
+ }
105
+ return d;
106
+ }
107
+
108
+ void precompute() {
109
+ N = g.teams; S = g.size; CELLS = S * S;
110
+ wall.assign(CELLS, 0);
111
+ for (int y = 0; y < S; y++) for (int x = 0; x < S; x++) wall[cid(x, y)] = (g.map[y][x] == '#');
112
+ centerx = centery = S / 2;
113
+ teamBaseDist.assign(N, {});
114
+ spawnOrder.assign(N, {});
115
+ for (int t = 0; t < N; t++) {
116
+ vector<int> cells;
117
+ auto bc = g.bases[t];
118
+ for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) cells.push_back(cid(bc.first + dx, bc.second + dy));
119
+ teamBaseDist[t] = bfsFromCells(cells);
120
+ vector<int> so = cells;
121
+ sort(so.begin(), so.end(), [&](int a, int b) {
122
+ int ax = a % S, ay = a / S, bx = b % S, by = b / S;
123
+ int da = abs(ax - centerx) + abs(ay - centery), db = abs(bx - centerx) + abs(by - centery);
124
+ if (da != db) return da < db;
125
+ int ta = abs(ax - bc.first) + 2 * abs(ay - bc.second);
126
+ int tb = abs(bx - bc.first) + 2 * abs(by - bc.second);
127
+ return ta < tb;
128
+ });
129
+ spawnOrder[t] = so;
130
+ }
131
+ }
132
+
133
+ struct My {
134
+ Unit u;
135
+ bool alive = false, immune = false;
136
+ int px = -1, py = -1;
137
+ int role = 3;
138
+ int tx = -1, ty = -1;
139
+ int move = 4, act = 0, actArg = -1;
140
+ int fid = -1; // role==1 时的目标旗
141
+ string note;
142
+ };
143
+
144
+ vector<double> costField(int tx, int ty, const vector<double>& w) {
145
+ const double INF = 1e18;
146
+ vector<double> d(CELLS, INF);
147
+ priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> pq;
148
+ int t = cid(tx, ty);
149
+ d[t] = 0; pq.push({0, t});
150
+ while (!pq.empty()) {
151
+ auto [dc, c] = pq.top(); pq.pop();
152
+ if (dc > d[c] + 1e-9) continue;
153
+ int x = c % S, y = c / S;
154
+ for (int k = 0; k < 4; k++) {
155
+ int nx = x + DX[k], ny = y + DY[k];
156
+ if (isWall(nx, ny)) continue;
157
+ int nc = cid(nx, ny);
158
+ double nd = dc + w[nc];
159
+ if (nd < d[nc] - 1e-9) { d[nc] = nd; pq.push({nd, nc}); }
160
+ }
161
+ }
162
+ return d;
163
+ }
164
+
165
+ // 敌方载旗者沿最短路回家的路径格(含当前格)
166
+ vector<int> carrierPath(const Unit& e) {
167
+ vector<int> path;
168
+ int x = e.x, y = e.y;
169
+ path.push_back(cid(x, y));
170
+ for (int i = 0; i < 200; i++) {
171
+ int bd = teamBaseDist[e.team][cid(x, y)];
172
+ if (bd <= 0) break;
173
+ int bx = -1, by = -1;
174
+ for (int d = 0; d < 4; d++) {
175
+ int nx = x + DX[d], ny = y + DY[d];
176
+ if (isWall(nx, ny)) continue;
177
+ int nd = teamBaseDist[e.team][cid(nx, ny)];
178
+ if (nd >= 0 && nd < bd) { bd = nd; bx = nx; by = ny; }
179
+ }
180
+ if (bx < 0) break;
181
+ x = bx; y = by;
182
+ path.push_back(cid(x, y));
183
+ }
184
+ return path;
185
+ }
186
+
187
+ string solve() {
188
+ vector<My> mine(3);
189
+ vector<int> occupied(CELLS, -1);
190
+ for (auto& u : g.units) if (u.x >= 0) occupied[cid(u.x, u.y)] = u.id;
191
+
192
+ // 预测本回合开头的重生(按 id 顺序模拟全部队伍)
193
+ vector<pair<int, int>> respawnPos(g.units.size(), {-1, -1});
194
+ {
195
+ vector<int> occ = occupied;
196
+ for (auto& u : g.units) {
197
+ if (u.x < 0 && u.respawn_at == g.turn) {
198
+ for (int c : spawnOrder[u.team]) {
199
+ if (occ[c] < 0) { occ[c] = u.id; respawnPos[u.id] = {c % S, c / S}; break; }
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ vector<const Unit*> enemies;
206
+ for (auto& u : g.units) if (u.team != g.me && u.x >= 0) enemies.push_back(&u);
207
+
208
+ for (int k = 0; k < 3; k++) {
209
+ int uid = 3 * g.me + k;
210
+ const Unit& u = g.units[uid];
211
+ mine[k].u = u;
212
+ if (u.x >= 0) { mine[k].alive = true; mine[k].px = u.x; mine[k].py = u.y; }
213
+ else if (u.respawn_at == g.turn && respawnPos[uid].first >= 0) {
214
+ mine[k].alive = true; mine[k].immune = true;
215
+ mine[k].px = respawnPos[uid].first; mine[k].py = respawnPos[uid].second;
216
+ }
217
+ // 卡住检测:上回合预测的位置与实际不符
218
+ if (mine[k].alive && prevPred[k][0] >= 0 && (prevPred[k][0] != mine[k].px || prevPred[k][1] != mine[k].py)) {
219
+ stuck[k]++;
220
+ banCell[k] = cid(prevPred[k][0], prevPred[k][1]); // 没进成的格
221
+ } else {
222
+ stuck[k] = 0; banCell[k] = -1;
223
+ }
224
+ }
225
+
226
+ // 威胁格
227
+ vector<int> threatNow(CELLS, 0), threatNext(CELLS, 0);
228
+ for (auto e : enemies) {
229
+ if (e->flag < 0) {
230
+ for (int dy = -2; dy <= 2; dy++) for (int dx = -2; dx <= 2; dx++) {
231
+ int nx = e->x + dx, ny = e->y + dy;
232
+ if (isWall(nx, ny)) continue;
233
+ if (canAtk(e->x, e->y, nx, ny)) threatNow[cid(nx, ny)]++;
234
+ }
235
+ }
236
+ for (int dy = -3; dy <= 3; dy++) for (int dx = -3; dx <= 3; dx++) {
237
+ if (abs(dx) + abs(dy) > 3) continue;
238
+ int nx = e->x + dx, ny = e->y + dy;
239
+ if (isWall(nx, ny)) continue;
240
+ threatNext[cid(nx, ny)]++;
241
+ }
242
+ }
243
+
244
+ vector<vector<int>> distU(3);
245
+ for (int k = 0; k < 3; k++)
246
+ if (mine[k].alive) distU[k] = bfsFromCells({cid(mine[k].px, mine[k].py)});
247
+
248
+ // 可取旗子
249
+ vector<int> availFlags;
250
+ for (auto& f : g.flags) {
251
+ if (f.status == "home" && f.x >= 0) availFlags.push_back(f.id);
252
+ else if (f.status == "dropped" && f.x >= 0 && (f.return_at < 0 || f.return_at > g.turn)) availFlags.push_back(f.id);
253
+ }
254
+ vector<vector<int>> distF(g.flags.size());
255
+ for (int fid : availFlags) distF[fid] = bfsFromCells({cid(g.flags[fid].x, g.flags[fid].y)});
256
+ auto enemyMinDist = [&](const vector<int>& df) {
257
+ int best = 1 << 29;
258
+ for (auto e : enemies) {
259
+ int d = df[cid(e->x, e->y)];
260
+ if (d >= 0) best = min(best, d);
261
+ }
262
+ return best;
263
+ };
264
+
265
+ vector<const Unit*> eCarriers;
266
+ for (auto e : enemies) if (e->flag >= 0) eCarriers.push_back(e);
267
+ int myCarrier = -1;
268
+ for (int k = 0; k < 3; k++) if (mine[k].alive && mine[k].u.flag >= 0) myCarrier = k;
269
+
270
+ // 拥挤程度:人多时热旗封锁与避险才值得
271
+ double crowd = N <= 2 ? 0.25 : (N == 3 ? 0.5 : (N <= 5 ? 0.7 : 1.0));
272
+ // 旗子热度:周围敌人多 = 捡起来就死;不如坐在旗上封锁并战斗
273
+ vector<int> hotFlag(g.flags.size(), 0);
274
+ for (int fid : availFlags) {
275
+ int fc = cid(g.flags[fid].x, g.flags[fid].y);
276
+ int near = 0;
277
+ for (auto e : enemies) if (abs(e->x - g.flags[fid].x) + abs(e->y - g.flags[fid].y) <= 2) near++;
278
+ hotFlag[fid] = (N >= 3 && (threatNext[fc] >= 2 || near >= 2)) ? 1 : 0;
279
+ }
280
+
281
+ // 敌方载旗者路径与拦截可行性
282
+ vector<vector<int>> ePath(eCarriers.size());
283
+ for (int i = 0; i < (int)eCarriers.size(); i++) ePath[i] = carrierPath(*eCarriers[i]);
284
+ auto interceptEta = [&](int k, int i) -> int {
285
+ // min over path cells: 我到该格的回合数 - 载旗者到该格的回合数;<=1 表示能就位射击
286
+ int best = 1 << 29;
287
+ for (int j = 0; j < (int)ePath[i].size(); j++) {
288
+ int d = distU[k][ePath[i][j]];
289
+ if (d < 0) continue;
290
+ best = min(best, d - j);
291
+ }
292
+ return best;
293
+ };
294
+
295
+ // ---------- 任务分配 ----------
296
+ int F = availFlags.size(), C = eCarriers.size();
297
+ int T_ESC = F + C, T_STAGE = F + C + 1, NT = F + C + 2;
298
+
299
+ // 载旗者状态
300
+ int carrierBd = 0, carrierTh = 0, carrierChasers = 0;
301
+ if (myCarrier >= 0) {
302
+ carrierBd = teamBaseDist[g.me][cid(mine[myCarrier].px, mine[myCarrier].py)];
303
+ carrierTh = threatNext[cid(mine[myCarrier].px, mine[myCarrier].py)];
304
+ for (auto e : enemies)
305
+ if (e->flag < 0 && abs(e->x - mine[myCarrier].px) + abs(e->y - mine[myCarrier].py) <= 3) carrierChasers++;
306
+ }
307
+ int escCap = (myCarrier >= 0 && carrierBd >= 4 && carrierTh > 0) ? 2 : 1;
308
+
309
+ auto taskScore = [&](int k, int t) -> double {
310
+ if (!mine[k].alive) return -1e17;
311
+ if (t < F) {
312
+ int fid = availFlags[t];
313
+ int fc = cid(g.flags[fid].x, g.flags[fid].y);
314
+ int d = distU[k][fc];
315
+ if (d < 0) return -1e17;
316
+ double v = 100.0 - 2.0 * d - 1.5 * teamBaseDist[g.me][fc];
317
+ int ed = enemyMinDist(distF[fid]);
318
+ if (ed <= d - 2) v -= 35; // 明显抢不过
319
+ else if (ed <= d + 1) v += 10; // 均势争夺,值得去(可转战斗)
320
+ else v += 15; // 稳拿
321
+ // 危险区取旗:旗格周边敌人多 => 拿到也走不掉(人多才在意)
322
+ v -= crowd * (10.0 * threatNext[fc] + 20.0 * threatNow[fc]);
323
+ // 残血角色避免争夺
324
+ if (mine[k].u.hp <= g.damage && ed <= d + 1) v -= 45 * crowd;
325
+ else if (mine[k].u.hp <= 2 * g.damage && ed <= d + 1) v -= 15 * crowd;
326
+ if (g.flags[fid].status == "dropped") {
327
+ int left = g.flags[fid].return_at - g.turn;
328
+ if (left >= 0 && left < d + 1) v -= 40;
329
+ }
330
+ return v;
331
+ } else if (t < F + C) {
332
+ int i = t - F;
333
+ auto e = eCarriers[i];
334
+ int eta = interceptEta(k, i);
335
+ int tb = teamBaseDist[e->team][cid(e->x, e->y)];
336
+ if (eta > 1 && eta > tb) return -1e17; // 完全追不上
337
+ double progress = 1.0 - tb / 20.0;
338
+ double v = 85.0 + 70.0 * progress - 6.0 * max(0, eta);
339
+ if (eta > 1) v -= 3.0 * eta; // 追不上也跟在后面等捡漏
340
+ return v;
341
+ } else if (t == T_ESC) {
342
+ if (myCarrier < 0) return -1e17;
343
+ int d = distU[k][cid(mine[myCarrier].px, mine[myCarrier].py)];
344
+ if (d < 0) return -1e17;
345
+ int th = threatNext[cid(mine[myCarrier].px, mine[myCarrier].py)];
346
+ int bd = teamBaseDist[g.me][cid(mine[myCarrier].px, mine[myCarrier].py)];
347
+ // 载旗者被追时护送最优先(同速追击跑不掉,只能靠护送击退)
348
+ return 20.0 + 45.0 * min(carrierChasers, 2) + 20.0 * min(th, 2) + 0.5 * bd - 2.0 * d;
349
+ } else {
350
+ return 25.0 - 1.0 * distU[k][cid(centerx, centery)];
351
+ }
352
+ };
353
+
354
+ vector<int> bestAsg(3, T_STAGE);
355
+ double bestScore = -1e17;
356
+ vector<int> asg(3);
357
+ function<void(int, double)> dfs = [&](int k, double acc) {
358
+ if (k == 3) {
359
+ if (acc > bestScore) { bestScore = acc; bestAsg = asg; }
360
+ return;
361
+ }
362
+ if (!mine[k].alive) { asg[k] = T_STAGE; dfs(k + 1, acc); return; }
363
+ if (k == myCarrier) { asg[k] = -1; dfs(k + 1, acc); return; }
364
+ for (int t = 0; t < NT; t++) {
365
+ vector<int> cntInt(C, 0);
366
+ int cntEsc = 0;
367
+ for (int j = 0; j < k; j++) {
368
+ if (asg[j] >= F && asg[j] < F + C) cntInt[asg[j] - F]++;
369
+ else if (asg[j] == T_ESC) cntEsc++;
370
+ }
371
+ double s = taskScore(k, t);
372
+ if (t < F) {
373
+ int have = 0;
374
+ for (int j = 0; j < k; j++) if (asg[j] == t) have++;
375
+ int fid = availFlags[t];
376
+ int d = distU[k][cid(g.flags[fid].x, g.flags[fid].y)];
377
+ int ed = enemyMinDist(distF[fid]);
378
+ int cap = (ed <= d + 1) ? 2 : 1; // 有争夺时允许两人去
379
+ if (have >= cap) continue;
380
+ if (have == 1) s -= 20; // 第二人支援打折
381
+ } else if (t < F + C) {
382
+ if (cntInt[t - F] >= 2) continue;
383
+ if (cntInt[t - F] == 1) s += 25; // 双人拦截加成
384
+ } else if (t == T_ESC) {
385
+ if (cntEsc >= escCap) continue;
386
+ if (cntEsc == 1) s -= 10;
387
+ }
388
+ if (s < -1e16) continue;
389
+ asg[k] = t;
390
+ dfs(k + 1, acc + s);
391
+ }
392
+ };
393
+ dfs(0, 0);
394
+
395
+ // 占位目标:分散到不同的空旗点
396
+ vector<int> spotTaken(CELLS, 0), intTaken(CELLS, 0);
397
+ for (int k = 0; k < 3; k++) {
398
+ if (!mine[k].alive) continue;
399
+ if (k == myCarrier) {
400
+ mine[k].role = 0;
401
+ mine[k].tx = g.bases[g.me].first; mine[k].ty = g.bases[g.me].second;
402
+ mine[k].note = "回家";
403
+ continue;
404
+ }
405
+ int t = bestAsg[k];
406
+ if (t < F) {
407
+ mine[k].role = 1;
408
+ mine[k].fid = availFlags[t];
409
+ mine[k].tx = g.flags[availFlags[t]].x; mine[k].ty = g.flags[availFlags[t]].y;
410
+ mine[k].note = "取旗";
411
+ } else if (t < F + C) {
412
+ mine[k].role = 2;
413
+ auto e = eCarriers[t - F];
414
+ auto& path = ePath[t - F];
415
+ // 目标:路径上我能最早就位的格;多名拦截手错开站位
416
+ int bestc = cid(e->x, e->y), bestv = 1 << 29;
417
+ for (int j = 0; j < (int)path.size(); j++) {
418
+ if (intTaken[path[j]]) continue;
419
+ int d = distU[k][path[j]];
420
+ if (d < 0) continue;
421
+ if (d - j < bestv) { bestv = d - j; bestc = path[j]; }
422
+ }
423
+ intTaken[bestc] = 1;
424
+ mine[k].tx = bestc % S; mine[k].ty = bestc / S;
425
+ mine[k].note = "拦截";
426
+ } else if (t == T_ESC) {
427
+ mine[k].role = 2;
428
+ // 护送:卡在载旗者与最近追兵之间贴身阻挡,否则跟随
429
+ int bestd = 6, ex = -1, ey = -1;
430
+ for (auto e : enemies) {
431
+ if (e->flag >= 0) continue;
432
+ int d = abs(e->x - mine[myCarrier].px) + abs(e->y - mine[myCarrier].py);
433
+ if (d < bestd) { bestd = d; ex = e->x; ey = e->y; }
434
+ }
435
+ if (ex >= 0) {
436
+ int cx0 = mine[myCarrier].px, cy0 = mine[myCarrier].py;
437
+ int bx = cx0, by = cy0, bd2 = 1 << 29;
438
+ for (int d = 0; d < 5; d++) {
439
+ int nx = cx0 + DX[d], ny = cy0 + DY[d];
440
+ if (d < 4 && isWall(nx, ny)) continue;
441
+ int dd = abs(nx - ex) + abs(ny - ey);
442
+ if (dd < bd2) { bd2 = dd; bx = nx; by = ny; }
443
+ }
444
+ mine[k].tx = bx; mine[k].ty = by; mine[k].note = "卡位";
445
+ } else { mine[k].tx = mine[myCarrier].px; mine[k].ty = mine[myCarrier].py; mine[k].note = "护送"; }
446
+ } else {
447
+ mine[k].role = 3;
448
+ double best = 1e18; int sx = centerx, sy = centery;
449
+ for (auto& sp : g.spots) {
450
+ int c = cid(sp.first, sp.second);
451
+ if (spotTaken[c]) continue;
452
+ bool hasFlag = false;
453
+ for (auto& f : g.flags) if (f.status == "home" && f.x == sp.first && f.y == sp.second) hasFlag = true;
454
+ if (hasFlag) continue;
455
+ int d = distU[k][c];
456
+ if (d < 0) continue;
457
+ double cost = d + 0.8 * teamBaseDist[g.me][c] + 5.0 * threatNext[c];
458
+ if (cost < best) { best = cost; sx = sp.first; sy = sp.second; }
459
+ }
460
+ spotTaken[cid(sx, sy)] = 1;
461
+ mine[k].tx = sx; mine[k].ty = sy;
462
+ mine[k].note = "占位";
463
+ }
464
+ }
465
+
466
+ // ---------- 移动 ----------
467
+ vector<int> order = {0, 1, 2};
468
+ sort(order.begin(), order.end(), [&](int a, int b) {
469
+ if (mine[a].alive != mine[b].alive) return mine[a].alive > mine[b].alive;
470
+ return mine[a].role < mine[b].role;
471
+ });
472
+ vector<int> reserved(CELLS, 0), stays(CELLS, 0);
473
+ for (int k = 0; k < 3; k++) if (mine[k].alive) stays[cid(mine[k].px, mine[k].py)] = 1;
474
+
475
+ for (int oi = 0; oi < 3; oi++) {
476
+ int k = order[oi];
477
+ if (!mine[k].alive) continue;
478
+ vector<double> w(CELLS, 1.0);
479
+ // 血量越低越怕死
480
+ double frag = mine[k].u.hp <= g.damage ? 3.0 : (mine[k].u.hp <= 2 * g.damage ? 1.6 : 1.0);
481
+ for (int c = 0; c < CELLS; c++) {
482
+ if (occupied[c] >= 0 && g.units[occupied[c]].team != g.me) w[c] += 15;
483
+ if (mine[k].role == 0) w[c] += ((8.0 + 17.0 * crowd) * threatNow[c] + (1.0 + 2.0 * crowd) * threatNext[c]) * frag;
484
+ else if (mine[k].role == 1) w[c] += (3.0 * threatNow[c] + 0.5 * threatNext[c]) * frag * crowd;
485
+ else if (mine[k].role == 3) w[c] += 2.0 * threatNow[c] * frag * crowd;
486
+ }
487
+ int tc = cid(mine[k].tx, mine[k].ty);
488
+ bool enemyOnTarget = occupied[tc] >= 0 && g.units[occupied[tc]].team != g.me;
489
+ // 坐在热旗上封锁:不动,靠战斗清场
490
+ bool hotSit = mine[k].role == 1 && mine[k].fid >= 0 && hotFlag[mine[k].fid] &&
491
+ mine[k].px == mine[k].tx && mine[k].py == mine[k].ty;
492
+ bool hotAdj = mine[k].role == 1 && mine[k].fid >= 0 && hotFlag[mine[k].fid] && enemyOnTarget &&
493
+ abs(mine[k].px - mine[k].tx) + abs(mine[k].py - mine[k].ty) <= 1;
494
+ if (!enemyOnTarget) w[tc] = 1.0;
495
+ auto cf = costField(mine[k].tx, mine[k].ty, w);
496
+ vector<pair<double, int>> cand;
497
+ for (int d = 0; d < 5; d++) {
498
+ int nx = mine[k].px + DX[d], ny = mine[k].py + DY[d];
499
+ if (d < 4 && isWall(nx, ny)) continue;
500
+ int nc = cid(nx, ny);
501
+ double sc = cf[nc] + (d == 4 ? 0.4 : 0.0);
502
+ if (mine[k].role == 0) sc += 3.0 * threatNow[nc];
503
+ if (nc == banCell[k]) sc += 6.0; // 上回合没进成的格,尽量绕行
504
+ if (hotSit || hotAdj) sc += (d == 4 ? -100.0 : 100.0); // 强制驻守
505
+ cand.push_back({sc, d});
506
+ }
507
+ sort(cand.begin(), cand.end());
508
+ int chosen = 4;
509
+ for (auto& [sc, d] : cand) {
510
+ int nx = mine[k].px + DX[d], ny = mine[k].py + DY[d];
511
+ int nc = cid(nx, ny);
512
+ if (d != 4) {
513
+ if (reserved[nc]) continue;
514
+ int occ = occupied[nc];
515
+ if (occ >= 0 && g.units[occ].team == g.me && stays[nc]) continue;
516
+ if (nc == banCell[k] && stuck[k] >= 2) continue; // 死锁时强制绕行
517
+ }
518
+ chosen = d;
519
+ break;
520
+ }
521
+ int nx = mine[k].px + DX[chosen], ny = mine[k].py + DY[chosen];
522
+ mine[k].move = chosen;
523
+ if (chosen == 4 || isWall(nx, ny)) {
524
+ reserved[cid(mine[k].px, mine[k].py)] = 1; // 不动也占位,防止队友撞进来
525
+ } else {
526
+ stays[cid(mine[k].px, mine[k].py)] = 0;
527
+ mine[k].px = nx; mine[k].py = ny;
528
+ reserved[cid(nx, ny)] = 1;
529
+ stays[cid(nx, ny)] = 1;
530
+ }
531
+ }
532
+
533
+ // ---------- 动作 ----------
534
+ // 取旗被争夺时:若敌人在旗格上或卡住我,优先攻击而非空按 P
535
+ auto flagContender = [&](int k) -> int {
536
+ if (mine[k].role != 1) return -1;
537
+ int fc = cid(mine[k].tx, mine[k].ty);
538
+ int occ = occupied[fc];
539
+ if (occ >= 0 && g.units[occ].team != g.me) return occ; // 敌人站在旗上
540
+ if (stuck[k] >= 1) {
541
+ // 找与我目标旗相邻/阻碍我的敌人
542
+ for (auto e : enemies) {
543
+ int d = abs(e->x - mine[k].tx) + abs(e->y - mine[k].ty);
544
+ if (d <= 1) return e->id;
545
+ }
546
+ }
547
+ return -1;
548
+ };
549
+ for (int k = 0; k < 3; k++) {
550
+ if (!mine[k].alive || mine[k].u.flag >= 0) continue;
551
+ int cont = flagContender(k);
552
+ int onFid = -1;
553
+ for (auto& f : g.flags)
554
+ if ((f.status == "home" || f.status == "dropped") && f.x == mine[k].px && f.y == mine[k].py) onFid = f.id;
555
+ if (onFid >= 0) {
556
+ // 热旗封锁:敌人能立刻打我时,坐在旗上战斗而不是白捡白死
557
+ int fc = cid(mine[k].px, mine[k].py);
558
+ int enemyNear = 0, myNear = 0;
559
+ for (auto e : enemies) if (abs(e->x - mine[k].px) + abs(e->y - mine[k].py) <= 2) enemyNear++;
560
+ for (int j = 0; j < 3; j++) if (j != k && mine[j].alive && abs(mine[j].px - mine[k].px) + abs(mine[j].py - mine[k].py) <= 3) myNear++;
561
+ int bd = teamBaseDist[g.me][fc];
562
+ // 同速追击下被锁定必死:有追兵且离家远且无支援 => 坐了别捡
563
+ bool safe = enemyNear == 0 || myNear >= enemyNear || bd <= 4 ||
564
+ (enemyNear <= 1 && threatNow[fc] == 0 && bd <= 7);
565
+ if (safe) { mine[k].act = 1; mine[k].note = "拾旗"; continue; }
566
+ mine[k].note = "封旗"; // 坐在旗上不占,转入战斗
567
+ }
568
+ if (cont >= 0 && !mine[k].immune) { mine[k].act = 3; mine[k].actArg = cont; mine[k].note = "争旗"; }
569
+ }
570
+
571
+ // 攻击目标预测
572
+ vector<pair<int, int>> ePred(g.units.size(), {-1, -1});
573
+ for (auto& u : g.units) {
574
+ if (u.team == g.me || u.x < 0) continue;
575
+ int ex = u.x, ey = u.y;
576
+ if (u.flag >= 0) {
577
+ int bd = teamBaseDist[u.team][cid(ex, ey)], bx = ex, by = ey;
578
+ for (int d = 0; d < 4; d++) {
579
+ int nx = ex + DX[d], ny = ey + DY[d];
580
+ if (isWall(nx, ny)) continue;
581
+ int nd = teamBaseDist[u.team][cid(nx, ny)];
582
+ if (nd >= 0 && nd < bd) { bd = nd; bx = nx; by = ny; }
583
+ }
584
+ ex = bx; ey = by;
585
+ }
586
+ ePred[u.id] = {ex, ey};
587
+ }
588
+ vector<int> shooters;
589
+ for (int k = 0; k < 3; k++)
590
+ if (mine[k].alive && mine[k].act == 0 && mine[k].u.flag < 0 && !mine[k].immune) shooters.push_back(k);
591
+ struct Tgt { int uid; double val; int need; vector<int> by; };
592
+ vector<Tgt> tgts;
593
+ for (auto e : enemies) {
594
+ if (e->x < 0) continue;
595
+ auto pp = ePred[e->id];
596
+ vector<int> by;
597
+ for (int k : shooters) if (canAtk(mine[k].px, mine[k].py, pp.first, pp.second)) by.push_back(k);
598
+ // 已被“争旗”占用的射手也算上
599
+ for (int k = 0; k < 3; k++)
600
+ if (mine[k].act == 3 && mine[k].actArg == e->id &&
601
+ find(by.begin(), by.end(), k) == by.end() &&
602
+ find(shooters.begin(), shooters.end(), k) == shooters.end()) {
603
+ if (canAtk(mine[k].px, mine[k].py, pp.first, pp.second)) by.push_back(k);
604
+ }
605
+ if (by.empty()) continue;
606
+ double val = 1.0 * (g.hp - e->hp) + 2.0 * max(0, 3 - (abs(pp.first - mine[by[0]].px) + abs(pp.second - mine[by[0]].py)));
607
+ if (e->flag >= 0) {
608
+ int tb = teamBaseDist[e->team][cid(e->x, e->y)];
609
+ val += 150 + 10.0 * max(0, 20 - tb);
610
+ }
611
+ // 靠近我方目标旗的争夺者
612
+ for (int k = 0; k < 3; k++)
613
+ if (mine[k].role == 1 && abs(e->x - mine[k].tx) + abs(e->y - mine[k].ty) <= 2) { val += 80; break; }
614
+ // 站在我基地里的敌人(会卡住重生)
615
+ if (teamBaseDist[g.me][cid(e->x, e->y)] <= 1) val += 60;
616
+ int need = (e->hp + g.damage - 1) / g.damage;
617
+ if ((int)by.size() >= need) val += 300;
618
+ tgts.push_back({e->id, val, need, by});
619
+ }
620
+ sort(tgts.begin(), tgts.end(), [](const Tgt& a, const Tgt& b) { return a.val > b.val; });
621
+ vector<int> used(3, 0);
622
+ for (int k = 0; k < 3; k++) if (mine[k].act == 3) used[k] = 1;
623
+ for (auto& t : tgts) {
624
+ int assigned = 0;
625
+ for (int k : t.by) if (mine[k].act == 3 && mine[k].actArg == t.uid) assigned++;
626
+ for (int k : t.by) {
627
+ if (used[k]) continue;
628
+ mine[k].act = 3; mine[k].actArg = t.uid;
629
+ used[k] = 1;
630
+ if (++assigned >= t.need) break;
631
+ }
632
+ }
633
+
634
+ // 记录预测位置供下回合卡住检测
635
+ for (int k = 0; k < 3; k++) {
636
+ if (mine[k].alive) { prevPred[k][0] = mine[k].px; prevPred[k][1] = mine[k].py; }
637
+ else { prevPred[k][0] = prevPred[k][1] = -1; stuck[k] = 0; banCell[k] = -1; }
638
+ }
639
+
640
+ // ---------- 输出 ----------
641
+ string out = to_string(g.turn);
642
+ vector<string> notes(3);
643
+ for (int k = 0; k < 3; k++) {
644
+ char mv = mine[k].alive ? MVC[mine[k].move] : 'S';
645
+ string act = "-";
646
+ if (mine[k].alive) {
647
+ if (mine[k].act == 1) act = "P";
648
+ else if (mine[k].act == 2) act = "X";
649
+ else if (mine[k].act == 3) act = to_string(mine[k].actArg);
650
+ }
651
+ out += " "; out += mv; out += " "; out += act;
652
+ notes[k] = mine[k].note;
653
+ }
654
+ out += " # " + notes[0] + ";" + notes[1] + ";" + notes[2];
655
+ return out;
656
+ }
657
+ };
658
+
659
+ int main() {
660
+ ios::sync_with_stdio(false);
661
+ Solver s;
662
+ bool first = true;
663
+ while (read_turn(s.g)) {
664
+ if (first) { s.precompute(); first = false; }
665
+ cout << s.solve() << endl;
666
+ }
667
+ }