dsh-eval-guard 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +91 -13
  2. package/assets/bomberman/workspace.zip +0 -0
  3. package/assets/commit0/instance.json +30 -0
  4. package/assets/commit0/workspace.zip +0 -0
  5. package/assets/ctf/workspace.zip +0 -0
  6. package/assets/featurebench/hidden/test_regression.py +690 -0
  7. package/assets/featurebench/instance.json +16 -0
  8. package/assets/featurebench/workspace.zip +0 -0
  9. package/assets/swe-bench-pro/hidden/test.patch +36 -0
  10. package/assets/swe-bench-pro/instance.json +10 -0
  11. package/assets/swe-bench-pro/workspace.zip +0 -0
  12. package/assets/tank/workspace.zip +0 -0
  13. package/eval/README.md +18 -0
  14. package/eval/arena/arena/README.md +21 -0
  15. package/eval/arena/arena/bt.py +104 -0
  16. package/eval/arena/arena/clock.py +15 -0
  17. package/eval/arena/arena/core.py +265 -0
  18. package/eval/arena/arena/run.cmd +24 -0
  19. package/eval/arena/arena/run.sh +11 -0
  20. package/eval/arena/arena/schedule.py +79 -0
  21. package/eval/arena/arena/tournament.py +183 -0
  22. package/eval/arena/bomberman/bots/README.md +16 -0
  23. package/eval/arena/bomberman/bots/deepseek-v4.1-flash.cpp +447 -0
  24. package/eval/arena/bomberman/bots/doubao-seed-2.1.cpp +542 -0
  25. package/eval/arena/bomberman/bots/glm-5.3.cpp +406 -0
  26. package/eval/arena/bomberman/bots/gpt-6-astra.cpp +768 -0
  27. package/eval/arena/bomberman/bots/gpt-6-sol.cpp +444 -0
  28. package/eval/arena/bomberman/bots/kimi-k3.cpp +432 -0
  29. package/eval/arena/bomberman/bots/mimo-v2.6-pro.cpp +529 -0
  30. package/eval/arena/bomberman/bots/opus-5.5.cpp +548 -0
  31. package/eval/arena/bomberman/bots/qwen-3.8-max.cpp +836 -0
  32. package/eval/arena/bomberman/tournament/README.md +11 -0
  33. package/eval/arena/bomberman/tournament/bt.py +56 -0
  34. package/eval/arena/bomberman/tournament/evaluate.py +199 -0
  35. package/eval/arena/bomberman/tournament/run.py +79 -0
  36. package/eval/arena/bomberman/tournament/schedule-2to10.json.gz +0 -0
  37. package/eval/arena/bomberman/workspace/MANIFEST.json +13 -0
  38. package/eval/arena/bomberman/workspace/README.md +29 -0
  39. package/eval/arena/bomberman/workspace/RULES.md +100 -0
  40. package/eval/arena/bomberman/workspace/baseline.cpp +240 -0
  41. package/eval/arena/bomberman/workspace/clock.py +25 -0
  42. package/eval/arena/bomberman/workspace/engine/arena.py +198 -0
  43. package/eval/arena/bomberman/workspace/engine/build.py +35 -0
  44. package/eval/arena/bomberman/workspace/engine/engine.py +256 -0
  45. package/eval/arena/bomberman/workspace/engine/verify_replay.py +24 -0
  46. package/eval/arena/bomberman/workspace/run.cmd +28 -0
  47. package/eval/arena/bomberman/workspace/run.sh +16 -0
  48. package/eval/arena/bomberman/workspace/viewer/index.html +42 -0
  49. package/eval/arena/ctf/bots/README.md +18 -0
  50. package/eval/arena/ctf/bots/deepseek-v4.1-flash.cpp +601 -0
  51. package/eval/arena/ctf/bots/doubao-seed-2.1-turbo.cpp +320 -0
  52. package/eval/arena/ctf/bots/fable-5.1.cpp +634 -0
  53. package/eval/arena/ctf/bots/glm-5.3.cpp +689 -0
  54. package/eval/arena/ctf/bots/gpt-6-astra.cpp +657 -0
  55. package/eval/arena/ctf/bots/gpt-6.1-sol.cpp +725 -0
  56. package/eval/arena/ctf/bots/kimi-k3.cpp +667 -0
  57. package/eval/arena/ctf/bots/mimo-v2.6-pro.cpp +533 -0
  58. package/eval/arena/ctf/bots/opus-5.5.cpp +645 -0
  59. package/eval/arena/ctf/bots/qwen-3.8-max.cpp +726 -0
  60. package/eval/arena/ctf/bots/sonnet-5.5.cpp +569 -0
  61. package/eval/arena/ctf/tournament/README.md +15 -0
  62. package/eval/arena/ctf/tournament/formal-2to8.json +31 -0
  63. package/eval/arena/ctf/tournament/formal-9to15.json +31 -0
  64. package/eval/arena/ctf/workspace/README.md +41 -0
  65. package/eval/arena/ctf/workspace/RULES.md +119 -0
  66. package/eval/arena/ctf/workspace/arena.py +186 -0
  67. package/eval/arena/ctf/workspace/baseline.cpp +257 -0
  68. package/eval/arena/ctf/workspace/clock.py +15 -0
  69. package/eval/arena/ctf/workspace/core.py +265 -0
  70. package/eval/arena/ctf/workspace/engine.py +389 -0
  71. package/eval/arena/ctf/workspace/run.cmd +24 -0
  72. package/eval/arena/ctf/workspace/run.sh +11 -0
  73. package/eval/arena/ctf/workspace/viewer.html +71 -0
  74. package/eval/arena/land/bots/README.md +17 -0
  75. package/eval/arena/land/bots/deepseek-4.1f@workbuddy#1/bot.cpp +608 -0
  76. package/eval/arena/land/bots/glm-5.3@workbuddy#1/bot.cpp +521 -0
  77. package/eval/arena/land/bots/gpt-6-astra@codex#1/bot.cpp +373 -0
  78. package/eval/arena/land/bots/gpt-6-sol@codex#1/bot.cpp +341 -0
  79. package/eval/arena/land/bots/kimi-k3@workbuddy#1/bot.cpp +492 -0
  80. package/eval/arena/land/bots/mimo-2.6-pro@zcode#1/bot.cpp +652 -0
  81. package/eval/arena/land/bots/mystery-model@zcode#1/bot.cpp +466 -0
  82. package/eval/arena/land/bots/opus-5.5@claude-code#1/bot.cpp +630 -0
  83. package/eval/arena/land/bots/sonnet-5@claude-code#1/bot.cpp +619 -0
  84. package/eval/arena/land/tournament/make_replay_page.py +17 -0
  85. package/eval/arena/land/tournament/rate.py +290 -0
  86. package/eval/arena/land/tournament/round_robin.py +172 -0
  87. package/eval/arena/land/tournament/sparring.cpp +356 -0
  88. package/eval/arena/land/workspace/RULES.md +114 -0
  89. package/eval/arena/land/workspace/TASK.md +46 -0
  90. package/eval/arena/land/workspace/anchors/.build/greedy_f2e6d2dea5ca +0 -0
  91. package/eval/arena/land/workspace/anchors/greedy.cpp +194 -0
  92. package/eval/arena/land/workspace/anchors/random.cpp +80 -0
  93. package/eval/arena/land/workspace/clock.py +64 -0
  94. package/eval/arena/land/workspace/engine/build.py +33 -0
  95. package/eval/arena/land/workspace/engine/game.py +273 -0
  96. package/eval/arena/land/workspace/engine/referee.py +308 -0
  97. package/eval/arena/land/workspace/starter/.build/bot_be32b45b4699 +0 -0
  98. package/eval/arena/land/workspace/starter/bot.cpp +82 -0
  99. package/eval/arena/land/workspace/viewer/viewer.html +210 -0
  100. package/eval/arena/tank/bots/README.md +24 -0
  101. package/eval/arena/tank/bots/half1/deepseek-v4.1-flash.cpp +367 -0
  102. package/eval/arena/tank/bots/half1/doubao-seed-evolving.cpp +402 -0
  103. package/eval/arena/tank/bots/half1/gemini-4-argon.cpp +1132 -0
  104. package/eval/arena/tank/bots/half1/glm-5.3.cpp +551 -0
  105. package/eval/arena/tank/bots/half1/gpt-6-astra.cpp +233 -0
  106. package/eval/arena/tank/bots/half1/gpt-6.1-sol-ultrafast.cpp +350 -0
  107. package/eval/arena/tank/bots/half1/gpt-6.1-sol.cpp +78 -0
  108. package/eval/arena/tank/bots/half1/grok-4.7.cpp +1099 -0
  109. package/eval/arena/tank/bots/half1/haiku-5.5.cpp +210 -0
  110. package/eval/arena/tank/bots/half1/kimi-k3.cpp +353 -0
  111. package/eval/arena/tank/bots/half1/mimo-v2.6-pro.cpp +336 -0
  112. package/eval/arena/tank/bots/half1/muse-wonder-full.cpp +560 -0
  113. package/eval/arena/tank/bots/half1/opus-5.5.cpp +435 -0
  114. package/eval/arena/tank/bots/half1/qwen-3.8-max.cpp +537 -0
  115. package/eval/arena/tank/bots/half2/deepseek-v4.1-flash.cpp +425 -0
  116. package/eval/arena/tank/bots/half2/doubao-seed-evolving.cpp +308 -0
  117. package/eval/arena/tank/bots/half2/gemini-4-argon.cpp +1390 -0
  118. package/eval/arena/tank/bots/half2/glm-5.3.cpp +651 -0
  119. package/eval/arena/tank/bots/half2/gpt-6-astra.cpp +241 -0
  120. package/eval/arena/tank/bots/half2/gpt-6.1-sol-ultrafast.cpp +356 -0
  121. package/eval/arena/tank/bots/half2/gpt-6.1-sol.cpp +87 -0
  122. package/eval/arena/tank/bots/half2/grok-4.7.cpp +1205 -0
  123. package/eval/arena/tank/bots/half2/haiku-5.5.cpp +210 -0
  124. package/eval/arena/tank/bots/half2/kimi-k3.cpp +487 -0
  125. package/eval/arena/tank/bots/half2/mimo-v2.6-pro.cpp +336 -0
  126. package/eval/arena/tank/bots/half2/muse-wonder-full.cpp +560 -0
  127. package/eval/arena/tank/bots/half2/opus-5.5.cpp +476 -0
  128. package/eval/arena/tank/bots/half2/qwen-3.8-max.cpp +392 -0
  129. package/eval/arena/tank/tournament/README.md +24 -0
  130. package/eval/arena/tank/tournament/bt.py +218 -0
  131. package/eval/arena/tank/tournament/final.json +202 -0
  132. package/eval/arena/tank/tournament/halftime.json +146 -0
  133. package/eval/arena/tank/tournament/progress.json +911 -0
  134. package/eval/arena/tank/tournament/schedule.py +100 -0
  135. package/eval/arena/tank/tournament/sparring.cpp +928 -0
  136. package/eval/arena/tank/tournament/tournament.py +1426 -0
  137. package/eval/arena/tank/workspace/README.md +169 -0
  138. package/eval/arena/tank/workspace/RULES.md +443 -0
  139. package/eval/arena/tank/workspace/arena.py +862 -0
  140. package/eval/arena/tank/workspace/baseline.cpp +259 -0
  141. package/eval/arena/tank/workspace/clock.py +103 -0
  142. package/eval/arena/tank/workspace/core.py +712 -0
  143. package/eval/arena/tank/workspace/engine.py +573 -0
  144. package/eval/arena/tank/workspace/history/.lock +0 -0
  145. package/eval/arena/tank/workspace/history/20261017-193610-08715287f91f-bot.cpp +109 -0
  146. package/eval/arena/tank/workspace/history/20261017-193619-f00b2d5635fa-gpt-6-astra.cpp +241 -0
  147. package/eval/arena/tank/workspace/history/20261017-193643-63319e0a2b1a-gpt-6_1-sol-ultrafast.cpp +356 -0
  148. package/eval/arena/tank/workspace/history/20261017-193647-41c1341d0a8a-gemini-4-argon.cpp +1390 -0
  149. package/eval/arena/tank/workspace/history/20261017-193652-e34c0f45539a-gpt-6_1-sol.cpp +87 -0
  150. package/eval/arena/tank/workspace/history/20261017-193654-c026348ce96e-opus-5_5.cpp +476 -0
  151. package/eval/arena/tank/workspace/history/20261017-193655-4a21366e94d1-muse-wonder-full.cpp +560 -0
  152. package/eval/arena/tank/workspace/history/20261017-193657-dbc4e9969c52-mimo-v2_6-pro.cpp +336 -0
  153. package/eval/arena/tank/workspace/history/20261017-193703-723cd036eb31-grok-4_7.cpp +1205 -0
  154. package/eval/arena/tank/workspace/history/20261017-193707-1ebbb227be68-deepseek-v4_1-flash.cpp +425 -0
  155. package/eval/arena/tank/workspace/history/20261017-193709-aeb0e7202ad5-doubao-seed-evolving.cpp +308 -0
  156. package/eval/arena/tank/workspace/history/20261017-193710-b21ebeb9bc76-kimi-k3.cpp +487 -0
  157. package/eval/arena/tank/workspace/history/20261017-193712-54cd86531905-haiku-5_5.cpp +210 -0
  158. package/eval/arena/tank/workspace/history/20261017-193714-efdb8e35c0bf-qwen-3_8-max.cpp +392 -0
  159. package/eval/arena/tank/workspace/history/20261017-193715-681423c23fdb-glm-5_3.cpp +651 -0
  160. package/eval/arena/tank/workspace/history/20261017-193717-1a8b3c75181d-sparring.cpp +928 -0
  161. package/eval/arena/tank/workspace/history/20261017-193720-1e0803a541e8-baseline.cpp +259 -0
  162. package/eval/arena/tank/workspace/history/log.jsonl +103 -0
  163. package/eval/arena/tank/workspace/judge/cycles.hpp +53 -0
  164. package/eval/arena/tank/workspace/judge/fast.cpp +337 -0
  165. package/eval/arena/tank/workspace/judge/referee.cpp +125 -0
  166. package/eval/arena/tank/workspace/judge/speed.cpp +99 -0
  167. package/eval/arena/tank/workspace/run.cmd +31 -0
  168. package/eval/arena/tank/workspace/run.sh +23 -0
  169. package/eval/arena/tank/workspace/tank.hpp +1762 -0
  170. package/eval/arena/tank/workspace/tank_main.cpp +215 -0
  171. package/eval/arena/tank/workspace/viewer.html +1150 -0
  172. package/eval/arena/warehouse/workspace/SPEC.md +130 -0
  173. package/eval/arena/warehouse/workspace/TASK.md +71 -0
  174. package/eval/arena/warehouse/workspace/baseline/common.h +88 -0
  175. package/eval/arena/warehouse/workspace/baseline/main.cpp +27 -0
  176. package/eval/arena/warehouse/workspace/baseline/old_stuff.cpp +87 -0
  177. package/eval/arena/warehouse/workspace/baseline/sim.cpp +427 -0
  178. package/eval/arena/warehouse/workspace/baseline/util.cpp +220 -0
  179. package/eval/arena/warehouse/workspace/clock.py +42 -0
  180. package/eval/arena/warehouse/workspace/src/common.h +88 -0
  181. package/eval/arena/warehouse/workspace/src/main.cpp +27 -0
  182. package/eval/arena/warehouse/workspace/src/old_stuff.cpp +87 -0
  183. package/eval/arena/warehouse/workspace/src/sim.cpp +427 -0
  184. package/eval/arena/warehouse/workspace/src/util.cpp +220 -0
  185. package/eval/arena/warehouse/workspace/tools/bench.py +119 -0
  186. package/eval/arena/warehouse/workspace/tools/check_input.py +161 -0
  187. package/eval/arena/warehouse/workspace/tools/gen.py +132 -0
  188. package/eval/arena/warehouse/workspace/tools/measure.py +107 -0
  189. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.in +1420 -0
  190. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.out +9162 -0
  191. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.in +1465 -0
  192. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.out +3439 -0
  193. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.in +2757 -0
  194. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.out +3126 -0
  195. package/eval/arena/warehouse/workspace/workloads/public/pub_small.in +731 -0
  196. package/eval/arena/warehouse/workspace/workloads/public/pub_small.out +2578 -0
  197. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.in +528 -0
  198. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.out +2026 -0
  199. package/eval/bomberman.py +20 -0
  200. package/eval/commit0.py +21 -0
  201. package/eval/common.py +61 -0
  202. package/eval/ctf.py +20 -0
  203. package/eval/featurebench.py +25 -0
  204. package/eval/land.py +20 -0
  205. package/eval/legacy/bomberman-prices.json +4 -0
  206. package/eval/legacy/bomberman.py +161 -0
  207. package/eval/legacy/commit0.py +91 -0
  208. package/eval/legacy/ctf-prices.json +4 -0
  209. package/eval/legacy/ctf.py +178 -0
  210. package/eval/legacy/featurebench.py +103 -0
  211. package/eval/legacy/land-prices.json +4 -0
  212. package/eval/legacy/land.py +177 -0
  213. package/eval/legacy/swe_bench_pro.py +116 -0
  214. package/eval/legacy/tank-prices.json +3 -0
  215. package/eval/legacy/tank.py +408 -0
  216. package/eval/legacy/warehouse-prices.json +4 -0
  217. package/eval/legacy/warehouse.py +365 -0
  218. package/eval/swe-bench-pro.py +25 -0
  219. package/eval/tank.py +20 -0
  220. package/eval/warehouse.py +20 -0
  221. package/lib/client/index.js +376 -63
  222. package/lib/client/index.js.map +1 -1
  223. package/lib/index.js +684 -27
  224. package/package.json +2 -1
