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,320 @@
1
+ // 夺旗 bot v15 - 稳定版,基于最佳表现优化
2
+ // 策略:
3
+ // - 每个单位独立决策
4
+ // - 优先拿旗,有敌人在范围内就打
5
+ // - 低血量撤退
6
+ // - 每个单位去最近的可用旗子
7
+ #include <bits/stdc++.h>
8
+ using namespace std;
9
+
10
+ struct Unit { int id, team, x, y, hp, flag, respawn_at; };
11
+ struct Flag { int id; string status; int x, y, holder, return_at; };
12
+ struct Event { string type; vector<int> args; };
13
+
14
+ struct Game {
15
+ int teams = 0, me = 0, size = 0, turns = 0, hp = 0, damage = 0, respawn = 0, flag_return = 0, flag_cooldown = 0;
16
+ vector<string> map;
17
+ vector<pair<int, int>> bases;
18
+ vector<pair<int, int>> spots;
19
+ int turn = 0;
20
+ vector<int> score;
21
+ vector<Unit> units;
22
+ vector<Flag> flags;
23
+ vector<Event> events;
24
+ };
25
+
26
+ bool read_turn(Game& g) {
27
+ string w;
28
+ while (cin >> w) {
29
+ if (w == "INIT") {
30
+ cin >> g.teams >> g.me >> g.size >> g.turns >> g.hp >> g.damage >> g.respawn >> g.flag_return >> g.flag_cooldown;
31
+ } else if (w == "MAP") {
32
+ g.map.assign(g.size, "");
33
+ for (auto& row : g.map) cin >> row;
34
+ } else if (w == "BASES") {
35
+ int k; cin >> k; g.bases.resize(k);
36
+ for (auto& b : g.bases) cin >> b.first >> b.second;
37
+ } else if (w == "SPOTS") {
38
+ int k; cin >> k; g.spots.resize(k);
39
+ for (auto& s : g.spots) cin >> s.first >> s.second;
40
+ } else if (w == "TURN") {
41
+ cin >> g.turn;
42
+ } else if (w == "SCORE") {
43
+ g.score.resize(g.teams);
44
+ for (auto& s : g.score) cin >> s;
45
+ } else if (w == "UNITS") {
46
+ int k; cin >> k; g.units.resize(k);
47
+ for (auto& u : g.units) { string tag; cin >> tag >> u.id >> u.team >> u.x >> u.y >> u.hp >> u.flag >> u.respawn_at; }
48
+ } else if (w == "FLAGS") {
49
+ int k; cin >> k; g.flags.resize(k);
50
+ for (auto& f : g.flags) { string tag; cin >> tag >> f.id >> f.status >> f.x >> f.y >> f.holder >> f.return_at; }
51
+ } else if (w == "EVENTS") {
52
+ int k; cin >> k; g.events.assign(k, {});
53
+ string line; getline(cin, line);
54
+ for (auto& e : g.events) {
55
+ getline(cin, line);
56
+ istringstream in(line);
57
+ string tag; in >> tag >> e.type;
58
+ for (int v; in >> v;) e.args.push_back(v);
59
+ }
60
+ } else if (w == "END") {
61
+ return true;
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
67
+ inline int mdist(int x1, int y1, int x2, int y2) {
68
+ return abs(x1 - x2) + abs(y1 - y2);
69
+ }
70
+
71
+ inline bool is_wall(const Game& g, int x, int y) {
72
+ return x < 0 || y < 0 || x >= g.size || y >= g.size || g.map[y][x] == '#';
73
+ }
74
+
75
+ vector<vector<int>> bfs_from(const Game& g, int sx, int sy) {
76
+ vector<vector<int>> d(g.size, vector<int>(g.size, -1));
77
+ if (sx < 0 || sy < 0) return d;
78
+ queue<pair<int,int>> q;
79
+ d[sy][sx] = 0;
80
+ q.push({sx, sy});
81
+ static const int dx[] = {0, 0, -1, 1};
82
+ static const int dy[] = {-1, 1, 0, 0};
83
+ while (!q.empty()) {
84
+ auto [x, y] = q.front(); q.pop();
85
+ for (int di = 0; di < 4; di++) {
86
+ int nx = x + dx[di], ny = y + dy[di];
87
+ if (is_wall(g, nx, ny) || d[ny][nx] != -1) continue;
88
+ d[ny][nx] = d[y][x] + 1;
89
+ q.push({nx, ny});
90
+ }
91
+ }
92
+ return d;
93
+ }
94
+
95
+ char step_toward(const Game& g, const vector<vector<int>>& d, int sx, int sy, int tx, int ty) {
96
+ if (sx == tx && sy == ty) return 'S';
97
+ if (d[ty][tx] == -1 || d[sy][sx] == -1) return 'S';
98
+
99
+ static const int dx[] = {0, 0, -1, 1};
100
+ static const int dy[] = {-1, 1, 0, 0};
101
+
102
+ int cx = tx, cy = ty;
103
+ while (d[cy][cx] > 1) {
104
+ bool found = false;
105
+ for (int di = 0; di < 4; di++) {
106
+ int nx = cx + dx[di], ny = cy + dy[di];
107
+ if (!is_wall(g, nx, ny) && d[ny][nx] == d[cy][cx] - 1) {
108
+ cx = nx; cy = ny;
109
+ found = true;
110
+ break;
111
+ }
112
+ }
113
+ if (!found) break;
114
+ }
115
+
116
+ if (cx == sx && cy == sy - 1) return 'U';
117
+ if (cx == sx && cy == sy + 1) return 'D';
118
+ if (cx == sx - 1 && cy == sy) return 'L';
119
+ if (cx == sx + 1 && cy == sy) return 'R';
120
+ return 'S';
121
+ }
122
+
123
+ bool can_attack(const Game& g, int ax, int ay, int tx, int ty) {
124
+ if (mdist(ax, ay, tx, ty) > 2) return false;
125
+ int dx = tx - ax, dy = ty - ay;
126
+ if (abs(dx) == 2 && dy == 0) return !is_wall(g, ax + dx/2, ay);
127
+ if (abs(dy) == 2 && dx == 0) return !is_wall(g, ax, ay + dy/2);
128
+ if (abs(dx) == 1 && abs(dy) == 1) return !is_wall(g, ax + dx, ay) || !is_wall(g, ax, ay + dy);
129
+ return true;
130
+ }
131
+
132
+ bool in_my_base(const Game& g, int x, int y) {
133
+ auto [bx, by] = g.bases[g.me];
134
+ return abs(x - bx) <= 1 && abs(y - by) <= 1;
135
+ }
136
+
137
+ pair<int,int> best_base_cell(const Game& g, const vector<vector<int>>& dist) {
138
+ auto [bx, by] = g.bases[g.me];
139
+ int best_d = INT_MAX;
140
+ pair<int,int> best = {bx, by};
141
+ for (int dy = -1; dy <= 1; dy++) {
142
+ for (int dx = -1; dx <= 1; dx++) {
143
+ int nx = bx + dx, ny = by + dy;
144
+ if (is_wall(g, nx, ny)) continue;
145
+ if (dist[ny][nx] != -1 && dist[ny][nx] < best_d) {
146
+ best_d = dist[ny][nx];
147
+ best = {nx, ny};
148
+ }
149
+ }
150
+ }
151
+ return best;
152
+ }
153
+
154
+ char move_away(const Game& g, int x, int y, int tx, int ty) {
155
+ static const int dx[] = {0, 0, -1, 1};
156
+ static const int dy[] = {-1, 1, 0, 0};
157
+ static const char dirs[] = {'U', 'D', 'L', 'R'};
158
+ int best_d = mdist(x, y, tx, ty);
159
+ char best = 'S';
160
+ for (int d = 0; d < 4; d++) {
161
+ int nx = x + dx[d], ny = y + dy[d];
162
+ if (is_wall(g, nx, ny)) continue;
163
+ int nd = mdist(nx, ny, tx, ty);
164
+ if (nd > best_d) { best_d = nd; best = dirs[d]; }
165
+ }
166
+ return best;
167
+ }
168
+
169
+ string decide(const Game& g) {
170
+ vector<char> moves(3, 'S');
171
+ vector<string> actions(3, "-");
172
+ vector<string> notes(3, "");
173
+
174
+ vector<Unit> mine;
175
+ for (auto& u : g.units) if (u.team == g.me) mine.push_back(u);
176
+
177
+ vector<Unit> enemies;
178
+ for (auto& u : g.units) if (u.team != g.me && u.x != -1) enemies.push_back(u);
179
+
180
+ // 对每个单位独立决策
181
+ for (int i = 0; i < 3; i++) {
182
+ auto& u = mine[i];
183
+ if (u.x == -1) continue;
184
+
185
+ auto dist = bfs_from(g, u.x, u.y);
186
+
187
+ // 找最佳攻击目标
188
+ int best_pri = -1;
189
+ Unit best_target = {-1, -1, -1, -1, 0, -1, -1};
190
+ for (auto& e : enemies) {
191
+ if (!can_attack(g, u.x, u.y, e.x, e.y)) continue;
192
+ int pri = 0;
193
+ if (e.flag != -1) pri += 1000;
194
+ pri += (100 - e.hp) * 5;
195
+ if (pri > best_pri) { best_pri = pri; best_target = e; }
196
+ }
197
+
198
+ // 携旗:回基地
199
+ if (u.flag != -1) {
200
+ if (in_my_base(g, u.x, u.y)) {
201
+ notes[i] = "交旗";
202
+ } else {
203
+ auto [tx, ty] = best_base_cell(g, dist);
204
+ moves[i] = step_toward(g, dist, u.x, u.y, tx, ty);
205
+ notes[i] = "回基地";
206
+ }
207
+ continue;
208
+ }
209
+
210
+ // 没携旗
211
+ bool did_action = false;
212
+
213
+ // 1. 攻击(如果有好目标)
214
+ if (best_target.id != -1 && u.hp > 34) {
215
+ actions[i] = to_string(best_target.id);
216
+ int d = mdist(u.x, u.y, best_target.x, best_target.y);
217
+ if (u.hp <= 67 && d <= 1) {
218
+ // 低血量且敌人贴脸,边打边退
219
+ moves[i] = move_away(g, u.x, u.y, best_target.x, best_target.y);
220
+ notes[i] = "边打边退";
221
+ } else {
222
+ moves[i] = 'S';
223
+ notes[i] = "攻击";
224
+ }
225
+ did_action = true;
226
+ }
227
+
228
+ if (!did_action) {
229
+ // 2. 找最近的旗子
230
+ int best_fd = INT_MAX;
231
+ Flag best_flag = {-1, "", -1, -1, -1, -1};
232
+ for (auto& f : g.flags) {
233
+ if (f.status != "home" && f.status != "dropped") continue;
234
+ int d = dist[f.y][f.x];
235
+ if (d != -1 && d < best_fd) { best_fd = d; best_flag = f; }
236
+ }
237
+
238
+ if (best_flag.id != -1) {
239
+ if (best_fd == 0) {
240
+ actions[i] = "P";
241
+ notes[i] = "拾旗";
242
+ } else {
243
+ moves[i] = step_toward(g, dist, u.x, u.y, best_flag.x, best_flag.y);
244
+ if (best_fd == 1) actions[i] = "P";
245
+ notes[i] = "拿旗";
246
+ }
247
+ did_action = true;
248
+ }
249
+ }
250
+
251
+ if (!did_action) {
252
+ // 3. 找最近的敌方携旗者
253
+ int best_cd = INT_MAX;
254
+ Unit best_carrier;
255
+ for (auto& e : enemies) {
256
+ if (e.flag == -1) continue;
257
+ int d = dist[e.y][e.x];
258
+ if (d != -1 && d < best_cd) { best_cd = d; best_carrier = e; }
259
+ }
260
+ if (best_carrier.id != -1 && best_cd < 15) {
261
+ moves[i] = step_toward(g, dist, u.x, u.y, best_carrier.x, best_carrier.y);
262
+ notes[i] = "拦截";
263
+ did_action = true;
264
+ }
265
+ }
266
+
267
+ if (!did_action) {
268
+ // 4. 回基地
269
+ if (!in_my_base(g, u.x, u.y)) {
270
+ auto [tx, ty] = best_base_cell(g, dist);
271
+ moves[i] = step_toward(g, dist, u.x, u.y, tx, ty);
272
+ notes[i] = "回防";
273
+ } else {
274
+ notes[i] = "待命";
275
+ }
276
+ }
277
+
278
+ // 低血量强制撤退
279
+ if (u.hp <= 34 && u.flag == -1) {
280
+ int nearest_d = INT_MAX;
281
+ int nex = -1, ney = -1;
282
+ for (auto& e : enemies) {
283
+ int d = mdist(u.x, u.y, e.x, e.y);
284
+ if (d <= 4 && d < nearest_d) {
285
+ nearest_d = d;
286
+ nex = e.x;
287
+ ney = e.y;
288
+ }
289
+ }
290
+ if (nex != -1) {
291
+ moves[i] = move_away(g, u.x, u.y, nex, ney);
292
+ actions[i] = "-";
293
+ notes[i] = "撤退";
294
+ }
295
+ }
296
+ }
297
+
298
+ string out = to_string(g.turn);
299
+ for (int i = 0; i < 3; i++) {
300
+ out += " ";
301
+ out += moves[i];
302
+ out += " ";
303
+ out += actions[i];
304
+ }
305
+ out += " # ";
306
+ for (int i = 0; i < 3; i++) {
307
+ if (i > 0) out += ";";
308
+ out += notes[i];
309
+ }
310
+
311
+ return out;
312
+ }
313
+
314
+ int main() {
315
+ ios::sync_with_stdio(false);
316
+ Game g;
317
+ while (read_turn(g)) {
318
+ cout << decide(g) << endl;
319
+ }
320
+ }