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,645 @@
1
+ // 夺旗 bot:全图 BFS 距离 + 战略任务分配(抢旗/拦截/护送/蹲旗点)+ 三人联合走位搜索(集火、危险评估)。
2
+ #include <bits/stdc++.h>
3
+ using namespace std;
4
+
5
+ struct Unit { int id, team, x, y, hp, flag, respawn_at; }; // 阵亡时 x = y = -1
6
+ struct Flag { int id; string status; int x, y, holder, return_at; };
7
+ struct Event { string type; vector<int> args; };
8
+
9
+ struct Game {
10
+ int teams = 0, me = 0, size = 0, turns = 0, hp = 0, damage = 0, respawn = 0, flag_return = 0, flag_cooldown = 0;
11
+ vector<string> map;
12
+ vector<pair<int, int>> bases;
13
+ vector<pair<int, int>> spots;
14
+ int turn = 0;
15
+ vector<int> score;
16
+ vector<Unit> units;
17
+ vector<Flag> flags;
18
+ vector<Event> events;
19
+ };
20
+
21
+ bool read_turn(Game& g) {
22
+ string w;
23
+ while (cin >> w) {
24
+ if (w == "INIT") {
25
+ cin >> g.teams >> g.me >> g.size >> g.turns >> g.hp >> g.damage >> g.respawn >> g.flag_return >> g.flag_cooldown;
26
+ } else if (w == "MAP") {
27
+ g.map.assign(g.size, "");
28
+ for (auto& row : g.map) cin >> row;
29
+ } else if (w == "BASES") {
30
+ int k; cin >> k; g.bases.resize(k);
31
+ for (auto& b : g.bases) cin >> b.first >> b.second;
32
+ } else if (w == "SPOTS") {
33
+ int k; cin >> k; g.spots.resize(k);
34
+ for (auto& s : g.spots) cin >> s.first >> s.second;
35
+ } else if (w == "TURN") {
36
+ cin >> g.turn;
37
+ } else if (w == "SCORE") {
38
+ g.score.resize(g.teams);
39
+ for (auto& s : g.score) cin >> s;
40
+ } else if (w == "UNITS") {
41
+ int k; cin >> k; g.units.resize(k);
42
+ for (auto& u : g.units) { string tag; cin >> tag >> u.id >> u.team >> u.x >> u.y >> u.hp >> u.flag >> u.respawn_at; }
43
+ } else if (w == "FLAGS") {
44
+ int k; cin >> k; g.flags.resize(k);
45
+ for (auto& f : g.flags) { string tag; cin >> tag >> f.id >> f.status >> f.x >> f.y >> f.holder >> f.return_at; }
46
+ } else if (w == "EVENTS") {
47
+ int k; cin >> k; g.events.assign(k, {});
48
+ string line; getline(cin, line);
49
+ for (auto& e : g.events) {
50
+ getline(cin, line);
51
+ istringstream in(line);
52
+ string tag; in >> tag >> e.type;
53
+ for (int v; in >> v;) e.args.push_back(v);
54
+ }
55
+ } else if (w == "END") {
56
+ return true;
57
+ }
58
+ }
59
+ return false;
60
+ }
61
+
62
+ // ---------------------------------------------------------------------------
63
+ static int S, NC, NT, ME, TURNS = 400;
64
+ static vector<char> W;
65
+ static vector<uint16_t> DD;
66
+ static vector<array<int, 5>> NB;
67
+ static vector<vector<int>> baseCells, distBase, spawnOrd;
68
+ static vector<vector<char>> inBase;
69
+ static vector<int> spots;
70
+ static vector<char> isSpot;
71
+ static int CEN;
72
+ static const int DX[5] = {0, 0, -1, 1, 0}, DY[5] = {-1, 1, 0, 0, 0};
73
+ static const char MC[5] = {'U', 'D', 'L', 'R', 'S'};
74
+ static const int INF = 65535;
75
+ static bool JOINT = true; static double PA = 0.6;
76
+ static double CARRIER_PROG = 120.0, CARRIER_DEATH = 600.0, CARRIER_HIT = 60.0, KILL_BASE = 260, KILL_CARRIER = 500, UNIT_DEATH = 170, HIT_COST = 25;
77
+
78
+ static inline int D(int a, int b) { return DD[(size_t)a * NC + b]; }
79
+
80
+ static bool canAtk(int a, int b) {
81
+ int ax = a % S, ay = a / S, bx = b % S, by = b / S;
82
+ int dx = bx - ax, dy = by - ay;
83
+ if (abs(dx) + abs(dy) > 2) return false;
84
+ if (abs(dx) == 2 && dy == 0) return !W[ay * S + ax + dx / 2];
85
+ if (abs(dy) == 2 && dx == 0) return !W[(ay + dy / 2) * S + ax];
86
+ if (abs(dx) == 1 && abs(dy) == 1) return !W[ay * S + ax + dx] || !W[(ay + dy) * S + ax];
87
+ return true;
88
+ }
89
+
90
+ static void init(const Game& g) {
91
+ S = g.size; NC = S * S; NT = g.teams; ME = g.me; TURNS = g.turns;
92
+ if (NT == 2) { KILL_BASE = 380; KILL_CARRIER = 900; UNIT_DEATH = 170; }
93
+ else if (NT <= 2) { KILL_BASE = 260; KILL_CARRIER = 500; UNIT_DEATH = 170; HIT_COST = 40; }
94
+ else { KILL_BASE = 140; KILL_CARRIER = 450; UNIT_DEATH = 240; HIT_COST = 75; }
95
+ W.assign(NC, 0);
96
+ for (int y = 0; y < S; y++)
97
+ for (int x = 0; x < S; x++) W[y * S + x] = g.map[y][x] == '#';
98
+ NB.resize(NC);
99
+ for (int y = 0; y < S; y++)
100
+ for (int x = 0; x < S; x++) {
101
+ int c = y * S + x;
102
+ for (int k = 0; k < 5; k++) {
103
+ int nx = x + DX[k], ny = y + DY[k];
104
+ if (nx < 0 || ny < 0 || nx >= S || ny >= S || W[ny * S + nx]) NB[c][k] = c;
105
+ else NB[c][k] = ny * S + nx;
106
+ }
107
+ }
108
+ DD.assign((size_t)NC * NC, INF);
109
+ vector<int> q(NC);
110
+ for (int s = 0; s < NC; s++) {
111
+ if (W[s]) continue;
112
+ uint16_t* d = &DD[(size_t)s * NC];
113
+ d[s] = 0; int h = 0, tl = 0; q[tl++] = s;
114
+ while (h < tl) {
115
+ int c = q[h++];
116
+ for (int k = 0; k < 4; k++) {
117
+ int n = NB[c][k];
118
+ if (n != c && d[n] == INF) { d[n] = d[c] + 1; q[tl++] = n; }
119
+ }
120
+ }
121
+ }
122
+ int c0 = S / 2;
123
+ CEN = c0 * S + c0;
124
+ baseCells.assign(NT, {}); inBase.assign(NT, vector<char>(NC, 0)); distBase.assign(NT, vector<int>(NC, INF));
125
+ spawnOrd.assign(NT, {});
126
+ for (int t = 0; t < NT; t++) {
127
+ int bx = g.bases[t].first, by = g.bases[t].second;
128
+ for (int dy = -1; dy <= 1; dy++)
129
+ for (int dx = -1; dx <= 1; dx++) {
130
+ int c = (by + dy) * S + bx + dx;
131
+ baseCells[t].push_back(c); inBase[t][c] = 1;
132
+ }
133
+ for (int c = 0; c < NC; c++) {
134
+ int m = INF;
135
+ for (int b : baseCells[t]) m = min(m, D(b, c));
136
+ distBase[t][c] = m;
137
+ }
138
+ vector<int> ord = baseCells[t];
139
+ stable_sort(ord.begin(), ord.end(), [&](int a, int b) {
140
+ int ax = a % S, ay = a / S, bx2 = b % S, by2 = b / S;
141
+ int ka = abs(ax - c0) + abs(ay - c0), kb = abs(bx2 - c0) + abs(by2 - c0);
142
+ if (ka != kb) return ka < kb;
143
+ int la = abs(ax - bx) + 2 * abs(ay - by), lb = abs(bx2 - bx) + 2 * abs(by2 - by);
144
+ return la < lb;
145
+ });
146
+ spawnOrd[t] = ord;
147
+ }
148
+ isSpot.assign(NC, 0);
149
+ for (auto& s : g.spots) { int c = s.second * S + s.first; spots.push_back(c); isSpot[c] = 1; }
150
+ }
151
+
152
+ // ---------------------------------------------------------------------------
153
+ struct EInfo {
154
+ int id, team, cell, hp, flag;
155
+ int nopt; int opt[5]; double w[5];
156
+ bool threat; // 本回合可以攻击
157
+ };
158
+
159
+ static double binomGE(int k, double p, int need) {
160
+ // P(Bin(k,p) >= need)
161
+ if (need <= 0) return 1.0;
162
+ if (need > k) return 0.0;
163
+ double tot = 0;
164
+ for (int i = need; i <= k; i++) {
165
+ double c = 1;
166
+ for (int j = 0; j < i; j++) c = c * (k - j) / (j + 1);
167
+ tot += c * pow(p, i) * pow(1 - p, k - i);
168
+ }
169
+ return tot;
170
+ }
171
+
172
+ // 敌方携旗者下一步(沿到其基地的最短路)
173
+ static int carrierNext(int team, int cell) {
174
+ int best = cell, bd = distBase[team][cell];
175
+ for (int k = 0; k < 4; k++) {
176
+ int n = NB[cell][k];
177
+ if (distBase[team][n] < bd) { bd = distBase[team][n]; best = n; }
178
+ }
179
+ return best;
180
+ }
181
+
182
+ static string decide(Game& g) {
183
+ int t = g.turn;
184
+ int NU = g.units.size();
185
+ vector<int> cell(NU, -1);
186
+ vector<char> alive(NU, 0), respNow(NU, 0);
187
+ vector<char> occ(NC, 0);
188
+ for (auto& u : g.units)
189
+ if (u.x >= 0) { cell[u.id] = u.y * S + u.x; alive[u.id] = 1; occ[cell[u.id]] = 1; }
190
+ for (auto& u : g.units) {
191
+ if (u.x < 0 && u.respawn_at >= 0 && u.respawn_at <= t) {
192
+ for (int p : spawnOrd[u.team])
193
+ if (!occ[p]) { cell[u.id] = p; occ[p] = 1; respNow[u.id] = 1; break; }
194
+ }
195
+ }
196
+ // 旗子
197
+ vector<int> flagAt(NC, -1); // 本回合可拾的旗
198
+ int offBoard = 0, returnsNow = 0;
199
+ vector<char> homeFlagSpot(NC, 0);
200
+ for (auto& f : g.flags) {
201
+ bool returning = (f.status == "dropped" || f.status == "cooldown") && f.return_at >= 0 && f.return_at <= t;
202
+ if (returning) { returnsNow++; continue; }
203
+ if (f.status == "home" || f.status == "dropped") {
204
+ int c = f.y * S + f.x;
205
+ if (flagAt[c] < 0 || f.id < flagAt[c]) flagAt[c] = f.id;
206
+ if (f.status == "home") homeFlagSpot[c] = 1;
207
+ } else offBoard++;
208
+ }
209
+ int emptySpots = 0;
210
+ for (int s : spots) if (!homeFlagSpot[s]) emptySpots++;
211
+
212
+ // 敌人信息
213
+ vector<EInfo> en;
214
+ vector<int> enIdx(NU, -1);
215
+ for (auto& u : g.units) {
216
+ if (u.team == ME || !alive[u.id]) continue;
217
+ EInfo e; e.id = u.id; e.team = u.team; e.cell = cell[u.id]; e.hp = u.hp; e.flag = u.flag;
218
+ e.threat = (u.flag < 0);
219
+ e.nopt = 0;
220
+ for (int k = 0; k < 5; k++) {
221
+ int n = NB[e.cell][k];
222
+ bool dup = false;
223
+ for (int j = 0; j < e.nopt; j++) if (e.opt[j] == n) dup = true;
224
+ if (!dup) e.opt[e.nopt++] = n;
225
+ }
226
+ if (u.flag >= 0) {
227
+ int nx = carrierNext(u.team, e.cell);
228
+ for (int j = 0; j < e.nopt; j++) e.w[j] = (e.nopt > 1) ? 0.25 / (e.nopt - 1) : 0;
229
+ for (int j = 0; j < e.nopt; j++) if (e.opt[j] == nx) e.w[j] += 0.75;
230
+ double s = 0; for (int j = 0; j < e.nopt; j++) s += e.w[j];
231
+ for (int j = 0; j < e.nopt; j++) e.w[j] /= s;
232
+ } else {
233
+ for (int j = 0; j < e.nopt; j++) e.w[j] = 1.0 / e.nopt;
234
+ }
235
+ enIdx[u.id] = en.size();
236
+ en.push_back(e);
237
+ }
238
+ int NE = en.size();
239
+
240
+ // 敌人到达各处的时间估计(非携旗者)
241
+ auto enemyEta = [&](int c) {
242
+ int best = INF;
243
+ for (auto& u : g.units) {
244
+ if (u.team == ME || u.flag >= 0) continue;
245
+ int e;
246
+ if (alive[u.id] || respNow[u.id]) e = D(cell[u.id], c);
247
+ else if (u.respawn_at >= 0) e = (u.respawn_at - t) + distBase[u.team][c] + 1;
248
+ else continue;
249
+ best = min(best, e);
250
+ }
251
+ return best;
252
+ };
253
+
254
+ // 我方单位
255
+ vector<int> my;
256
+ for (int k = 0; k < 3; k++) {
257
+ int id = 3 * ME + k;
258
+ if (alive[id] || respNow[id]) my.push_back(id);
259
+ }
260
+ int K = my.size();
261
+
262
+ // ---------------- 战略层:给每个单位分配目标 ----------------
263
+ // 携旗者:带危险代价的回家势场
264
+ vector<double> homeField(NC, 1e9);
265
+ {
266
+ vector<double> cost(NC, 1.0);
267
+ for (auto& e : en) {
268
+ if (!e.threat) continue;
269
+ for (int c = 0; c < NC; c++) {
270
+ if (W[c]) continue;
271
+ int d = D(e.cell, c);
272
+ if (d <= 1) cost[c] += 1.5; else if (d == 2) cost[c] += 1.0; else if (d == 3) cost[c] += 0.5;
273
+ }
274
+ }
275
+ priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> pq;
276
+ for (int b : baseCells[ME]) { homeField[b] = 0; pq.push({0, b}); }
277
+ while (!pq.empty()) {
278
+ auto [d, c] = pq.top(); pq.pop();
279
+ if (d > homeField[c]) continue;
280
+ for (int k = 0; k < 4; k++) {
281
+ int n = NB[c][k];
282
+ if (n == c) continue;
283
+ double nd = d + cost[n];
284
+ if (nd < homeField[n]) { homeField[n] = nd; pq.push({nd, n}); }
285
+ }
286
+ }
287
+ }
288
+
289
+ // 任务
290
+ struct Task { int type, cell, key; double base; }; // type 0 抢旗 1 拦截 2 护送 3 蹲点
291
+ vector<int> goal(NU, -1);
292
+ vector<double> gw(NU, 0);
293
+ vector<int> role(NU, -1);
294
+ vector<char> carrier(NU, 0);
295
+ for (int id : my) if (g.units[id].flag >= 0) { carrier[id] = 1; role[id] = 9; }
296
+
297
+ int remain = TURNS - t + 1;
298
+ vector<int> freeU;
299
+ for (int id : my) if (!carrier[id]) freeU.push_back(id);
300
+
301
+ int enemyAlive = 0;
302
+ for (auto& e : en) if (e.threat) enemyAlive++;
303
+ double density = 100.0 * enemyAlive / max(1, NC);
304
+ // 在 c 拾旗后能活着送回家的概率
305
+ auto pSurvive = [&](int id, int c) -> double {
306
+ int thr = 0;
307
+ for (auto& e : en) if (e.threat && D(e.cell, c) <= 5) thr++;
308
+ int helpers = 0;
309
+ for (int o : my) if (o != id && !carrier[o] && D(cell[o], c) <= 4) helpers++;
310
+ double lam = 0.7 * max(0.0, thr - 0.7 * helpers) + 0.035 * distBase[ME][c] * density;
311
+ int need = (g.units[id].hp + 33) / 34;
312
+ double p = 0, term = exp(-lam);
313
+ for (int i = 0; i < need; i++) { p += term; term *= lam / (i + 1); }
314
+ return min(1.0, p);
315
+ };
316
+
317
+ // 候选任务值矩阵
318
+ struct Cand { int unit, type, cell, key; double val; };
319
+ vector<Cand> cands;
320
+ for (int id : freeU) {
321
+ int uc = cell[id];
322
+ // 抢旗
323
+ for (int c = 0; c < NC; c++) {
324
+ if (flagAt[c] < 0) continue;
325
+ int eu = D(uc, c);
326
+ if (eu >= INF) continue;
327
+ int ee = enemyEta(c);
328
+ int margin = ee - eu;
329
+ double pw = margin >= 2 ? 1.0 : margin == 1 ? 0.85 : margin == 0 ? 0.45 : margin == -1 ? 0.2 : 0.07;
330
+ int hd = distBase[ME][c];
331
+ if (eu + hd > remain) continue;
332
+ int crowd = 0;
333
+ for (auto& e : en) if (e.threat && D(e.cell, c) <= 4) crowd++;
334
+ int mine = 0;
335
+ for (int o : my) if (o != id && !carrier[o] && D(cell[o], c) <= 4) mine++;
336
+ double cf = 1.0 / (1.0 + 0.45 * max(0, crowd - mine));
337
+ double hf = 0.55 + 0.45 * g.units[id].hp / 100.0;
338
+ double ps = pSurvive(id, c);
339
+ double v = pw * (0.12 + 0.88 * ps) * (0.6 + 0.4 * cf) * hf * 1000.0 / (eu + hd + 8);
340
+ cands.push_back({id, 0, c, flagAt[c], v});
341
+ }
342
+ // 拦截敌方携旗者
343
+ for (auto& e : en) {
344
+ if (e.flag < 0) continue;
345
+ // 路径
346
+ vector<int> path; int c = e.cell; path.push_back(c);
347
+ int guard = 0;
348
+ while (!inBase[e.team][c] && guard++ < 200) { c = carrierNext(e.team, c); path.push_back(c); }
349
+ int L = path.size() - 1;
350
+ int k0 = -1;
351
+ for (int k = 0; k <= L; k++) if (D(uc, path[k]) <= k + 2) { k0 = k; break; }
352
+ if (k0 < 0 || k0 > 10) continue;
353
+ int need = (e.hp + 33) / 34;
354
+ int avail = L - k0 + 1;
355
+ double pk = avail >= need ? 0.8 : 0.25 * avail / need;
356
+ double vd = (NT == 2 ? 1000.0 : 550.0);
357
+ // 击杀点离我家近,旗子容易抢回
358
+ int kc = path[min(k0 + need, L)];
359
+ double grab = 1000.0 * 8.0 / (distBase[ME][kc] + 8) * 0.5;
360
+ double v = pk * (vd + grab) / (k0 + 8);
361
+ int gc = path[min(L, max(k0, 1))];
362
+ cands.push_back({id, 1, gc, e.id, v});
363
+ }
364
+ // 护送
365
+ for (int m : my) {
366
+ if (!carrier[m]) continue;
367
+ int thr = 0;
368
+ for (auto& e : en) if (e.threat && D(e.cell, cell[m]) <= 7) thr++;
369
+ double v = (60.0 + 250.0 * min(thr, 3)) / (D(uc, cell[m]) + 6);
370
+ cands.push_back({id, 2, cell[m], m, v});
371
+ }
372
+ // 蹲旗点
373
+ if (offBoard + returnsNow > 0) {
374
+ for (int s : spots) {
375
+ if (homeFlagSpot[s]) continue;
376
+ bool enemyOn = false;
377
+ for (auto& e : en) if (e.cell == s) enemyOn = true;
378
+ if (enemyOn) continue;
379
+ int hd = distBase[ME][s];
380
+ double p = (double)(offBoard + returnsNow) / max(1, emptySpots);
381
+ double v = 350.0 * p / (D(uc, s) + hd + 6);
382
+ cands.push_back({id, 3, s, s, v});
383
+ }
384
+ }
385
+ }
386
+ // 贪心分配
387
+ {
388
+ vector<char> done(NU, 0);
389
+ map<pair<int, int>, int> taken; // (type,key) -> count
390
+ for (int it = 0; it < (int)freeU.size(); it++) {
391
+ double bv = -1; int bi = -1;
392
+ for (int i = 0; i < (int)cands.size(); i++) {
393
+ auto& c = cands[i];
394
+ if (done[c.unit]) continue;
395
+ int cnt = taken[{c.type, c.key}];
396
+ double v = c.val;
397
+ if (cnt > 0) {
398
+ if (c.type == 0) v *= 0.12;
399
+ else if (c.type == 1) v *= (cnt == 1 ? 0.6 : 0.3);
400
+ else if (c.type == 2) v *= 0.3;
401
+ else v = 0;
402
+ }
403
+ if (v > bv) { bv = v; bi = i; }
404
+ }
405
+ if (bi < 0) break;
406
+ auto& c = cands[bi];
407
+ done[c.unit] = 1; taken[{c.type, c.key}]++;
408
+ goal[c.unit] = c.cell; role[c.unit] = c.type;
409
+ gw[c.unit] = c.type == 0 ? 30 : c.type == 1 ? 25 : c.type == 2 ? 12 : 8;
410
+ }
411
+ for (int id : freeU) if (!done[id]) {
412
+ // 默认:去离家最近的旗点
413
+ int bs = spots[0]; int bd = INF;
414
+ for (int s : spots) { int d = distBase[ME][s] + D(cell[id], s) / 2; if (d < bd) { bd = d; bs = s; } }
415
+ goal[id] = bs; role[id] = 4; gw[id] = 5;
416
+ }
417
+ }
418
+
419
+ // ---------------- 战术层:联合走位搜索 ----------------
420
+ // 每个单位每个移动后的位置、危险、可命中的敌人
421
+ struct MoveInfo { int nc; double danger; unsigned long long thr; vector<pair<int, int>> hits; /* (enemy idx, mask) */ };
422
+ vector<array<MoveInfo, 5>> mi(K);
423
+ const double P_ATK = 0.5;
424
+ for (int i = 0; i < K; i++) {
425
+ int id = my[i];
426
+ int hp = g.units[id].hp;
427
+ bool imm = respNow[id];
428
+ for (int m = 0; m < 5; m++) {
429
+ MoveInfo& M = mi[i][m];
430
+ M.nc = NB[cell[id]][m];
431
+ // 危险
432
+ int tc = 0;
433
+ M.thr = 0;
434
+ if (!imm) {
435
+ for (int ei = 0; ei < NE; ei++) {
436
+ auto& e = en[ei];
437
+ if (!e.threat) continue;
438
+ if (D(e.cell, M.nc) > 3 && abs(e.cell % S - M.nc % S) + abs(e.cell / S - M.nc / S) > 3) continue;
439
+ bool can = false;
440
+ for (int j = 0; j < e.nopt && !can; j++) if (canAtk(e.opt[j], M.nc)) can = true;
441
+ if (can) { tc++; if (ei < 64) M.thr |= 1ULL << ei; }
442
+ }
443
+ }
444
+ int need = (hp + 33) / 34;
445
+ double pd = binomGE(tc, carrier[id] ? 0.85 : P_ATK, need);
446
+ double deathCost = carrier[id] ? CARRIER_DEATH : UNIT_DEATH;
447
+ M.danger = pd * deathCost + tc * (carrier[id] ? 0.85 * CARRIER_HIT : P_ATK * HIT_COST);
448
+ // 命中
449
+ if (!imm && !carrier[id]) {
450
+ for (int j = 0; j < NE; j++) {
451
+ auto& e = en[j];
452
+ int mask = 0;
453
+ for (int q = 0; q < e.nopt; q++) if (canAtk(M.nc, e.opt[q])) mask |= 1 << q;
454
+ if (mask) M.hits.push_back({j, mask});
455
+ }
456
+ }
457
+ }
458
+ }
459
+ auto fieldVal = [&](int id, int c) -> double {
460
+ if (carrier[id]) return homeField[c];
461
+ if (goal[id] < 0) return 0;
462
+ int d = D(goal[id], c);
463
+ return d;
464
+ };
465
+ auto enemyKillVal = [&](const EInfo& e) {
466
+ double v = KILL_BASE;
467
+ if (e.flag >= 0) {
468
+ v += KILL_CARRIER;
469
+ }
470
+ return v;
471
+ };
472
+
473
+ double bestScore = -1e18;
474
+ int bestMv[3] = {4, 4, 4};
475
+ int bestAct[3] = {-1, -1, -1}; // -1 无, -2 拾旗, >=0 攻击 id
476
+ int total = 1; for (int i = 0; i < K; i++) total *= 5;
477
+ vector<int> startCell(K), want(K);
478
+ for (int i = 0; i < K; i++) startCell[i] = cell[my[i]];
479
+ auto tStart = chrono::steady_clock::now();
480
+ for (int combo = 0; combo < total; combo++) {
481
+ if ((combo & 7) == 0 && chrono::duration<double, milli>(chrono::steady_clock::now() - tStart).count() > 25.0) break;
482
+ int mv[3]; int cc = combo;
483
+ for (int i = 0; i < K; i++) { mv[i] = cc % 5; cc /= 5; }
484
+ bool bad = false;
485
+ for (int i = 0; i < K; i++) {
486
+ want[i] = mi[i][mv[i]].nc;
487
+ if (want[i] != startCell[i] && occ[want[i]]) {
488
+ // 有人占着:只允许是我方会离开的单位
489
+ bool ok = false;
490
+ for (int j = 0; j < K; j++) if (j != i && startCell[j] == want[i] && want[j] != startCell[j]) ok = true;
491
+ if (!ok) { bad = true; break; }
492
+ }
493
+ }
494
+ if (bad) continue;
495
+ for (int i = 0; i < K && !bad; i++)
496
+ for (int j = i + 1; j < K; j++) if (want[i] == want[j]) { bad = true; break; }
497
+ if (bad) continue;
498
+ double sc = 0;
499
+ for (int i = 0; i < K; i++) {
500
+ int id = my[i];
501
+ sc -= gw[id] * fieldVal(id, want[i]) + (carrier[id] ? CARRIER_PROG * homeField[want[i]] : 0);
502
+ if (!JOINT) sc -= mi[i][mv[i]].danger;
503
+ if (carrier[id] && inBase[ME][want[i]]) sc += 5000;
504
+ }
505
+ if (JOINT) {
506
+ double wg[3];
507
+ for (int i = 0; i < K; i++) { int id = my[i]; wg[i] = 1.0 + (g.units[id].hp <= 34 ? 1.5 : 0) + (carrier[id] ? 2.5 : 0); }
508
+ unsigned long long all = 0;
509
+ for (int i = 0; i < K; i++) all |= mi[i][mv[i]].thr;
510
+ double dp[3][4]; double eh[3];
511
+ int needI[3];
512
+ for (int i = 0; i < K; i++) { needI[i] = (g.units[my[i]].hp + 33) / 34; for (int k = 0; k < 4; k++) dp[i][k] = 0; dp[i][0] = 1; eh[i] = 0; }
513
+ while (all) {
514
+ int e = __builtin_ctzll(all); all &= all - 1;
515
+ double sw = 0;
516
+ for (int i = 0; i < K; i++) if (mi[i][mv[i]].thr >> e & 1) sw += wg[i];
517
+ for (int i = 0; i < K; i++) if (mi[i][mv[i]].thr >> e & 1) {
518
+ double p = PA * wg[i] / sw;
519
+ eh[i] += p;
520
+ for (int k = 3; k >= 1; k--) dp[i][k] = dp[i][k] * (1 - p) + dp[i][k - 1] * p + (k == 3 ? dp[i][3] * p : 0);
521
+ dp[i][0] *= (1 - p);
522
+ }
523
+ }
524
+ for (int i = 0; i < K; i++) {
525
+ int id = my[i];
526
+ double pd = 0;
527
+ for (int k = needI[i]; k <= 3; k++) pd += dp[i][k];
528
+ double deathCost = carrier[id] ? CARRIER_DEATH : UNIT_DEATH;
529
+ sc -= pd * deathCost + eh[i] * (carrier[id] ? CARRIER_HIT : HIT_COST);
530
+ }
531
+ }
532
+ // 动作选择:拾旗 / 攻击
533
+ int act[3] = {-1, -1, -1};
534
+ double pickVal[3] = {0, 0, 0};
535
+ vector<char> flagClaim(0);
536
+ int claimed[3] = {-1, -1, -1};
537
+ for (int i = 0; i < K; i++) {
538
+ int id = my[i];
539
+ if (carrier[id]) continue;
540
+ int c = want[i];
541
+ if (flagAt[c] >= 0) {
542
+ bool dup = false;
543
+ for (int j = 0; j < i; j++) if (claimed[j] == c) dup = true;
544
+ if (!dup) { claimed[i] = c; pickVal[i] = (200.0 + 1300.0 * pSurvive(id, c)) - 10 * distBase[ME][c]; }
545
+ } else if (returnsNow > 0 && isSpot[c] && !homeFlagSpot[c]) {
546
+ pickVal[i] = 1000.0 * returnsNow / max(1, emptySpots) * 0.8;
547
+ }
548
+ }
549
+ // 枚举攻击分配
550
+ double bestA = -1e18; int ba[3] = {-1, -1, -1};
551
+ int choices[3][16]; int nch[3];
552
+ for (int i = 0; i < 3; i++) nch[i] = 0;
553
+ for (int i = 0; i < K; i++) {
554
+ choices[i][nch[i]++] = -1;
555
+ if (pickVal[i] > 0) choices[i][nch[i]++] = -2;
556
+ {
557
+ auto& hs = mi[i][mv[i]].hits;
558
+ if ((int)hs.size() <= 6) { for (auto& h : hs) choices[i][nch[i]++] = h.first; }
559
+ else {
560
+ vector<pair<double, int>> pr;
561
+ for (auto& h : hs) {
562
+ double p = 0; const EInfo& E = en[h.first];
563
+ for (int q = 0; q < E.nopt; q++) if (h.second >> q & 1) p += E.w[q];
564
+ p *= enemyKillVal(E) / (double)((E.hp + 33) / 34);
565
+ pr.push_back({-p, h.first});
566
+ }
567
+ sort(pr.begin(), pr.end());
568
+ for (int k = 0; k < 6; k++) choices[i][nch[i]++] = pr[k].second;
569
+ }
570
+ }
571
+ }
572
+ int sel[3] = {0, 0, 0};
573
+ int tot2 = 1; for (int i = 0; i < K; i++) tot2 *= nch[i];
574
+ for (int a = 0; a < tot2; a++) {
575
+ int aa = a;
576
+ for (int i = 0; i < K; i++) { sel[i] = choices[i][aa % nch[i]]; aa /= nch[i]; }
577
+ double v = 0;
578
+ for (int i = 0; i < K; i++) if (sel[i] == -2) v += pickVal[i];
579
+ // 按敌人汇总
580
+ for (int i = 0; i < K; i++) {
581
+ if (sel[i] < 0) continue;
582
+ int e = sel[i];
583
+ bool first = true;
584
+ for (int j = 0; j < i; j++) if (sel[j] == e) first = false;
585
+ if (!first) continue;
586
+ const EInfo& E = en[e];
587
+ int need = (E.hp + 33) / 34;
588
+ double pk = 0, eh = 0;
589
+ for (int q = 0; q < E.nopt; q++) {
590
+ int hits = 0;
591
+ for (int j = i; j < K; j++) if (sel[j] == e) {
592
+ for (auto& h : mi[j][mv[j]].hits) if (h.first == e && (h.second >> q & 1)) hits++;
593
+ }
594
+ if (hits >= need) pk += E.w[q];
595
+ eh += E.w[q] * min(hits, need);
596
+ }
597
+ double kv = enemyKillVal(E);
598
+ v += pk * kv + eh * kv * 0.22;
599
+ }
600
+ if (v > bestA) { bestA = v; for (int i = 0; i < K; i++) ba[i] = sel[i]; }
601
+ }
602
+ sc += bestA;
603
+ if (sc > bestScore) {
604
+ bestScore = sc;
605
+ for (int i = 0; i < K; i++) { bestMv[i] = mv[i]; bestAct[i] = ba[i]; }
606
+ }
607
+ }
608
+
609
+ // 输出
610
+ string out = to_string(t);
611
+ string notes = " #";
612
+ for (int k = 0; k < 3; k++) {
613
+ int id = 3 * ME + k;
614
+ int idx = -1;
615
+ for (int i = 0; i < K; i++) if (my[i] == id) idx = i;
616
+ if (idx < 0) { out += " S -"; notes += "dead;"; continue; }
617
+ out += ' '; out += MC[bestMv[idx]];
618
+ int a = bestAct[idx];
619
+ if (carrier[id]) out += " -";
620
+ else if (a == -2) out += " P";
621
+ else if (a >= 0) out += " " + to_string(en[a].id);
622
+ else {
623
+ // 站在旗点上且可能刷旗时顺手拾旗
624
+ int nc = mi[idx][bestMv[idx]].nc;
625
+ if (flagAt[nc] >= 0 || (returnsNow > 0 && isSpot[nc])) out += " P";
626
+ else out += " -";
627
+ }
628
+ const char* rn[] = {"grab", "intercept", "escort", "camp", "idle"};
629
+ int r = role[id];
630
+ notes += (r == 9 ? string("carry") : (r >= 0 && r <= 4 ? string(rn[r]) : string("?")));
631
+ notes += ";";
632
+ }
633
+ if (!notes.empty() && notes.back() == ';') notes.pop_back();
634
+ return out + notes;
635
+ }
636
+
637
+ int main() {
638
+ ios::sync_with_stdio(false);
639
+ Game g;
640
+ bool inited = false;
641
+ while (read_turn(g)) {
642
+ if (!inited) { init(g); inited = true; }
643
+ cout << decide(g) << endl;
644
+ }
645
+ }