@@ -0,0 +1,406 @@
1
+ // Bomberman bot: survival-first with exact forward simulation of explosions.
2
+ // Public state only; deterministic decision each turn within the 50ms budget.
3
+ #include <algorithm>
4
+ #include <array>
5
+ #include <cmath>
6
+ #include <iostream>
7
+ #include <queue>
8
+ #include <string>
9
+ #include <vector>
10
+ using namespace std;
11
+
12
+ const string DS = "UDLRS";
13
+ const int DX[] = {0, 0, -1, 1, 0}, DY[] = {-1, 1, 0, 0, 0};
14
+ int N, P, ME, T, LIMIT, FUSE, RANGE, CAP, FIRE, SHRINK, EVERY;
15
+
16
+ struct Player { int x, y, alive; };
17
+ struct Bomb { int owner, x, y, at; };
18
+ struct Flame { int x, y, end; };
19
+ vector<string> board;
20
+ vector<Player> players;
21
+ vector<Bomb> bombs;
22
+ vector<Flame> flames;
23
+
24
+ int cell(int x, int y) { return y * N + x; }
25
+ bool inside(int x, int y) { return x >= 0 && y >= 0 && x < N && y < N; }
26
+
27
+ // ---- exact forward prediction of explosions / flames / shrink ----
28
+ struct Pred {
29
+ vector<vector<unsigned char>> safe, open, occ;
30
+ };
31
+
32
+ Pred predict(vector<Bomb> bs, int horizon) {
33
+ Pred out;
34
+ out.safe = out.open = out.occ = vector(horizon, vector<unsigned char>(N * N));
35
+ auto grid = board;
36
+ vector<int> expires(N * N, -1);
37
+ for (auto &f : flames) expires[cell(f.x, f.y)] = f.end;
38
+ for (int k = 0; k < horizon; k++) {
39
+ int now = T + k;
40
+ int layer = now < SHRINK ? 0 : 1 + (now - SHRINK) / EVERY;
41
+ for (int y = 0; y < N; y++)
42
+ for (int x = 0; x < N; x++)
43
+ if (min({x, y, N - 1 - x, N - 1 - y}) <= layer) {
44
+ grid[y][x] = '#';
45
+ expires[cell(x, y)] = -1;
46
+ }
47
+ bs.erase(remove_if(bs.begin(), bs.end(),
48
+ [&](Bomb b) { return grid[b.y][b.x] == '#'; }),
49
+ bs.end());
50
+ vector<int> at(N * N, -1);
51
+ for (int i = 0; i < (int)bs.size(); i++) {
52
+ at[cell(bs[i].x, bs[i].y)] = i;
53
+ out.occ[k][cell(bs[i].x, bs[i].y)] = 1;
54
+ }
55
+ for (int y = 0; y < N; y++)
56
+ for (int x = 0; x < N; x++) out.open[k][cell(x, y)] = grid[y][x] == '.';
57
+ queue<int> q;
58
+ vector<unsigned char> gone(bs.size()), hit(N * N);
59
+ for (int i = 0; i < (int)bs.size(); i++)
60
+ if (bs[i].at <= now || expires[cell(bs[i].x, bs[i].y)] >= now) q.push(i);
61
+ while (!q.empty()) {
62
+ int i = q.front(); q.pop();
63
+ if (gone[i]) continue;
64
+ gone[i] = true;
65
+ auto b = bs[i];
66
+ hit[cell(b.x, b.y)] = 1;
67
+ for (int d = 0; d < 4; d++)
68
+ for (int r = 1; r <= RANGE; r++) {
69
+ int x = b.x + DX[d] * r, y = b.y + DY[d] * r;
70
+ if (!inside(x, y) || grid[y][x] == '#') break;
71
+ int c = cell(x, y);
72
+ hit[c] = 1;
73
+ if (grid[y][x] == '+') break;
74
+ if (at[c] >= 0) { q.push(at[c]); break; }
75
+ }
76
+ }
77
+ vector<Bomb> left;
78
+ for (int i = 0; i < (int)bs.size(); i++)
79
+ if (!gone[i]) left.push_back(bs[i]);
80
+ bs = move(left);
81
+ for (int y = 0; y < N; y++)
82
+ for (int x = 0; x < N; x++) {
83
+ int c = cell(x, y);
84
+ if (hit[c]) {
85
+ expires[c] = max(expires[c], now + FIRE - 1);
86
+ if (grid[y][x] == '+') grid[y][x] = '.';
87
+ }
88
+ out.safe[k][c] = grid[y][x] == '.' && expires[c] < now;
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+
94
+ // ---- layered survival BFS: which cells can be occupied alive at end of turn T+k ----
95
+ struct ReachR {
96
+ int horizon = -1; // max k with a nonempty alive layer (>=0 means survive turn T)
97
+ long long breadth = 0; // size of final alive layer
98
+ };
99
+ ReachR reach(const Pred &pr, int startCell) {
100
+ ReachR r;
101
+ vector<unsigned char> cur(N * N), nxt;
102
+ if (startCell >= 0 && pr.safe[0][startCell]) cur[startCell] = 1;
103
+ for (int k = 0; k < (int)pr.safe.size(); k++) {
104
+ if (k > 0) {
105
+ int now = T + k;
106
+ int layer = now < SHRINK ? 0 : 1 + (now - SHRINK) / EVERY;
107
+ nxt.assign(N * N, 0);
108
+ for (int c = 0; c < N * N; c++) {
109
+ if (!cur[c]) continue;
110
+ int x = c % N, y = c / N;
111
+ if (min({x, y, N - 1 - x, N - 1 - y}) <= layer) continue;
112
+ for (int d = 0; d < 5; d++) {
113
+ int nx = x + DX[d], ny = y + DY[d], nc = c;
114
+ if (inside(nx, ny)) {
115
+ int z = cell(nx, ny);
116
+ if (pr.open[k][z] && (!pr.occ[k][z] || z == c)) nc = z;
117
+ }
118
+ if (pr.safe[k][nc]) nxt[nc] = 1;
119
+ }
120
+ }
121
+ cur = move(nxt);
122
+ }
123
+ bool any = false;
124
+ long long b = 0;
125
+ for (int c = 0; c < N * N; c++) if (cur[c]) { any = true; b++; }
126
+ if (!any) break;
127
+ r.horizon = k;
128
+ r.breadth = b;
129
+ }
130
+ return r;
131
+ }
132
+
133
+ int blast_value(int x, int y) {
134
+ int score = 0;
135
+ for (int d = 0; d < 4; d++)
136
+ for (int r = 1; r <= RANGE; r++) {
137
+ int nx = x + DX[d] * r, ny = y + DY[d] * r;
138
+ if (!inside(nx, ny) || board[ny][nx] == '#') break;
139
+ if (board[ny][nx] == '+') { score += 3; break; }
140
+ for (int i = 0; i < P; i++)
141
+ if (i != ME && players[i].alive && players[i].x == nx && players[i].y == ny) score += 5;
142
+ }
143
+ return score;
144
+ }
145
+
146
+ vector<double> potential;
147
+ void make_potential() {
148
+ potential.assign(N * N, -1e6);
149
+ priority_queue<pair<double, int>> q;
150
+ for (int y = 0; y < N; y++)
151
+ for (int x = 0; x < N; x++)
152
+ if (board[y][x] == '.') {
153
+ int edge = min({x, y, N - 1 - x, N - 1 - y});
154
+ double val = 0.8 * blast_value(x, y);
155
+ int until = SHRINK + max(0, edge - 1) * EVERY - T;
156
+ if (until < 14) val -= 30;
157
+ else val += min(4.0, edge * 0.4);
158
+ potential[cell(x, y)] = val;
159
+ q.push({val, cell(x, y)});
160
+ }
161
+ while (!q.empty()) {
162
+ auto [v, c] = q.top(); q.pop();
163
+ if (v < potential[c] - 1e-9) continue;
164
+ int x = c % N, y = c / N;
165
+ for (int d = 0; d < 4; d++) {
166
+ int nx = x + DX[d], ny = y + DY[d];
167
+ if (!inside(nx, ny) || board[ny][nx] != '.') continue;
168
+ int nc = cell(nx, ny);
169
+ if (v - 0.7 > potential[nc]) {
170
+ potential[nc] = v - 0.7;
171
+ q.push({v - 0.7, nc});
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ vector<int> recent;
178
+ double visits(int c) {
179
+ double s = 0;
180
+ for (int k = 0; k < (int)recent.size(); k++)
181
+ if (recent[k] == c) s += 1.0 / (1 + 0.15 * (recent.size() - 1 - k));
182
+ return s;
183
+ }
184
+
185
+ int myBombCount() {
186
+ int n = 0;
187
+ for (auto &b : bombs) n += b.owner == ME;
188
+ return n;
189
+ }
190
+
191
+ pair<int, int> decide() {
192
+ int H = min(12, LIMIT - T);
193
+ auto me = players[ME];
194
+ if (H <= 0) return {4, 0};
195
+ make_potential();
196
+ recent.push_back(cell(me.x, me.y));
197
+ if (recent.size() > 24) recent.erase(recent.begin());
198
+
199
+ Pred base = predict(bombs, H);
200
+
201
+ // eligibility to place at my current cell
202
+ bool bombAtFeet = false;
203
+ for (auto &b : bombs) bombAtFeet |= b.x == me.x && b.y == me.y;
204
+ bool sharedCell = false;
205
+ for (int i = 0; i < P; i++)
206
+ if (i != ME && players[i].alive && players[i].x == me.x && players[i].y == me.y) sharedCell = true;
207
+ bool canPlace = myBombCount() < CAP && !bombAtFeet && !sharedCell;
208
+
209
+ Pred bombScen = base;
210
+ if (canPlace) {
211
+ auto bs = bombs;
212
+ bs.push_back({ME, me.x, me.y, T + FUSE});
213
+ bombScen = predict(bs, H);
214
+ }
215
+
216
+ // hypothetical threat: nearest armed enemy within distance 4 may bomb now,
217
+ // possibly after stepping one cell toward me first
218
+ vector<int> threats;
219
+ int tdist = 1000;
220
+ int threatRadius = P >= 6 ? 5 : 4;
221
+ for (int i = 0; i < P; i++) {
222
+ if (i == ME || !players[i].alive) continue;
223
+ auto &e = players[i];
224
+ int cnt = 0;
225
+ for (auto &b : bombs) cnt += b.owner == i;
226
+ bool foot = false;
227
+ for (auto &b : bombs) foot |= b.x == e.x && b.y == e.y;
228
+ if (cnt >= CAP || foot) continue;
229
+ int dd = abs(e.x - me.x) + abs(e.y - me.y);
230
+ if (dd <= threatRadius && dd < tdist) { tdist = dd; threats = {i}; }
231
+ }
232
+ Pred threatScen = base, bombThreatScen = bombScen;
233
+ if (!threats.empty()) {
234
+ auto bs = bombs;
235
+ for (int i : threats) {
236
+ auto &e = players[i];
237
+ bs.push_back({i, e.x, e.y, T + FUSE});
238
+ // one step toward me: seals pocket entrances (enemy capacity is 2)
239
+ if (tdist > 1) {
240
+ int sx = e.x, sy = e.y;
241
+ for (int d = 0; d < 4; d++) {
242
+ int nx = e.x + DX[d], ny = e.y + DY[d];
243
+ if (!inside(nx, ny) || board[ny][nx] != '.') continue;
244
+ if (abs(nx - me.x) + abs(ny - me.y) < abs(sx - me.x) + abs(sy - me.y)) { sx = nx; sy = ny; }
245
+ }
246
+ if (sx != e.x || sy != e.y) bs.push_back({i, sx, sy, T + FUSE});
247
+ }
248
+ }
249
+ threatScen = predict(bs, H);
250
+ if (canPlace) {
251
+ bs.push_back({ME, me.x, me.y, T + FUSE});
252
+ bombThreatScen = predict(bs, H);
253
+ }
254
+ }
255
+
256
+ // enemy escape metrics for denial scoring
257
+ int aliveEnemies = 0;
258
+ for (int i = 0; i < P; i++) aliveEnemies += i != ME && players[i].alive;
259
+ vector<ReachR> enemyBase(P), enemyBomb(P);
260
+ if (canPlace && aliveEnemies) {
261
+ for (int i = 0; i < P; i++) {
262
+ if (i == ME || !players[i].alive) continue;
263
+ enemyBase[i] = reach(base, cell(players[i].x, players[i].y));
264
+ enemyBomb[i] = reach(bombScen, cell(players[i].x, players[i].y));
265
+ }
266
+ }
267
+
268
+ int myPos = cell(me.x, me.y);
269
+ pair<int, int> answer = {4, 0};
270
+ double best = -1e30;
271
+ for (int place = 0; place <= 1; place++) {
272
+ if (place && !canPlace) continue;
273
+ const Pred &scen = place ? bombScen : base;
274
+ const Pred &caut = place ? bombThreatScen : threatScen;
275
+ double placeKill = 0, placeOther = 0; // kill credit counts even in mutual destruction
276
+ if (place) {
277
+ placeOther = 0.7 * blast_value(me.x, me.y) - 2.0;
278
+ for (int i = 0; i < P; i++) {
279
+ if (i == ME || !players[i].alive) continue;
280
+ if (enemyBomb[i].horizon < H - 1 && enemyBase[i].horizon >= H - 1) placeKill += 100; // guaranteed kill
281
+ else if (enemyBase[i].breadth > 0)
282
+ placeOther += 10 * max(0.0, 1.0 - (double)enemyBomb[i].breadth / enemyBase[i].breadth);
283
+ }
284
+ }
285
+ for (int d = 0; d < 5; d++) {
286
+ int tx = me.x + DX[d], ty = me.y + DY[d];
287
+ bool terrainOK = false;
288
+ int target = myPos;
289
+ if (inside(tx, ty)) {
290
+ int tc = cell(tx, ty);
291
+ if (scen.open[0][tc] && (!scen.occ[0][tc] || tc == myPos)) { terrainOK = true; target = tc; }
292
+ }
293
+ // conservative outcomes: contested cells may leave me stuck at origin
294
+ vector<int> outcomes;
295
+ outcomes.push_back(terrainOK ? target : myPos);
296
+ if (terrainOK && target != myPos) {
297
+ bool contested = false;
298
+ for (int i = 0; i < P; i++) {
299
+ if (i == ME || !players[i].alive) continue;
300
+ auto &e = players[i];
301
+ if (abs(e.x - tx) + abs(e.y - ty) <= 1) contested = true;
302
+ }
303
+ if (contested) outcomes.push_back(myPos);
304
+ }
305
+
306
+ // branches: intended move (weight ~0.75) vs blocked-in-place if contested
307
+ auto safetyScore = [&](const ReachR &w, const ReachR &c) {
308
+ if (w.horizon < 0) return -1e6; // dead this turn regardless
309
+ double s = 400.0 * w.horizon;
310
+ if (w.horizon >= H - 1) s += 30 + 3.0 * log(1.0 + w.breadth);
311
+ else s -= 250.0 * (H - 1 - w.horizon);
312
+ // hypothetical enemy bombs near me: penalize relative danger
313
+ if (!threats.empty()) {
314
+ if (c.horizon < H - 1) s -= 280.0 + 40.0 * (H - 1 - max(c.horizon, -1));
315
+ else s += 1.5 * log(1.0 + c.breadth);
316
+ }
317
+ return s;
318
+ };
319
+ ReachR succW = reach(scen, outcomes[0]);
320
+ ReachR succC = threats.empty() ? succW : reach(caut, outcomes[0]);
321
+ double pBlock = 0.0;
322
+ ReachR blockW = succW, blockC = succC;
323
+ if ((int)outcomes.size() > 1) {
324
+ pBlock = 0.25;
325
+ blockW = reach(scen, outcomes[1]);
326
+ blockC = threats.empty() ? blockW : reach(caut, outcomes[1]);
327
+ }
328
+ double score = (1.0 - pBlock) * safetyScore(succW, succC)
329
+ + pBlock * safetyScore(blockW, blockC);
330
+ {
331
+ // positional value
332
+ int pref = outcomes[0];
333
+ score += 0.55 * max(-40.0, potential[pref]);
334
+ score -= 1.4 * visits(pref);
335
+ if (d == 4) score -= 0.5;
336
+ // proximity to armed enemies is dangerous
337
+ for (int i = 0; i < P; i++) {
338
+ if (i == ME || !players[i].alive) continue;
339
+ int dd = abs(players[i].x - me.x) + abs(players[i].y - me.y);
340
+ int cnt = 0;
341
+ for (auto &b : bombs) cnt += b.owner == i;
342
+ if (dd <= 2 && cnt < CAP) score -= 4.0 * (3 - dd);
343
+ }
344
+ // crowd avoidance in multiplayer: penalize cells near armed enemies
345
+ if (aliveEnemies >= 2) {
346
+ int dens = 0;
347
+ for (int i = 0; i < P; i++) {
348
+ if (i == ME || !players[i].alive) continue;
349
+ int cnt = 0;
350
+ for (auto &b : bombs) cnt += b.owner == i;
351
+ if (cnt >= CAP) continue;
352
+ int dd = abs(players[i].x - tx) + abs(players[i].y - ty);
353
+ if (terrainOK && dd <= 3) dens += 4 - dd;
354
+ }
355
+ score -= 0.8 * dens;
356
+ }
357
+ if (aliveEnemies == 1 && myBombCount() < CAP) {
358
+ int ei = -1;
359
+ for (int i = 0; i < P; i++) if (i != ME && players[i].alive) ei = i;
360
+ if (ei >= 0) {
361
+ int dd = abs(players[ei].x - tx) + abs(players[ei].y - ty);
362
+ if (terrainOK) score += max(0.0, 5.0 - 1.1 * abs(dd - 3));
363
+ }
364
+ }
365
+ score += placeKill + placeOther;
366
+ }
367
+ score -= 0.003 * ((d + T) % 5);
368
+ #ifdef DEBUG
369
+ fprintf(stderr, "act %s place=%d h=%d hc=%d score=%.1f pk=%.2f po=%.2f\n",
370
+ DS.substr(d,1).c_str(), place, succW.horizon, succC.horizon, score, placeKill, placeOther);
371
+ #endif
372
+ if (score > best) { best = score; answer = {d, place}; }
373
+ }
374
+ }
375
+ return answer;
376
+ }
377
+
378
+ bool read() {
379
+ string w;
380
+ if (!(cin >> w >> T)) return false;
381
+ while (cin >> w) {
382
+ if (w == "END") return true;
383
+ if (w == "BOARD") { for (auto &row : board) cin >> row; }
384
+ else if (w == "P") { int id, x, y, a; cin >> id >> x >> y >> a; players[id] = {x, y, a}; }
385
+ else if (w == "BOMBS") { int k; cin >> k; bombs.resize(k); for (auto &b : bombs) { string bw; cin >> bw >> b.owner >> b.x >> b.y >> b.at; } }
386
+ else if (w == "FLAMES") { int f; cin >> f; flames.resize(f); for (auto &fl : flames) { string fw; cin >> fw >> fl.x >> fl.y >> fl.end; } }
387
+ else if (w == "STATUS") { int s; cin >> s; for (int i = 0; i < s; i++) { string sw; int id, dt, nu, de; cin >> sw >> id >> dt >> nu >> de; } }
388
+ else if (w == "SOURCES") { int s; cin >> s; for (int i = 0; i < s; i++) { string sw; int x, y, o, e; cin >> sw >> x >> y >> o >> e; } }
389
+ }
390
+ return false;
391
+ }
392
+
393
+ int main() {
394
+ ios::sync_with_stdio(false);
395
+ cin.tie(nullptr);
396
+ string w;
397
+ if (!(cin >> w >> N >> P >> ME >> LIMIT >> FUSE >> RANGE >> CAP >> FIRE >> SHRINK >> EVERY)) return 0;
398
+ board.resize(N);
399
+ players.resize(P);
400
+ while (read()) {
401
+ auto [d, place] = decide();
402
+ cout << T << ' ' << DS[d] << ' ' << place << '\n';
403
+ cout.flush();
404
+ }
405
+ return 0;
406
+ }