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,533 @@
1
+ // Competitive multi-team CTF bot.
2
+ // Direct BFS movement + aggressive opportunistic combat.
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
+ // ============================== WORLD =====================================
64
+ static int SZ, NTEAMS, ME, TURNS, FULLHP;
65
+ static vector<vector<char>> WALL;
66
+ static vector<vector<pair<int,int>>> ALLBASE, SPAWNORD;
67
+ static vector<pair<int,int>> MYBASE, SPOTS;
68
+ static vector<vector<int>> BASEDIST;
69
+ static vector<vector<vector<int>>> SPOTDIST;
70
+
71
+ static inline bool isWall(int x, int y) {
72
+ return x < 0 || y < 0 || x >= SZ || y >= SZ || WALL[y][x] == '#';
73
+ }
74
+ static inline int manh(int x1, int y1, int x2, int y2) {
75
+ return abs(x1 - x2) + abs(y1 - y2);
76
+ }
77
+ static bool canAttack(int ax, int ay, int bx, int by) {
78
+ int dx = bx - ax, dy = by - ay;
79
+ if (abs(dx) + abs(dy) > 2) return false;
80
+ if (abs(dx) == 2 && dy == 0) return !isWall(ax + dx / 2, ay);
81
+ if (abs(dy) == 2 && dx == 0) return !isWall(ax, ay + dy / 2);
82
+ if (abs(dx) == 1 && abs(dy) == 1) return !isWall(ax + dx, ay) || !isWall(ax, ay + dy);
83
+ return true;
84
+ }
85
+
86
+ static vector<vector<int>> bfsMulti(const vector<pair<int,int>>& src) {
87
+ vector<vector<int>> dist(SZ, vector<int>(SZ, -1));
88
+ queue<pair<int,int>> q;
89
+ for (auto [x, y] : src) {
90
+ if (isWall(x, y) || dist[y][x] >= 0) continue;
91
+ dist[y][x] = 0; q.push({x, y});
92
+ }
93
+ static const int DX[4] = {0, 0, -1, 1}, DY[4] = {-1, 1, 0, 0};
94
+ while (!q.empty()) {
95
+ auto [x, y] = q.front(); q.pop();
96
+ int d = dist[y][x];
97
+ for (int k = 0; k < 4; k++) {
98
+ int nx = x + DX[k], ny = y + DY[k];
99
+ if (isWall(nx, ny) || dist[ny][nx] >= 0) continue;
100
+ dist[ny][nx] = d + 1; q.push({nx, ny});
101
+ }
102
+ }
103
+ return dist;
104
+ }
105
+ static inline int distTo(const vector<vector<int>>& f, int x, int y) {
106
+ if (x < 0 || y < 0 || x >= SZ || y >= SZ) return 1 << 28;
107
+ int d = f[y][x];
108
+ return d < 0 ? 1 << 28 : d;
109
+ }
110
+
111
+ static const int MX[5] = {0, 0, 0, -1, 1};
112
+ static const int MY[5] = {0, -1, 1, 0, 0};
113
+ static const char MC[5] = {'S', 'U', 'D', 'L', 'R'};
114
+
115
+ static pair<int,int> bestStep(const vector<vector<int>>& fld, int x, int y) {
116
+ int best = distTo(fld, x, y), bx = x, by = y;
117
+ for (int k = 0; k < 5; k++) {
118
+ int nx = x + MX[k], ny = y + MY[k];
119
+ if (isWall(nx, ny)) continue;
120
+ int d = distTo(fld, nx, ny);
121
+ if (d < best) { best = d; bx = nx; by = ny; }
122
+ }
123
+ return {bx, by};
124
+ }
125
+
126
+ static void initWorld(const Game& g) {
127
+ SZ = g.size; NTEAMS = g.teams; ME = g.me; TURNS = g.turns; FULLHP = g.hp;
128
+ WALL.assign(SZ, vector<char>(SZ, '.'));
129
+ for (int y = 0; y < SZ; y++)
130
+ for (int x = 0; x < SZ; x++)
131
+ WALL[y][x] = g.map[y][x];
132
+ SPOTS = g.spots;
133
+ ALLBASE.assign(NTEAMS, {});
134
+ SPAWNORD.assign(NTEAMS, {});
135
+ int cc = SZ / 2;
136
+ for (int t = 0; t < NTEAMS; t++) {
137
+ auto [cx, cy] = g.bases[t];
138
+ vector<pair<int,int>> cells;
139
+ for (int dy = -1; dy <= 1; dy++)
140
+ for (int dx = -1; dx <= 1; dx++)
141
+ cells.push_back({cx + dx, cy + dy});
142
+ ALLBASE[t] = cells;
143
+ vector<pair<int,int>> ord = cells;
144
+ sort(ord.begin(), ord.end(), [&](auto a, auto b) {
145
+ int da = manh(a.first, a.second, cc, cc);
146
+ int db = manh(b.first, b.second, cc, cc);
147
+ if (da != db) return da < db;
148
+ int ta = abs(a.first - cx) + 2 * abs(a.second - cy);
149
+ int tb = abs(b.first - cx) + 2 * abs(b.second - cy);
150
+ return ta < tb;
151
+ });
152
+ SPAWNORD[t] = ord;
153
+ }
154
+ MYBASE = ALLBASE[ME];
155
+ BASEDIST = bfsMulti(MYBASE);
156
+ SPOTDIST.clear();
157
+ for (auto& s : SPOTS) SPOTDIST.push_back(bfsMulti({s}));
158
+ }
159
+
160
+ // ============================== DECISION ==================================
161
+ struct Live {
162
+ int uid, slot, x, y, hp, flag;
163
+ bool spawning;
164
+ };
165
+ struct Enemy { int uid, x, y, hp, flag; };
166
+
167
+ static string decide(const Game& g) {
168
+ static bool inited = false;
169
+ if (!inited) { initWorld(g); inited = true; }
170
+
171
+ // --- live units / respawns ---
172
+ vector<pair<int,int>> occ;
173
+ for (auto& u : g.units) if (u.x >= 0) occ.push_back({u.x, u.y});
174
+ auto isOcc = [&](int x, int y) {
175
+ for (auto& p : occ) if (p.first == x && p.second == y) return true;
176
+ return false;
177
+ };
178
+ vector<pair<int,int>> spawnPos(g.units.size(), {-1, -1});
179
+ for (auto& u : g.units) {
180
+ if (u.x >= 0) spawnPos[u.id] = {u.x, u.y};
181
+ else if (u.respawn_at == g.turn) {
182
+ for (auto& p : SPAWNORD[u.team]) {
183
+ if (!isOcc(p.first, p.second)) {
184
+ spawnPos[u.id] = p;
185
+ occ.push_back(p);
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ vector<Live> mine;
193
+ vector<Enemy> enemies;
194
+ for (auto& u : g.units) {
195
+ if (spawnPos[u.id].first < 0) continue;
196
+ if (u.team == ME) {
197
+ int hp = (u.respawn_at == g.turn) ? FULLHP : u.hp;
198
+ mine.push_back({u.id, u.id - 3 * ME, spawnPos[u.id].first, spawnPos[u.id].second,
199
+ hp, u.flag, u.respawn_at == g.turn});
200
+ } else {
201
+ enemies.push_back({u.id, spawnPos[u.id].first, spawnPos[u.id].second, u.hp, u.flag});
202
+ }
203
+ }
204
+
205
+ auto idle = [&]() {
206
+ string out = to_string(g.turn);
207
+ for (int k = 0; k < 3; k++) out += " S -";
208
+ return out;
209
+ };
210
+ if (mine.empty()) return idle();
211
+
212
+ // --- flags ---
213
+ vector<pair<int,int>> freeFlags;
214
+ vector<int> freeFlagId;
215
+ for (auto& f : g.flags) {
216
+ if (f.status == "home" || f.status == "dropped") {
217
+ freeFlags.push_back({f.x, f.y});
218
+ freeFlagId.push_back(f.id);
219
+ }
220
+ }
221
+
222
+ unordered_map<int, vector<vector<int>>> flagFields;
223
+ for (int j = 0; j < (int)freeFlags.size(); j++)
224
+ flagFields[freeFlagId[j]] = bfsMulti({freeFlags[j]});
225
+
226
+ int n = (int)mine.size();
227
+
228
+ // --- predict enemy positions ---
229
+ vector<pair<int,int>> enemyPos(enemies.size());
230
+ for (int ei = 0; ei < (int)enemies.size(); ei++) {
231
+ auto& e = enemies[ei];
232
+ if (e.flag >= 0) {
233
+ auto fld = bfsMulti(ALLBASE[e.uid / 3]);
234
+ enemyPos[ei] = bestStep(fld, e.x, e.y);
235
+ } else {
236
+ int bestD = 1 << 28;
237
+ pair<int,int> tgt = {e.x, e.y};
238
+ for (auto& [fx, fy] : freeFlags) {
239
+ int dd = manh(e.x, e.y, fx, fy);
240
+ if (dd < bestD) { bestD = dd; tgt = {fx, fy}; }
241
+ }
242
+ if (bestD < 1 << 27) {
243
+ auto fld = bfsMulti({tgt});
244
+ enemyPos[ei] = bestStep(fld, e.x, e.y);
245
+ } else {
246
+ enemyPos[ei] = {e.x, e.y};
247
+ }
248
+ }
249
+ }
250
+
251
+ // --- assign goals ---
252
+ struct Plan {
253
+ int kind; // 0 home, 1 flag, 2 hunt, 3 spot, 4 escort
254
+ const vector<vector<int>>* fld;
255
+ int tx, ty;
256
+ };
257
+ vector<Plan> plans(n);
258
+ vector<char> assigned(n, 0);
259
+ vector<unique_ptr<vector<vector<int>>>> owned;
260
+
261
+ // 1. carriers -> home
262
+ for (int i = 0; i < n; i++) {
263
+ if (mine[i].flag >= 0) {
264
+ plans[i] = {0, &BASEDIST, -1, -1};
265
+ assigned[i] = 1;
266
+ }
267
+ }
268
+
269
+ // 2. hunt enemy carrier
270
+ {
271
+ int bestUid = -1, bestRem = 1 << 28;
272
+ for (auto& e : enemies) {
273
+ if (e.flag < 0) continue;
274
+ auto fld = bfsMulti(ALLBASE[e.uid / 3]);
275
+ int rem = distTo(fld, e.x, e.y);
276
+ if (rem < bestRem) { bestRem = rem; bestUid = e.uid; }
277
+ }
278
+ // hunt only if no free flags or enemy is about to score (adapt by team count)
279
+ bool anyFreeFlag = !freeFlags.empty();
280
+ int huntRange = (NTEAMS <= 2) ? 28 : (NTEAMS <= 3 ? 20 : 12);
281
+ // in multi-team with free flags available, skip hunting entirely
282
+ if (NTEAMS >= 5 && anyFreeFlag) huntRange = 0;
283
+ if (bestUid >= 0 && bestRem <= huntRange) {
284
+ Enemy* pe = nullptr;
285
+ for (auto& e : enemies) if (e.uid == bestUid) pe = &e;
286
+ if (pe) {
287
+ int maxHunt = (NTEAMS <= 2) ? 2 : 1;
288
+ for (int h = 0; h < maxHunt; h++) {
289
+ int bestI = -1, bestD = 1 << 28;
290
+ for (int i = 0; i < n; i++) {
291
+ if (assigned[i]) continue;
292
+ int dd = manh(mine[i].x, mine[i].y, pe->x, pe->y);
293
+ if (dd < bestD) { bestD = dd; bestI = i; }
294
+ }
295
+ if (bestI < 0) break;
296
+ auto fld = make_unique<vector<vector<int>>>(bfsMulti({{pe->x, pe->y}}));
297
+ plans[bestI] = {2, fld.get(), pe->x, pe->y};
298
+ owned.push_back(move(fld));
299
+ assigned[bestI] = 1;
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ // 3. fetch flags — race-aware, consider round-trip
306
+ {
307
+ struct Cand { int i, j, cost; };
308
+ vector<Cand> cands;
309
+ for (int i = 0; i < n; i++) {
310
+ if (assigned[i]) continue;
311
+ for (int j = 0; j < (int)freeFlags.size(); j++) {
312
+ int fid = freeFlagId[j];
313
+ int myd = distTo(flagFields[fid], mine[i].x, mine[i].y);
314
+ int ed = 1 << 28;
315
+ for (auto& e : enemies) ed = min(ed, distTo(flagFields[fid], e.x, e.y));
316
+ // round-trip: pickup distance + return distance to base
317
+ int ret = distTo(BASEDIST, freeFlags[j].first, freeFlags[j].second);
318
+ int cost = myd + ret / 2 + max(0, myd - min(ed, 30)) * 6;
319
+ if (g.flags[fid].status == "dropped") cost -= 4;
320
+ cands.push_back({i, j, cost});
321
+ }
322
+ }
323
+ sort(cands.begin(), cands.end(), [](const Cand& a, const Cand& b) { return a.cost < b.cost; });
324
+ vector<char> flagTaken(freeFlags.size(), 0);
325
+ for (auto& c : cands) {
326
+ if (assigned[c.i] || flagTaken[c.j]) continue;
327
+ int fid = freeFlagId[c.j];
328
+ plans[c.i] = {1, &flagFields[fid], freeFlags[c.j].first, freeFlags[c.j].second};
329
+ assigned[c.i] = 1;
330
+ flagTaken[c.j] = 1;
331
+ }
332
+ for (int i = 0; i < n; i++) {
333
+ if (assigned[i] || freeFlags.empty()) continue;
334
+ int bestJ = 0, bestD = 1 << 28;
335
+ for (int j = 0; j < (int)freeFlags.size(); j++) {
336
+ int dd = distTo(flagFields[freeFlagId[j]], mine[i].x, mine[i].y);
337
+ if (dd < bestD) { bestD = dd; bestJ = j; }
338
+ }
339
+ plans[i] = {1, &flagFields[freeFlagId[bestJ]], freeFlags[bestJ].first, freeFlags[bestJ].second};
340
+ assigned[i] = 1;
341
+ }
342
+ }
343
+
344
+ // 4. escort / spot
345
+ for (int i = 0; i < n; i++) {
346
+ if (assigned[i]) continue;
347
+ int bestJ = -1, bestD = 1 << 28;
348
+ for (int j = 0; j < n; j++) {
349
+ if (mine[j].flag < 0) continue;
350
+ int dd = manh(mine[i].x, mine[i].y, mine[j].x, mine[j].y);
351
+ if (dd < bestD) { bestD = dd; bestJ = j; }
352
+ }
353
+ if (bestJ >= 0 && bestD <= 16) {
354
+ auto fld = make_unique<vector<vector<int>>>(bfsMulti({{mine[bestJ].x, mine[bestJ].y}}));
355
+ plans[i] = {4, fld.get(), mine[bestJ].x, mine[bestJ].y};
356
+ owned.push_back(move(fld));
357
+ } else {
358
+ // no carrier to escort: go to nearest flag spot (or center for flexibility)
359
+ int bi = -1, bd = 1 << 28;
360
+ // prefer a free flag spot (flag will spawn there eventually)
361
+ for (int s = 0; s < (int)SPOTS.size(); s++) {
362
+ int dd = distTo(SPOTDIST[s], mine[i].x, mine[i].y);
363
+ int ret = distTo(BASEDIST, SPOTS[s].first, SPOTS[s].second);
364
+ int total = dd + ret / 3;
365
+ if (total < bd) { bd = total; bi = s; }
366
+ }
367
+ if (bi >= 0) {
368
+ plans[i] = {3, &SPOTDIST[bi], SPOTS[bi].first, SPOTS[bi].second};
369
+ } else {
370
+ int cc = SZ / 2;
371
+ auto fld = make_unique<vector<vector<int>>>(bfsMulti({{cc, cc}}));
372
+ plans[i] = {3, fld.get(), cc, cc};
373
+ owned.push_back(move(fld));
374
+ }
375
+ }
376
+ assigned[i] = 1;
377
+ }
378
+
379
+ // --- decide movement ---
380
+ vector<pair<int,int>> myPos(n);
381
+ for (int i = 0; i < n; i++) myPos[i] = {mine[i].x, mine[i].y};
382
+
383
+ vector<pair<int,int>> desired(n);
384
+ for (int i = 0; i < n; i++)
385
+ desired[i] = bestStep(*plans[i].fld, mine[i].x, mine[i].y);
386
+
387
+ // stay on a free flag to pick up
388
+ for (int i = 0; i < n; i++) {
389
+ if (mine[i].flag >= 0) continue;
390
+ for (auto& [fx, fy] : freeFlags) {
391
+ if (fx == mine[i].x && fy == mine[i].y) {
392
+ desired[i] = {mine[i].x, mine[i].y};
393
+ break;
394
+ }
395
+ }
396
+ }
397
+
398
+ auto prio = [&](int i) {
399
+ switch (plans[i].kind) {
400
+ case 0: return 5;
401
+ case 1: return 4;
402
+ case 2: return 3;
403
+ case 4: return 2;
404
+ default: return 1;
405
+ }
406
+ };
407
+ for (int i = 0; i < n; i++) {
408
+ for (int j = i + 1; j < n; j++) {
409
+ if (desired[i] == desired[j]) {
410
+ int loser = (prio(i) >= prio(j)) ? j : i;
411
+ int winner = (loser == i) ? j : i;
412
+ auto alt = myPos[loser];
413
+ int bestD = 1 << 28;
414
+ for (int k = 0; k < 5; k++) {
415
+ int nx = myPos[loser].first + MX[k], ny = myPos[loser].second + MY[k];
416
+ if (isWall(nx, ny)) continue;
417
+ if (make_pair(nx, ny) == desired[winner]) continue;
418
+ int d = distTo(*plans[loser].fld, nx, ny);
419
+ if (d < bestD) { bestD = d; alt = {nx, ny}; }
420
+ }
421
+ desired[loser] = alt;
422
+ }
423
+ }
424
+ }
425
+ for (int i = 0; i < n; i++) {
426
+ if (isWall(desired[i].first, desired[i].second)) desired[i] = myPos[i];
427
+ for (auto& e : enemies) {
428
+ if (desired[i].first == e.x && desired[i].second == e.y) {
429
+ desired[i] = myPos[i];
430
+ break;
431
+ }
432
+ }
433
+ }
434
+ for (int i = 0; i < n; i++)
435
+ for (int j = i + 1; j < n; j++)
436
+ if (desired[i] == desired[j]) {
437
+ if (prio(i) >= prio(j)) desired[j] = myPos[j];
438
+ else desired[i] = myPos[i];
439
+ }
440
+
441
+ auto moveTo = [&](int i) -> char {
442
+ auto [x, y] = myPos[i];
443
+ auto [tx, ty] = desired[i];
444
+ if (tx == x && ty == y) return 'S';
445
+ if (tx == x && ty == y - 1) return 'U';
446
+ if (tx == x && ty == y + 1) return 'D';
447
+ if (tx == x - 1 && ty == y) return 'L';
448
+ if (tx == x + 1 && ty == y) return 'R';
449
+ return 'S';
450
+ };
451
+
452
+ // --- actions ---
453
+ vector<string> actions(n, "-");
454
+
455
+ // pickups
456
+ for (int i = 0; i < n; i++) {
457
+ if (mine[i].flag >= 0) continue;
458
+ for (auto& [fx, fy] : freeFlags) {
459
+ if (fx == desired[i].first && fy == desired[i].second) {
460
+ actions[i] = "P";
461
+ break;
462
+ }
463
+ }
464
+ }
465
+
466
+ // attacks: aggressive focus fire
467
+ {
468
+ struct Att { int i, ei; };
469
+ vector<Att> atts;
470
+ for (int i = 0; i < n; i++) {
471
+ if (mine[i].flag >= 0 || mine[i].spawning) continue;
472
+ if (actions[i] == "P") continue;
473
+ auto [ax, ay] = desired[i];
474
+ for (int ei = 0; ei < (int)enemies.size(); ei++) {
475
+ bool hit = canAttack(ax, ay, enemyPos[ei].first, enemyPos[ei].second) ||
476
+ canAttack(ax, ay, enemies[ei].x, enemies[ei].y);
477
+ if (hit) atts.push_back({i, ei});
478
+ }
479
+ }
480
+ if (!atts.empty()) {
481
+ int bestTarget = -1, bestVal = 0;
482
+ for (int ei = 0; ei < (int)enemies.size(); ei++) {
483
+ int cnt = 0;
484
+ for (auto& a : atts) if (a.ei == ei) cnt++;
485
+ if (cnt == 0) continue;
486
+ int dmg = cnt * 34;
487
+ int v = dmg * 3;
488
+ if (dmg >= enemies[ei].hp) v += 800;
489
+ if (enemies[ei].flag >= 0) v += 500;
490
+ // extra value for enemies threatening my carrier
491
+ for (int i = 0; i < n; i++) {
492
+ if (mine[i].flag < 0) continue;
493
+ if (manh(enemies[ei].x, enemies[ei].y, mine[i].x, mine[i].y) <= 4) {
494
+ v += 400;
495
+ break;
496
+ }
497
+ }
498
+ if (v > bestVal) { bestVal = v; bestTarget = ei; }
499
+ }
500
+ if (bestTarget >= 0) {
501
+ for (auto& a : atts) {
502
+ if (a.ei == bestTarget && actions[a.i] == "-") {
503
+ actions[a.i] = to_string(enemies[bestTarget].uid);
504
+ }
505
+ }
506
+ }
507
+ }
508
+ }
509
+
510
+ // --- format output ---
511
+ string out = to_string(g.turn);
512
+ for (int k = 0; k < 3; k++) {
513
+ int uid = 3 * ME + k;
514
+ int idx = -1;
515
+ for (int i = 0; i < n; i++) if (mine[i].uid == uid) { idx = i; break; }
516
+ if (idx < 0) { out += " S -"; continue; }
517
+ out += " ";
518
+ out += moveTo(idx);
519
+ out += " ";
520
+ out += actions[idx];
521
+ }
522
+ return out;
523
+ }
524
+
525
+ int main() {
526
+ ios::sync_with_stdio(false);
527
+ cin.tie(nullptr);
528
+ Game g;
529
+ while (read_turn(g)) {
530
+ cout << decide(g) << endl;
531
+ }
532
+ return 0;
533
+ }