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.
- package/README.md +91 -13
- package/assets/commit0/instance.json +30 -0
- package/assets/commit0/workspace.zip +0 -0
- package/assets/featurebench/hidden/test_regression.py +690 -0
- package/assets/featurebench/instance.json +16 -0
- package/assets/featurebench/workspace.zip +0 -0
- package/assets/swe-bench-pro/hidden/test.patch +36 -0
- package/assets/swe-bench-pro/instance.json +10 -0
- package/assets/swe-bench-pro/workspace.zip +0 -0
- package/eval/README.md +18 -0
- package/eval/arena/arena/README.md +21 -0
- package/eval/arena/arena/bt.py +104 -0
- package/eval/arena/arena/clock.py +15 -0
- package/eval/arena/arena/core.py +265 -0
- package/eval/arena/arena/run.cmd +24 -0
- package/eval/arena/arena/run.sh +11 -0
- package/eval/arena/arena/schedule.py +79 -0
- package/eval/arena/arena/tournament.py +183 -0
- package/eval/arena/bomberman/bots/README.md +16 -0
- package/eval/arena/bomberman/bots/deepseek-v4.1-flash.cpp +447 -0
- package/eval/arena/bomberman/bots/doubao-seed-2.1.cpp +542 -0
- package/eval/arena/bomberman/bots/glm-5.3.cpp +406 -0
- package/eval/arena/bomberman/bots/gpt-6-astra.cpp +768 -0
- package/eval/arena/bomberman/bots/gpt-6-sol.cpp +444 -0
- package/eval/arena/bomberman/bots/kimi-k3.cpp +432 -0
- package/eval/arena/bomberman/bots/mimo-v2.6-pro.cpp +529 -0
- package/eval/arena/bomberman/bots/opus-5.5.cpp +548 -0
- package/eval/arena/bomberman/bots/qwen-3.8-max.cpp +836 -0
- package/eval/arena/bomberman/tournament/README.md +11 -0
- package/eval/arena/bomberman/tournament/bt.py +56 -0
- package/eval/arena/bomberman/tournament/evaluate.py +199 -0
- package/eval/arena/bomberman/tournament/run.py +79 -0
- package/eval/arena/bomberman/tournament/schedule-2to10.json.gz +0 -0
- package/eval/arena/bomberman/workspace/MANIFEST.json +13 -0
- package/eval/arena/bomberman/workspace/README.md +29 -0
- package/eval/arena/bomberman/workspace/RULES.md +100 -0
- package/eval/arena/bomberman/workspace/baseline.cpp +240 -0
- package/eval/arena/bomberman/workspace/clock.py +25 -0
- package/eval/arena/bomberman/workspace/engine/arena.py +198 -0
- package/eval/arena/bomberman/workspace/engine/build.py +35 -0
- package/eval/arena/bomberman/workspace/engine/engine.py +256 -0
- package/eval/arena/bomberman/workspace/engine/verify_replay.py +24 -0
- package/eval/arena/bomberman/workspace/run.cmd +28 -0
- package/eval/arena/bomberman/workspace/run.sh +16 -0
- package/eval/arena/bomberman/workspace/viewer/index.html +42 -0
- package/eval/arena/ctf/bots/README.md +18 -0
- package/eval/arena/ctf/bots/deepseek-v4.1-flash.cpp +601 -0
- package/eval/arena/ctf/bots/doubao-seed-2.1-turbo.cpp +320 -0
- package/eval/arena/ctf/bots/fable-5.1.cpp +634 -0
- package/eval/arena/ctf/bots/glm-5.3.cpp +689 -0
- package/eval/arena/ctf/bots/gpt-6-astra.cpp +657 -0
- package/eval/arena/ctf/bots/gpt-6.1-sol.cpp +725 -0
- package/eval/arena/ctf/bots/kimi-k3.cpp +667 -0
- package/eval/arena/ctf/bots/mimo-v2.6-pro.cpp +533 -0
- package/eval/arena/ctf/bots/opus-5.5.cpp +645 -0
- package/eval/arena/ctf/bots/qwen-3.8-max.cpp +726 -0
- package/eval/arena/ctf/bots/sonnet-5.5.cpp +569 -0
- package/eval/arena/ctf/tournament/README.md +15 -0
- package/eval/arena/ctf/tournament/formal-2to8.json +31 -0
- package/eval/arena/ctf/tournament/formal-9to15.json +31 -0
- package/eval/arena/ctf/workspace/README.md +41 -0
- package/eval/arena/ctf/workspace/RULES.md +119 -0
- package/eval/arena/ctf/workspace/arena.py +186 -0
- package/eval/arena/ctf/workspace/baseline.cpp +257 -0
- package/eval/arena/ctf/workspace/clock.py +15 -0
- package/eval/arena/ctf/workspace/core.py +265 -0
- package/eval/arena/ctf/workspace/engine.py +389 -0
- package/eval/arena/ctf/workspace/run.cmd +24 -0
- package/eval/arena/ctf/workspace/run.sh +11 -0
- package/eval/arena/ctf/workspace/viewer.html +71 -0
- package/eval/arena/land/bots/README.md +17 -0
- package/eval/arena/land/bots/deepseek-4.1f@workbuddy#1/bot.cpp +608 -0
- package/eval/arena/land/bots/glm-5.3@workbuddy#1/bot.cpp +521 -0
- package/eval/arena/land/bots/gpt-6-astra@codex#1/bot.cpp +373 -0
- package/eval/arena/land/bots/gpt-6-sol@codex#1/bot.cpp +341 -0
- package/eval/arena/land/bots/kimi-k3@workbuddy#1/bot.cpp +492 -0
- package/eval/arena/land/bots/mimo-2.6-pro@zcode#1/bot.cpp +652 -0
- package/eval/arena/land/bots/mystery-model@zcode#1/bot.cpp +466 -0
- package/eval/arena/land/bots/opus-5.5@claude-code#1/bot.cpp +630 -0
- package/eval/arena/land/bots/sonnet-5@claude-code#1/bot.cpp +619 -0
- package/eval/arena/land/tournament/make_replay_page.py +17 -0
- package/eval/arena/land/tournament/rate.py +290 -0
- package/eval/arena/land/tournament/round_robin.py +172 -0
- package/eval/arena/land/tournament/sparring.cpp +356 -0
- package/eval/arena/land/workspace/RULES.md +114 -0
- package/eval/arena/land/workspace/TASK.md +46 -0
- package/eval/arena/land/workspace/anchors/.build/greedy_f2e6d2dea5ca +0 -0
- package/eval/arena/land/workspace/anchors/greedy.cpp +194 -0
- package/eval/arena/land/workspace/anchors/random.cpp +80 -0
- package/eval/arena/land/workspace/clock.py +64 -0
- package/eval/arena/land/workspace/engine/build.py +33 -0
- package/eval/arena/land/workspace/engine/game.py +273 -0
- package/eval/arena/land/workspace/engine/referee.py +308 -0
- package/eval/arena/land/workspace/starter/.build/bot_be32b45b4699 +0 -0
- package/eval/arena/land/workspace/starter/bot.cpp +82 -0
- package/eval/arena/land/workspace/viewer/viewer.html +210 -0
- package/eval/arena/tank/bots/README.md +24 -0
- package/eval/arena/tank/bots/half1/deepseek-v4.1-flash.cpp +367 -0
- package/eval/arena/tank/bots/half1/doubao-seed-evolving.cpp +402 -0
- package/eval/arena/tank/bots/half1/gemini-4-argon.cpp +1132 -0
- package/eval/arena/tank/bots/half1/glm-5.3.cpp +551 -0
- package/eval/arena/tank/bots/half1/gpt-6-astra.cpp +233 -0
- package/eval/arena/tank/bots/half1/gpt-6.1-sol-ultrafast.cpp +350 -0
- package/eval/arena/tank/bots/half1/gpt-6.1-sol.cpp +78 -0
- package/eval/arena/tank/bots/half1/grok-4.7.cpp +1099 -0
- package/eval/arena/tank/bots/half1/haiku-5.5.cpp +210 -0
- package/eval/arena/tank/bots/half1/kimi-k3.cpp +353 -0
- package/eval/arena/tank/bots/half1/mimo-v2.6-pro.cpp +336 -0
- package/eval/arena/tank/bots/half1/muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/bots/half1/opus-5.5.cpp +435 -0
- package/eval/arena/tank/bots/half1/qwen-3.8-max.cpp +537 -0
- package/eval/arena/tank/bots/half2/deepseek-v4.1-flash.cpp +425 -0
- package/eval/arena/tank/bots/half2/doubao-seed-evolving.cpp +308 -0
- package/eval/arena/tank/bots/half2/gemini-4-argon.cpp +1390 -0
- package/eval/arena/tank/bots/half2/glm-5.3.cpp +651 -0
- package/eval/arena/tank/bots/half2/gpt-6-astra.cpp +241 -0
- package/eval/arena/tank/bots/half2/gpt-6.1-sol-ultrafast.cpp +356 -0
- package/eval/arena/tank/bots/half2/gpt-6.1-sol.cpp +87 -0
- package/eval/arena/tank/bots/half2/grok-4.7.cpp +1205 -0
- package/eval/arena/tank/bots/half2/haiku-5.5.cpp +210 -0
- package/eval/arena/tank/bots/half2/kimi-k3.cpp +487 -0
- package/eval/arena/tank/bots/half2/mimo-v2.6-pro.cpp +336 -0
- package/eval/arena/tank/bots/half2/muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/bots/half2/opus-5.5.cpp +476 -0
- package/eval/arena/tank/bots/half2/qwen-3.8-max.cpp +392 -0
- package/eval/arena/tank/tournament/README.md +24 -0
- package/eval/arena/tank/tournament/bt.py +218 -0
- package/eval/arena/tank/tournament/final.json +202 -0
- package/eval/arena/tank/tournament/halftime.json +146 -0
- package/eval/arena/tank/tournament/progress.json +911 -0
- package/eval/arena/tank/tournament/schedule.py +100 -0
- package/eval/arena/tank/tournament/sparring.cpp +928 -0
- package/eval/arena/tank/tournament/tournament.py +1426 -0
- package/eval/arena/tank/workspace/README.md +169 -0
- package/eval/arena/tank/workspace/RULES.md +443 -0
- package/eval/arena/tank/workspace/arena.py +862 -0
- package/eval/arena/tank/workspace/baseline.cpp +259 -0
- package/eval/arena/tank/workspace/clock.py +103 -0
- package/eval/arena/tank/workspace/core.py +712 -0
- package/eval/arena/tank/workspace/engine.py +573 -0
- package/eval/arena/tank/workspace/history/.lock +0 -0
- package/eval/arena/tank/workspace/history/20261017-193610-08715287f91f-bot.cpp +109 -0
- package/eval/arena/tank/workspace/history/20261017-193619-f00b2d5635fa-gpt-6-astra.cpp +241 -0
- package/eval/arena/tank/workspace/history/20261017-193643-63319e0a2b1a-gpt-6_1-sol-ultrafast.cpp +356 -0
- package/eval/arena/tank/workspace/history/20261017-193647-41c1341d0a8a-gemini-4-argon.cpp +1390 -0
- package/eval/arena/tank/workspace/history/20261017-193652-e34c0f45539a-gpt-6_1-sol.cpp +87 -0
- package/eval/arena/tank/workspace/history/20261017-193654-c026348ce96e-opus-5_5.cpp +476 -0
- package/eval/arena/tank/workspace/history/20261017-193655-4a21366e94d1-muse-wonder-full.cpp +560 -0
- package/eval/arena/tank/workspace/history/20261017-193657-dbc4e9969c52-mimo-v2_6-pro.cpp +336 -0
- package/eval/arena/tank/workspace/history/20261017-193703-723cd036eb31-grok-4_7.cpp +1205 -0
- package/eval/arena/tank/workspace/history/20261017-193707-1ebbb227be68-deepseek-v4_1-flash.cpp +425 -0
- package/eval/arena/tank/workspace/history/20261017-193709-aeb0e7202ad5-doubao-seed-evolving.cpp +308 -0
- package/eval/arena/tank/workspace/history/20261017-193710-b21ebeb9bc76-kimi-k3.cpp +487 -0
- package/eval/arena/tank/workspace/history/20261017-193712-54cd86531905-haiku-5_5.cpp +210 -0
- package/eval/arena/tank/workspace/history/20261017-193714-efdb8e35c0bf-qwen-3_8-max.cpp +392 -0
- package/eval/arena/tank/workspace/history/20261017-193715-681423c23fdb-glm-5_3.cpp +651 -0
- package/eval/arena/tank/workspace/history/20261017-193717-1a8b3c75181d-sparring.cpp +928 -0
- package/eval/arena/tank/workspace/history/20261017-193720-1e0803a541e8-baseline.cpp +259 -0
- package/eval/arena/tank/workspace/history/log.jsonl +103 -0
- package/eval/arena/tank/workspace/judge/cycles.hpp +53 -0
- package/eval/arena/tank/workspace/judge/fast.cpp +337 -0
- package/eval/arena/tank/workspace/judge/referee.cpp +125 -0
- package/eval/arena/tank/workspace/judge/speed.cpp +99 -0
- package/eval/arena/tank/workspace/run.cmd +31 -0
- package/eval/arena/tank/workspace/run.sh +23 -0
- package/eval/arena/tank/workspace/tank.hpp +1762 -0
- package/eval/arena/tank/workspace/tank_main.cpp +215 -0
- package/eval/arena/tank/workspace/viewer.html +1150 -0
- package/eval/arena/warehouse/workspace/SPEC.md +130 -0
- package/eval/arena/warehouse/workspace/TASK.md +71 -0
- package/eval/arena/warehouse/workspace/baseline/common.h +88 -0
- package/eval/arena/warehouse/workspace/baseline/main.cpp +27 -0
- package/eval/arena/warehouse/workspace/baseline/old_stuff.cpp +87 -0
- package/eval/arena/warehouse/workspace/baseline/sim.cpp +427 -0
- package/eval/arena/warehouse/workspace/baseline/util.cpp +220 -0
- package/eval/arena/warehouse/workspace/clock.py +42 -0
- package/eval/arena/warehouse/workspace/src/common.h +88 -0
- package/eval/arena/warehouse/workspace/src/main.cpp +27 -0
- package/eval/arena/warehouse/workspace/src/old_stuff.cpp +87 -0
- package/eval/arena/warehouse/workspace/src/sim.cpp +427 -0
- package/eval/arena/warehouse/workspace/src/util.cpp +220 -0
- package/eval/arena/warehouse/workspace/tools/bench.py +119 -0
- package/eval/arena/warehouse/workspace/tools/check_input.py +161 -0
- package/eval/arena/warehouse/workspace/tools/gen.py +132 -0
- package/eval/arena/warehouse/workspace/tools/measure.py +107 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.in +1420 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.out +9162 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.in +1465 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.out +3439 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_flood.in +2757 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_flood.out +3126 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_small.in +731 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_small.out +2578 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_wide.in +528 -0
- package/eval/arena/warehouse/workspace/workloads/public/pub_wide.out +2026 -0
- package/eval/bomberman.py +20 -0
- package/eval/commit0.py +21 -0
- package/eval/common.py +61 -0
- package/eval/ctf.py +20 -0
- package/eval/featurebench.py +25 -0
- package/eval/land.py +20 -0
- package/eval/legacy/bomberman-prices.json +4 -0
- package/eval/legacy/bomberman.py +161 -0
- package/eval/legacy/commit0.py +91 -0
- package/eval/legacy/ctf-prices.json +4 -0
- package/eval/legacy/ctf.py +178 -0
- package/eval/legacy/featurebench.py +103 -0
- package/eval/legacy/land-prices.json +4 -0
- package/eval/legacy/land.py +177 -0
- package/eval/legacy/swe_bench_pro.py +116 -0
- package/eval/legacy/tank-prices.json +3 -0
- package/eval/legacy/tank.py +408 -0
- package/eval/legacy/warehouse-prices.json +4 -0
- package/eval/legacy/warehouse.py +365 -0
- package/eval/swe-bench-pro.py +25 -0
- package/eval/tank.py +20 -0
- package/eval/warehouse.py +20 -0
- package/lib/client/index.js +376 -63
- package/lib/client/index.js.map +1 -1
- package/lib/index.js +684 -27
- package/package.json +2 -1
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
// 夺旗 bot:任务竞价的三角色协同
|
|
2
|
+
// - 携旗者走最快路线回基地(速度优先,不绕路)
|
|
3
|
+
// - 队友护卫我方携旗者;空闲角色拦截敌方携旗者(4 方以上积极追猎)
|
|
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
|
+
static const int DX4[4] = {0, 0, -1, 1};
|
|
68
|
+
static const int DY4[4] = {-1, 1, 0, 0};
|
|
69
|
+
static const char MVC[4] = {'U', 'D', 'L', 'R'};
|
|
70
|
+
static const int INF = 1000000000;
|
|
71
|
+
|
|
72
|
+
struct Bot {
|
|
73
|
+
int S = 0, me = 0;
|
|
74
|
+
vector<char> wall;
|
|
75
|
+
vector<vector<int>> baseCells, spawnCells;
|
|
76
|
+
vector<int> spotCells;
|
|
77
|
+
vector<int> dHome;
|
|
78
|
+
bool inited = false;
|
|
79
|
+
|
|
80
|
+
int cellOf(int x, int y) const { return y * S + x; }
|
|
81
|
+
bool inb(int x, int y) const { return x >= 0 && y >= 0 && x < S && y < S; }
|
|
82
|
+
|
|
83
|
+
static bool stableLess(int a, int b, int S, int bx, int by, int cx, int cy) {
|
|
84
|
+
int ax = a % S, ay = a / S, x2 = b % S, y2 = b / S;
|
|
85
|
+
int da = abs(ax - cx) + abs(ay - cy), db = abs(x2 - cx) + abs(y2 - cy);
|
|
86
|
+
if (da != db) return da < db;
|
|
87
|
+
return abs(ax - bx) + 2 * abs(ay - by) < abs(x2 - bx) + 2 * abs(y2 - by);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void init(const Game& g) {
|
|
91
|
+
S = g.size; me = g.me;
|
|
92
|
+
wall.assign(S * S, 0);
|
|
93
|
+
for (int y = 0; y < S; y++) for (int x = 0; x < S; x++) wall[cellOf(x, y)] = (g.map[y][x] == '#');
|
|
94
|
+
int cx = S / 2, cy = S / 2;
|
|
95
|
+
baseCells.assign(g.teams, {});
|
|
96
|
+
spawnCells.assign(g.teams, {});
|
|
97
|
+
for (int t = 0; t < g.teams; t++) {
|
|
98
|
+
int bx = g.bases[t].first, by = g.bases[t].second;
|
|
99
|
+
vector<int> cs;
|
|
100
|
+
for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) {
|
|
101
|
+
if (!inb(bx + dx, by + dy)) continue;
|
|
102
|
+
cs.push_back(cellOf(bx + dx, by + dy));
|
|
103
|
+
}
|
|
104
|
+
baseCells[t] = cs;
|
|
105
|
+
stable_sort(cs.begin(), cs.end(), [&](int a, int b) { return stableLess(a, b, S, bx, by, cx, cy); });
|
|
106
|
+
spawnCells[t] = cs;
|
|
107
|
+
}
|
|
108
|
+
for (auto& s : g.spots) spotCells.push_back(cellOf(s.first, s.second));
|
|
109
|
+
dHome = bfs(baseCells[me]);
|
|
110
|
+
inited = true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
vector<int> bfs(const vector<int>& src) const {
|
|
114
|
+
vector<int> d(S * S, -1);
|
|
115
|
+
vector<int> q;
|
|
116
|
+
q.reserve(S * S);
|
|
117
|
+
for (int c : src) if (c >= 0 && !wall[c] && d[c] < 0) { d[c] = 0; q.push_back(c); }
|
|
118
|
+
for (size_t i = 0; i < q.size(); i++) {
|
|
119
|
+
int c = q[i], x = c % S, y = c / S;
|
|
120
|
+
for (int k = 0; k < 4; k++) {
|
|
121
|
+
int nx = x + DX4[k], ny = y + DY4[k];
|
|
122
|
+
if (!inb(nx, ny)) continue;
|
|
123
|
+
int n = ny * S + nx;
|
|
124
|
+
if (wall[n] || d[n] >= 0) continue;
|
|
125
|
+
d[n] = d[c] + 1;
|
|
126
|
+
q.push_back(n);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return d;
|
|
130
|
+
}
|
|
131
|
+
vector<int> bfs1(int c) const { return bfs(vector<int>{c}); }
|
|
132
|
+
|
|
133
|
+
vector<int> dijkstra(const vector<int>& src, const vector<int>& cost) const {
|
|
134
|
+
vector<int> d(S * S, INF);
|
|
135
|
+
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
|
|
136
|
+
for (int c : src) if (c >= 0 && !wall[c] && d[c] > 0) { d[c] = 0; pq.push({0, c}); }
|
|
137
|
+
while (!pq.empty()) {
|
|
138
|
+
pair<int, int> top = pq.top(); pq.pop();
|
|
139
|
+
int dd = top.first, c = top.second;
|
|
140
|
+
if (dd > d[c]) continue;
|
|
141
|
+
int x = c % S, y = c / S;
|
|
142
|
+
for (int k = 0; k < 4; k++) {
|
|
143
|
+
int nx = x + DX4[k], ny = y + DY4[k];
|
|
144
|
+
if (!inb(nx, ny)) continue;
|
|
145
|
+
int n = ny * S + nx;
|
|
146
|
+
if (wall[n]) continue;
|
|
147
|
+
int nd = dd + 1 + cost[n];
|
|
148
|
+
if (nd < d[n]) { d[n] = nd; pq.push({nd, n}); }
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return d;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
bool canAttack(int ax, int ay, int bx, int by) const {
|
|
155
|
+
int dx = bx - ax, dy = by - ay;
|
|
156
|
+
if (abs(dx) + abs(dy) > 2) return false;
|
|
157
|
+
if (abs(dx) == 2 && dy == 0) return !wall[cellOf(ax + dx / 2, ay)];
|
|
158
|
+
if (abs(dy) == 2 && dx == 0) return !wall[cellOf(ax, ay + dy / 2)];
|
|
159
|
+
if (abs(dx) == 1 && abs(dy) == 1) return !wall[cellOf(ax + dx, ay)] || !wall[cellOf(ax, ay + dy)];
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
int stepDown(int from, const vector<int>& pot, const vector<int>& danger) const {
|
|
164
|
+
int x = from % S, y = from / S;
|
|
165
|
+
int cur = (pot[from] >= INF) ? INF : pot[from];
|
|
166
|
+
int bestVal = cur, bestDg = danger[from], bestMv = -1;
|
|
167
|
+
for (int k = 0; k < 4; k++) {
|
|
168
|
+
int nx = x + DX4[k], ny = y + DY4[k];
|
|
169
|
+
if (!inb(nx, ny)) continue;
|
|
170
|
+
int n = ny * S + nx;
|
|
171
|
+
if (wall[n] || pot[n] >= INF) continue;
|
|
172
|
+
int v = pot[n];
|
|
173
|
+
if (v < bestVal || (v == bestVal && danger[n] < bestDg)) { bestVal = v; bestDg = danger[n]; bestMv = k; }
|
|
174
|
+
}
|
|
175
|
+
if (bestMv >= 0 && bestVal >= cur) return -1;
|
|
176
|
+
return bestMv;
|
|
177
|
+
}
|
|
178
|
+
int cellAt(int c, int mv) const { return c + DY4[mv] * S + DX4[mv]; }
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
struct Cmd { char mv = 'S'; string act = "-"; };
|
|
182
|
+
|
|
183
|
+
enum { T_NONE = 0, T_FETCH, T_HOME, T_DEFEND, T_HUNT, T_CAMP };
|
|
184
|
+
|
|
185
|
+
int main() {
|
|
186
|
+
ios::sync_with_stdio(false);
|
|
187
|
+
Game g;
|
|
188
|
+
Bot bot;
|
|
189
|
+
while (read_turn(g)) {
|
|
190
|
+
if (!bot.inited) bot.init(g);
|
|
191
|
+
int T = g.turn;
|
|
192
|
+
int N = (int)g.units.size();
|
|
193
|
+
int S = bot.S, me = bot.me;
|
|
194
|
+
const int DMG = g.damage;
|
|
195
|
+
const int MELEE = 2;
|
|
196
|
+
|
|
197
|
+
// ---------- 有效位置(含本回合重生者)----------
|
|
198
|
+
vector<int> pos(N, -1);
|
|
199
|
+
vector<char> alive(N, 0), imm(N, 0);
|
|
200
|
+
{
|
|
201
|
+
vector<char> occ(S * S, 0);
|
|
202
|
+
for (auto& u : g.units) if (u.x >= 0) { pos[u.id] = bot.cellOf(u.x, u.y); alive[u.id] = 1; occ[pos[u.id]] = 1; }
|
|
203
|
+
for (auto& u : g.units) if (!alive[u.id] && u.respawn_at >= 0 && u.respawn_at <= T) {
|
|
204
|
+
for (int c : bot.spawnCells[u.team]) if (!occ[c]) { pos[u.id] = c; alive[u.id] = 1; imm[u.id] = 1; occ[c] = 1; break; }
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
vector<int> enemyCells, myCells;
|
|
208
|
+
for (auto& u : g.units) if (alive[u.id]) { if (u.team == me) myCells.push_back(pos[u.id]); else enemyCells.push_back(pos[u.id]); }
|
|
209
|
+
vector<int> dEnemy = bot.bfs(enemyCells);
|
|
210
|
+
|
|
211
|
+
// ---------- 威胁图 ----------
|
|
212
|
+
vector<int> danger(S * S, 0);
|
|
213
|
+
for (auto& u : g.units) {
|
|
214
|
+
if (u.team == me || !alive[u.id] || imm[u.id]) continue;
|
|
215
|
+
int ex = pos[u.id] % S, ey = pos[u.id] / S;
|
|
216
|
+
for (int dx = -2; dx <= 2; dx++) for (int dy = -2; dy <= 2; dy++) {
|
|
217
|
+
int md = abs(dx) + abs(dy);
|
|
218
|
+
if (md > 2) continue;
|
|
219
|
+
int tx = ex + dx, ty = ey + dy;
|
|
220
|
+
if (!bot.inb(tx, ty)) continue;
|
|
221
|
+
int c = bot.cellOf(tx, ty);
|
|
222
|
+
if (bot.wall[c]) continue;
|
|
223
|
+
if (bot.canAttack(ex, ey, tx, ty)) danger[c] += 2;
|
|
224
|
+
}
|
|
225
|
+
for (int dx = -3; dx <= 3; dx++) for (int dy = -3; dy <= 3; dy++) {
|
|
226
|
+
if (abs(dx) + abs(dy) != 3) continue;
|
|
227
|
+
int tx = ex + dx, ty = ey + dy;
|
|
228
|
+
if (!bot.inb(tx, ty)) continue;
|
|
229
|
+
int c = bot.cellOf(tx, ty);
|
|
230
|
+
if (!bot.wall[c]) danger[c] += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ---------- 旗子 ----------
|
|
235
|
+
int nReturn = 0, nEmptySpot = 0;
|
|
236
|
+
for (auto& f : g.flags) {
|
|
237
|
+
if ((f.status == "dropped" || f.status == "cooldown") && f.return_at == T) nReturn++;
|
|
238
|
+
if (f.status != "home") nEmptySpot++;
|
|
239
|
+
}
|
|
240
|
+
(void)nEmptySpot;
|
|
241
|
+
struct FI { int id, cell; vector<int> d; int enArr, en3, rt; };
|
|
242
|
+
vector<FI> fis;
|
|
243
|
+
for (auto& f : g.flags) {
|
|
244
|
+
if (f.status != "home" && f.status != "dropped") continue;
|
|
245
|
+
if (f.x < 0) continue;
|
|
246
|
+
FI fi; fi.id = f.id; fi.cell = bot.cellOf(f.x, f.y);
|
|
247
|
+
fi.d = bot.bfs1(fi.cell);
|
|
248
|
+
fi.enArr = INF; fi.en3 = 0;
|
|
249
|
+
for (auto& u : g.units) {
|
|
250
|
+
if (u.team == me || !alive[u.id] || g.units[u.id].flag >= 0) continue;
|
|
251
|
+
int dd = fi.d[pos[u.id]];
|
|
252
|
+
if (dd < 0) continue;
|
|
253
|
+
fi.enArr = min(fi.enArr, dd);
|
|
254
|
+
if (dd <= 3) fi.en3++;
|
|
255
|
+
}
|
|
256
|
+
fi.rt = bot.dHome[fi.cell];
|
|
257
|
+
if (fi.rt < 0) fi.rt = 60;
|
|
258
|
+
fis.push_back(fi);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ---------- 我的角色 ----------
|
|
262
|
+
int myU[3] = {3 * me, 3 * me + 1, 3 * me + 2};
|
|
263
|
+
bool carry[3] = {false, false, false}, live[3] = {false, false, false};
|
|
264
|
+
int hp[3] = {0, 0, 0};
|
|
265
|
+
for (int k = 0; k < 3; k++) {
|
|
266
|
+
live[k] = alive[myU[k]];
|
|
267
|
+
if (live[k]) { hp[k] = g.units[myU[k]].hp; carry[k] = g.units[myU[k]].flag >= 0; }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 每个我方角色到各处的距离场(按需)
|
|
271
|
+
struct Task { int type = T_NONE; int target = -1; double util = 0; int aux = -1; };
|
|
272
|
+
Task task[3];
|
|
273
|
+
int tref[3] = {-1, -1, -1};
|
|
274
|
+
|
|
275
|
+
// ---------- 1. 携旗者:回基地 ----------
|
|
276
|
+
for (int k = 0; k < 3; k++) if (live[k] && carry[k]) task[k] = {T_HOME, -1, 0, 0};
|
|
277
|
+
|
|
278
|
+
// ---------- 2. 护卫:我方携旗者受威胁 ----------
|
|
279
|
+
{
|
|
280
|
+
vector<char> assigned(3, 0);
|
|
281
|
+
for (int k = 0; k < 3; k++) if (task[k].type != T_NONE) assigned[k] = 1;
|
|
282
|
+
for (int k = 0; k < 3; k++) {
|
|
283
|
+
if (!live[k] || !carry[k]) continue;
|
|
284
|
+
vector<int> dc = bot.bfs1(pos[myU[k]]);
|
|
285
|
+
// 找我方携旗者附近的敌人
|
|
286
|
+
vector<pair<int, int>> threats; // (dist, uid)
|
|
287
|
+
for (auto& u : g.units) {
|
|
288
|
+
if (u.team == me || !alive[u.id] || imm[u.id]) continue;
|
|
289
|
+
int dd = dc[pos[u.id]];
|
|
290
|
+
if (dd >= 0 && dd <= 5) threats.push_back({dd, u.id});
|
|
291
|
+
}
|
|
292
|
+
if (threats.empty()) continue;
|
|
293
|
+
sort(threats.begin(), threats.end());
|
|
294
|
+
int nDef = (threats.size() >= 2 || hp[k] <= 68) ? 2 : 1;
|
|
295
|
+
for (int q = 0; q < nDef && q < (int)threats.size(); q++) {
|
|
296
|
+
int e = threats[q].second;
|
|
297
|
+
vector<int> de = bot.bfs1(pos[e]);
|
|
298
|
+
int bestK = -1, bestD = INF;
|
|
299
|
+
for (int j = 0; j < 3; j++) {
|
|
300
|
+
if (!live[j] || carry[j] || assigned[j]) continue;
|
|
301
|
+
int dd = de[pos[myU[j]]];
|
|
302
|
+
if (dd >= 0 && dd < bestD) { bestD = dd; bestK = j; }
|
|
303
|
+
}
|
|
304
|
+
if (bestK < 0 || bestD > 7) continue;
|
|
305
|
+
task[bestK] = {T_DEFEND, e, 1.0 / (1.0 + bestD), k};
|
|
306
|
+
assigned[bestK] = 1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ---------- 3. 抢旗 ----------
|
|
312
|
+
{
|
|
313
|
+
vector<char> usedF(g.flags.size(), 0), usedU(3, 0);
|
|
314
|
+
for (int k = 0; k < 3; k++) if (task[k].type != T_NONE) usedU[k] = 1;
|
|
315
|
+
struct Pair { double u; int k, f; };
|
|
316
|
+
vector<Pair> ps;
|
|
317
|
+
for (int k = 0; k < 3; k++) {
|
|
318
|
+
if (!live[k] || carry[k] || usedU[k]) continue;
|
|
319
|
+
for (int j = 0; j < (int)fis.size(); j++) {
|
|
320
|
+
int d = fis[j].d[pos[myU[k]]];
|
|
321
|
+
if (d < 0) continue;
|
|
322
|
+
double p = 1.0;
|
|
323
|
+
if (fis[j].enArr <= d) p = (fis[j].enArr == d) ? 0.25 : 0.06;
|
|
324
|
+
// 抢不到又远:别白跑,去站位更好
|
|
325
|
+
if (fis[j].enArr <= d && d > 4) continue;
|
|
326
|
+
double risk = 1.0 / (1.0 + 0.35 * fis[j].en3);
|
|
327
|
+
double util = p * risk / (double)max(4, d + fis[j].rt);
|
|
328
|
+
ps.push_back({util, k, j});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
sort(ps.begin(), ps.end(), [](const Pair& a, const Pair& b) { return a.u > b.u; });
|
|
332
|
+
for (auto& p : ps) {
|
|
333
|
+
if (usedU[p.k] || usedF[p.f]) continue;
|
|
334
|
+
task[p.k] = {T_FETCH, p.f, p.u, -1};
|
|
335
|
+
usedU[p.k] = 1; usedF[p.f] = 1;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ---------- 敌方携旗者 ----------
|
|
340
|
+
struct Carrier { int uid, cell, homeDist; };
|
|
341
|
+
vector<Carrier> ecar;
|
|
342
|
+
vector<vector<int>> ecarD;
|
|
343
|
+
for (auto& u : g.units) {
|
|
344
|
+
if (u.team == me || !alive[u.id] || g.units[u.id].flag < 0) continue;
|
|
345
|
+
vector<int> eb = bot.bfs(bot.baseCells[u.team]);
|
|
346
|
+
int hd = eb[pos[u.id]];
|
|
347
|
+
if (hd < 0) hd = 60;
|
|
348
|
+
ecar.push_back({u.id, pos[u.id], hd});
|
|
349
|
+
ecarD.push_back(bot.bfs1(pos[u.id]));
|
|
350
|
+
}
|
|
351
|
+
auto hitsNeeded = [&](int h) { return (h + DMG - 1) / DMG; };
|
|
352
|
+
|
|
353
|
+
// ---------- 4. 拦截敌方携旗者 ----------
|
|
354
|
+
// 人多时旗子几乎总在被携带,抢不到旗就等于丢分,所以积极追猎;
|
|
355
|
+
// 人数少时(2-3 方)追猎不如自己抢旗,保持原来的保守条件。
|
|
356
|
+
{
|
|
357
|
+
vector<char> usedU(3, 0);
|
|
358
|
+
for (int k = 0; k < 3; k++) if (task[k].type != T_NONE) usedU[k] = 1;
|
|
359
|
+
bool aggressive = g.teams >= 4;
|
|
360
|
+
for (size_t i = 0; i < ecar.size(); i++) {
|
|
361
|
+
if (!aggressive && ecar[i].homeDist > 14) continue;
|
|
362
|
+
int bestK = -1; double bestU = 0;
|
|
363
|
+
for (int k = 0; k < 3; k++) {
|
|
364
|
+
if (!live[k] || carry[k] || usedU[k]) continue;
|
|
365
|
+
int du = ecarD[i][pos[myU[k]]];
|
|
366
|
+
if (du < 0) continue;
|
|
367
|
+
int need = hitsNeeded(g.units[ecar[i].uid].hp);
|
|
368
|
+
if (aggressive) {
|
|
369
|
+
if (du > 10) continue;
|
|
370
|
+
int avail = ecar[i].homeDist + 1 - max(0, du - MELEE);
|
|
371
|
+
if (avail < 1) continue;
|
|
372
|
+
double util = 1.0 / (double)max(4, du + need);
|
|
373
|
+
if (util > bestU) { bestU = util; bestK = k; }
|
|
374
|
+
} else {
|
|
375
|
+
int avail = ecar[i].homeDist - max(0, du - MELEE);
|
|
376
|
+
double pk = avail <= 0 ? 0.0 : min(1.0, (double)avail / need);
|
|
377
|
+
double util = 1.0 * pk / (double)max(3, du + 2);
|
|
378
|
+
if (util > bestU) { bestU = util; bestK = k; }
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (bestK >= 0 && bestU > 0.02) { task[bestK] = {T_HUNT, ecar[i].uid, bestU, -1}; usedU[bestK] = 1; }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ---------- 5. 驻守旗点 ----------
|
|
386
|
+
{
|
|
387
|
+
// 每个旗点的距离场
|
|
388
|
+
vector<vector<int>> spotDist(bot.spotCells.size());
|
|
389
|
+
for (size_t i = 0; i < bot.spotCells.size(); i++) {
|
|
390
|
+
bool got = false;
|
|
391
|
+
for (auto& fi : fis) if (fi.cell == bot.spotCells[i]) { spotDist[i] = fi.d; got = true; break; }
|
|
392
|
+
if (!got) spotDist[i] = bot.bfs1(bot.spotCells[i]);
|
|
393
|
+
}
|
|
394
|
+
double pRet = nReturn > 0 ? (double)nReturn / (double)max(1, (int)bot.spotCells.size()) : 0.0;
|
|
395
|
+
vector<char> usedU(3, 0), usedSpot(bot.spotCells.size(), 0);
|
|
396
|
+
for (int k = 0; k < 3; k++) if (task[k].type != T_NONE) usedU[k] = 1;
|
|
397
|
+
// 每个空闲角色的最佳驻守目标
|
|
398
|
+
for (int k = 0; k < 3; k++) {
|
|
399
|
+
if (!live[k] || carry[k] || usedU[k]) continue;
|
|
400
|
+
double bestV = -1e18; int bestI = -1;
|
|
401
|
+
for (size_t i = 0; i < bot.spotCells.size(); i++) {
|
|
402
|
+
if (usedSpot[i]) continue;
|
|
403
|
+
int dd = spotDist[i][pos[myU[k]]];
|
|
404
|
+
if (dd < 0) continue;
|
|
405
|
+
double val = 0;
|
|
406
|
+
for (size_t j = 0; j < bot.spotCells.size(); j++) {
|
|
407
|
+
int d2 = spotDist[j][bot.spotCells[i]];
|
|
408
|
+
if (d2 < 0) d2 = 40;
|
|
409
|
+
val -= (double)(d2 + bot.dHome[bot.spotCells[j]]) / (double)bot.spotCells.size();
|
|
410
|
+
}
|
|
411
|
+
val += pRet * 6.0;
|
|
412
|
+
val -= 0.4 * dd;
|
|
413
|
+
if (val > bestV) { bestV = val; bestI = (int)i; }
|
|
414
|
+
}
|
|
415
|
+
if (bestI >= 0) { task[k] = {T_CAMP, bot.spotCells[bestI], bestV, -1}; usedSpot[bestI] = 1; usedU[k] = 1; }
|
|
416
|
+
}
|
|
417
|
+
// 兜底:没有任务的角色去最近的旗点,避免原地发呆
|
|
418
|
+
for (int k = 0; k < 3; k++) {
|
|
419
|
+
if (!live[k] || carry[k] || task[k].type != T_NONE) continue;
|
|
420
|
+
int bestC = -1, bestD = INF;
|
|
421
|
+
for (size_t i = 0; i < bot.spotCells.size(); i++) {
|
|
422
|
+
int dd = spotDist[i][pos[myU[k]]];
|
|
423
|
+
if (dd >= 0 && dd < bestD) { bestD = dd; bestC = bot.spotCells[i]; }
|
|
424
|
+
}
|
|
425
|
+
if (bestC >= 0) task[k] = {T_CAMP, bestC, 0, -1};
|
|
426
|
+
else task[k] = {T_HOME, -1, 0, -1};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ---------- 生成移动 ----------
|
|
431
|
+
Cmd cmd[3];
|
|
432
|
+
vector<int> post = pos;
|
|
433
|
+
vector<int> cost(S * S, 0);
|
|
434
|
+
for (int k = 0; k < 3; k++) {
|
|
435
|
+
if (!live[k]) continue;
|
|
436
|
+
int from = pos[myU[k]];
|
|
437
|
+
int tgt = -1;
|
|
438
|
+
bool isCarrier = carry[k];
|
|
439
|
+
if (task[k].type == T_HOME) {
|
|
440
|
+
vector<char> inBase(S * S, 0);
|
|
441
|
+
for (int bc : bot.baseCells[me]) inBase[bc] = 1;
|
|
442
|
+
for (int c = 0; c < S * S; c++) {
|
|
443
|
+
int de = dEnemy[c];
|
|
444
|
+
int cst = 0;
|
|
445
|
+
if (de >= 0 && de <= 1) cst += 3;
|
|
446
|
+
else if (de == 2) cst += 1;
|
|
447
|
+
// 队友挡路时绕开(基地格除外,基地有 9 格)
|
|
448
|
+
if (!inBase[c]) for (int j = 0; j < 3; j++) if (j != k && live[j] && pos[myU[j]] == c) cst += 25;
|
|
449
|
+
cost[c] = cst;
|
|
450
|
+
}
|
|
451
|
+
vector<int> pot = bot.dijkstra(bot.baseCells[me], cost);
|
|
452
|
+
int mv = bot.stepDown(from, pot, danger);
|
|
453
|
+
if (mv >= 0) { cmd[k].mv = MVC[mv]; post[myU[k]] = bot.cellAt(from, mv); }
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (task[k].type == T_FETCH) tgt = fis[task[k].target].cell;
|
|
457
|
+
else if (task[k].type == T_DEFEND || task[k].type == T_HUNT) {
|
|
458
|
+
int uid = task[k].target;
|
|
459
|
+
tgt = pos[uid];
|
|
460
|
+
if (tgt < 0) tgt = -1;
|
|
461
|
+
} else if (task[k].type == T_CAMP) tgt = task[k].target;
|
|
462
|
+
if (tgt < 0) continue;
|
|
463
|
+
for (int c = 0; c < S * S; c++) {
|
|
464
|
+
int dg = min(danger[c], 10);
|
|
465
|
+
int extra = 0;
|
|
466
|
+
// 避免与队友挤同一格
|
|
467
|
+
for (int j = 0; j < 3; j++) if (j != k && live[j] && pos[myU[j]] == c) extra += 12;
|
|
468
|
+
cost[c] = dg / 3 + extra;
|
|
469
|
+
}
|
|
470
|
+
vector<int> pot = bot.dijkstra(vector<int>{tgt}, cost);
|
|
471
|
+
int mv = bot.stepDown(from, pot, danger);
|
|
472
|
+
if (mv >= 0) { cmd[k].mv = MVC[mv]; post[myU[k]] = bot.cellAt(from, mv); }
|
|
473
|
+
(void)isCarrier;
|
|
474
|
+
}
|
|
475
|
+
// 队友撞车保护
|
|
476
|
+
for (int rep = 0; rep < 2; rep++) {
|
|
477
|
+
for (int a = 0; a < 3; a++) for (int b = a + 1; b < 3; b++) {
|
|
478
|
+
if (!live[a] || !live[b]) continue;
|
|
479
|
+
if (post[myU[a]] == post[myU[b]] && pos[myU[a]] != pos[myU[b]]) {
|
|
480
|
+
// 优先级:携旗 > 护卫 > 抢旗 > 其他
|
|
481
|
+
int lo = (carry[a] ? 0 : task[a].type == T_DEFEND ? 1 : task[a].type == T_FETCH ? 2 : 3);
|
|
482
|
+
int lb = (carry[b] ? 0 : task[b].type == T_DEFEND ? 1 : task[b].type == T_FETCH ? 2 : 3);
|
|
483
|
+
int lose = (lo >= lb) ? a : b;
|
|
484
|
+
cmd[lose].mv = 'S'; post[myU[lose]] = pos[myU[lose]];
|
|
485
|
+
}
|
|
486
|
+
if (post[myU[a]] == pos[myU[b]] && post[myU[b]] == pos[myU[a]] && cmd[a].mv != 'S' && cmd[b].mv != 'S') {
|
|
487
|
+
int lo = (carry[a] ? 0 : 3), lb = (carry[b] ? 0 : 3);
|
|
488
|
+
int lose = (lo >= lb) ? a : b;
|
|
489
|
+
cmd[lose].mv = 'S'; post[myU[lose]] = pos[myU[lose]];
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ---------- 动作 ----------
|
|
495
|
+
vector<char> acted(3, 0);
|
|
496
|
+
double pRetCell = 0;
|
|
497
|
+
if (nReturn > 0) pRetCell = (double)nReturn / (double)max(1, (int)bot.spotCells.size());
|
|
498
|
+
// 敌人优先级
|
|
499
|
+
vector<int> eprio(N, 0);
|
|
500
|
+
for (int i = 0; i < N; i++) {
|
|
501
|
+
if (g.units[i].team == me || !alive[i] || imm[i]) continue;
|
|
502
|
+
int pr = 0;
|
|
503
|
+
bool car = g.units[i].flag >= 0;
|
|
504
|
+
int need = hitsNeeded(g.units[i].hp);
|
|
505
|
+
if (car) pr += 100;
|
|
506
|
+
if (need == 1) pr += 60;
|
|
507
|
+
else if (need == 2) pr += 25;
|
|
508
|
+
pr += (g.hp - g.units[i].hp) / 4;
|
|
509
|
+
if (car) {
|
|
510
|
+
vector<int> eb = bot.bfs(bot.baseCells[g.units[i].team]);
|
|
511
|
+
int hd = eb[pos[i]];
|
|
512
|
+
if (hd >= 0) pr += max(0, 34 - 6 * hd);
|
|
513
|
+
}
|
|
514
|
+
eprio[i] = pr;
|
|
515
|
+
}
|
|
516
|
+
// 护卫目标额外加分
|
|
517
|
+
for (int k = 0; k < 3; k++) if (task[k].type == T_DEFEND) eprio[task[k].target] += 70;
|
|
518
|
+
for (int k = 0; k < 3; k++) if (task[k].type == T_HUNT) eprio[task[k].target] += 30;
|
|
519
|
+
|
|
520
|
+
struct Atk { int k, tgt, prio; };
|
|
521
|
+
vector<Atk> atks;
|
|
522
|
+
for (int k = 0; k < 3; k++) {
|
|
523
|
+
if (!live[k] || carry[k] || imm[myU[k]]) continue;
|
|
524
|
+
int px = post[myU[k]] % S, py = post[myU[k]] / S;
|
|
525
|
+
for (int i = 0; i < N; i++) {
|
|
526
|
+
if (g.units[i].team == me || !alive[i] || imm[i]) continue;
|
|
527
|
+
int tx = post[i] % S, ty = post[i] / S;
|
|
528
|
+
if (!bot.canAttack(px, py, tx, ty)) continue;
|
|
529
|
+
atks.push_back({k, i, eprio[i]});
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
sort(atks.begin(), atks.end(), [](const Atk& a, const Atk& b) { return a.prio > b.prio; });
|
|
533
|
+
// 是否有高价值目标可打(用于决定 P 还是攻击)
|
|
534
|
+
bool onFlagCell[3] = {false, false, false}, onSpotCell[3] = {false, false, false};
|
|
535
|
+
for (int k = 0; k < 3; k++) {
|
|
536
|
+
if (!live[k] || carry[k]) continue;
|
|
537
|
+
int c = post[myU[k]];
|
|
538
|
+
for (auto& f : g.flags) if ((f.status == "home" || f.status == "dropped") && f.x >= 0 && bot.cellOf(f.x, f.y) == c) { onFlagCell[k] = true; break; }
|
|
539
|
+
for (int s : bot.spotCells) if (s == c) { onSpotCell[k] = true; break; }
|
|
540
|
+
}
|
|
541
|
+
vector<int> assigned(N, 0);
|
|
542
|
+
for (int k = 0; k < 3; k++) {
|
|
543
|
+
if (!live[k] || carry[k] || imm[myU[k]]) continue;
|
|
544
|
+
// 该角色可用的最高优先级攻击
|
|
545
|
+
int bestT = -1, bestP = -1;
|
|
546
|
+
for (auto& a : atks) if (a.k == k) { if (a.prio > bestP) { bestP = a.prio; bestT = a.tgt; } }
|
|
547
|
+
bool wantAttack = false;
|
|
548
|
+
if (bestT >= 0) {
|
|
549
|
+
bool valuable = false;
|
|
550
|
+
if (eprio[bestT] >= 100 && hitsNeeded(g.units[bestT].hp) <= 1) valuable = true; // 能一击杀携旗者
|
|
551
|
+
if (g.units[bestT].flag >= 0 && hitsNeeded(g.units[bestT].hp) <= 1) valuable = true;
|
|
552
|
+
if (task[k].type == T_DEFEND && bestT == task[k].target) valuable = true;
|
|
553
|
+
if (onFlagCell[k]) valuable = true;
|
|
554
|
+
if (onSpotCell[k] && pRetCell > 0.05 && !valuable) valuable = false; // 站旗点待旗
|
|
555
|
+
else if (!onSpotCell[k]) valuable = true;
|
|
556
|
+
wantAttack = valuable;
|
|
557
|
+
}
|
|
558
|
+
if (wantAttack) {
|
|
559
|
+
int need = hitsNeeded(g.units[bestT].hp);
|
|
560
|
+
if (assigned[bestT] < need || bestP >= 100) {
|
|
561
|
+
cmd[k].act = to_string(bestT);
|
|
562
|
+
acted[k] = 1;
|
|
563
|
+
assigned[bestT]++;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (onFlagCell[k] || (onSpotCell[k] && pRetCell > 0.02)) { cmd[k].act = "P"; acted[k] = 1; }
|
|
568
|
+
}
|
|
569
|
+
// 剩余可攻击者补刀
|
|
570
|
+
for (auto& a : atks) {
|
|
571
|
+
if (acted[a.k] || cmd[a.k].act != "-") continue;
|
|
572
|
+
int need = hitsNeeded(g.units[a.tgt].hp);
|
|
573
|
+
if (assigned[a.tgt] >= need && a.prio < 100) continue;
|
|
574
|
+
cmd[a.k].act = to_string(a.tgt);
|
|
575
|
+
acted[a.k] = 1;
|
|
576
|
+
assigned[a.tgt]++;
|
|
577
|
+
}
|
|
578
|
+
// 站在棋点且没别的事:按 P
|
|
579
|
+
for (int k = 0; k < 3; k++) {
|
|
580
|
+
if (!live[k] || carry[k] || acted[k]) continue;
|
|
581
|
+
if (onFlagCell[k] || (onSpotCell[k] && pRetCell > 0.02)) { cmd[k].act = "P"; acted[k] = 1; }
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// ---------- 输出 ----------
|
|
585
|
+
string out = to_string(T);
|
|
586
|
+
for (int k = 0; k < 3; k++) { out += ' '; out += cmd[k].mv; out += ' '; out += cmd[k].act; }
|
|
587
|
+
out += " #";
|
|
588
|
+
for (int k = 0; k < 3; k++) {
|
|
589
|
+
if (k) out += ';';
|
|
590
|
+
if (!live[k]) out += "dead";
|
|
591
|
+
else if (carry[k]) out += "home";
|
|
592
|
+
else if (task[k].type == T_FETCH) out += "f" + to_string(task[k].target);
|
|
593
|
+
else if (task[k].type == T_DEFEND) out += "def";
|
|
594
|
+
else if (task[k].type == T_HUNT) out += "hunt";
|
|
595
|
+
else if (task[k].type == T_CAMP) out += "camp";
|
|
596
|
+
else out += "-";
|
|
597
|
+
}
|
|
598
|
+
cout << out << endl;
|
|
599
|
+
}
|
|
600
|
+
return 0;
|
|
601
|
+
}
|