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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# combat-prevent-retreat — Cut off the enemy's retreat path BEFORE
|
| 2 |
+
# engaging from the west (Wave-7 ACTION pack: encirclement / Cannae
|
| 3 |
+
# doctrine).
|
| 4 |
+
#
|
| 5 |
+
# Real-world anchors:
|
| 6 |
+
# - Military encirclement / Cannae doctrine: pin the enemy on the
|
| 7 |
+
# anvil and close the back door before the hammer falls, so the
|
| 8 |
+
# opposing force cannot exfiltrate when the engagement begins.
|
| 9 |
+
# - SC2 encirclement micro: a head-on attack from one bearing lets
|
| 10 |
+
# the enemy retreat toward their main base/regroup point; the
|
| 11 |
+
# winning play is to position a cut-off unit on the opposite side
|
| 12 |
+
# FIRST so the targets cannot exit the kill envelope.
|
| 13 |
+
# - "The hammer needs an anvil." A frontal hammer with no anvil
|
| 14 |
+
# just shoves the target back; the anvil makes the strike count.
|
| 15 |
+
#
|
| 16 |
+
# Mechanism (engine-load-bearing geometry — verified by scripted-policy
|
| 17 |
+
# smoke runs, all seeds 1–4 × every tier):
|
| 18 |
+
# - 4× medium tanks (2tnk) pre-placed at the west edge.
|
| 19 |
+
# - Mixed enemy infantry cluster at the centre column (x=60):
|
| 20 |
+
# easy 3× e1 + 2× e3 (5 enemies)
|
| 21 |
+
# medium 4× e1 + 3× e3 (7 enemies)
|
| 22 |
+
# hard 5× e1 + 3× e3 (8 enemies)
|
| 23 |
+
# `e3` (rocket infantry) is anti-armour and BITES tanks within ~5
|
| 24 |
+
# cells of the cluster — a frontal column charge through the cluster
|
| 25 |
+
# bleeds the tanks below the survival cap. e1 (small-arms ~3) is
|
| 26 |
+
# filler that makes up the kill bar so the cluster can't be one-
|
| 27 |
+
# shotted by overwhelming firepower.
|
| 28 |
+
# - The enemy is STATIONARY (no `bot_type`, default stance: return
|
| 29 |
+
# fire only). This is critical: a `hunt` bot would chase the lone
|
| 30 |
+
# cutoff tank as it flanks, breaking the off-axis safe-route
|
| 31 |
+
# assumption AND making the "stall lets the enemy walk into you"
|
| 32 |
+
# degeneracy trivially satisfiable.
|
| 33 |
+
# - The win predicate requires THREE things AT THE SAME EVALUATION:
|
| 34 |
+
# (1) `units_killed_gte: K` — all centre enemies dead
|
| 35 |
+
# (2) `units_in_region_gte:{85,20,r=8,n=1}` — cutoff tank present
|
| 36 |
+
# (3) `own_units_gte: 3` — at least 3 tanks alive
|
| 37 |
+
# plus `within_ticks: 4500` to deny stallers.
|
| 38 |
+
#
|
| 39 |
+
# Discrimination bar (six scripted-policy proxies in the test file;
|
| 40 |
+
# every level × every seed 1–4 must hold):
|
| 41 |
+
# • stall (only observe) → LOSS. No kills, no in-region,
|
| 42 |
+
# timeout fires.
|
| 43 |
+
# • brute attack_move-east-through-cluster (all 4 tanks toward 85,20)
|
| 44 |
+
# → LOSS. The column passes
|
| 45 |
+
# through the e3 cluster within Dragon range and loses ≥2 tanks
|
| 46 |
+
# en route → `own_units_gte:3` fails. The kill bar may or may not
|
| 47 |
+
# be met (depends on tier) but survival busts either way.
|
| 48 |
+
# • brute attack_move-centre (all 4 tanks toward 60,20) → LOSS.
|
| 49 |
+
# The column does engage and may even kill all centre enemies on
|
| 50 |
+
# easy/medium, BUT NO TANK IS IN THE EAST CUT-OFF REGION → the
|
| 51 |
+
# `units_in_region_gte` clause is never satisfied → after_ticks
|
| 52 |
+
# LOSS.
|
| 53 |
+
# • east-only (send ONE tank east, hold the rest) → LOSS. One tank
|
| 54 |
+
# can't kill the cluster; held tanks don't engage → kill bar
|
| 55 |
+
# fails. Even on easy with 5 enemies, a solo east tank can't
|
| 56 |
+
# pull the kill bar in the time budget.
|
| 57 |
+
# • intended cut-off-then-engage (NORTH route via y=5..10 OR SOUTH
|
| 58 |
+
# route via y=30..35) → WIN. The cutoff tank routes off-axis (out
|
| 59 |
+
# of e3 Dragon range), arrives at (85,20). The remaining 3 tanks
|
| 60 |
+
# attack-move the centre, kill the e1+e3 cluster, lose at most 1
|
| 61 |
+
# tank (well within `own_units_gte:3`). Kill bar AND in-region AND
|
| 62 |
+
# survival all satisfied → WIN.
|
| 63 |
+
#
|
| 64 |
+
# Engine guardrails (per CLAUDE.md):
|
| 65 |
+
# - Map: rush-hour-arena (128 × 40, playable x ∈ [2..126], y ∈ [2..38]).
|
| 66 |
+
# - All declared cells are well within playable bounds.
|
| 67 |
+
# - Persistent unarmed enemy `fact` at (120, 4) keeps the episode
|
| 68 |
+
# alive past the moment the cluster is wiped (otherwise the
|
| 69 |
+
# engine would auto-`done` on enemy-elimination before the
|
| 70 |
+
# `units_in_region_gte` predicate evaluates).
|
| 71 |
+
# - Per CLAUDE.md (60,20) is not on the silent-fail list (the cited
|
| 72 |
+
# problems are (50,20), (60,28), (90,30)); the e1/e3 cluster
|
| 73 |
+
# spans (60, 16..23) on hard, no member at a known-bad cell.
|
| 74 |
+
# - All deadlines (`after_ticks 4501`) are reachable within max_turns
|
| 75 |
+
# (~90 ticks/turn ⇒ tick ≤ 93 + 90·(max_turns−1) = 5403 on
|
| 76 |
+
# max_turns 60) ⇒ no draw degeneracy.
|
| 77 |
+
# - `spawn_point` filter applies ONLY to agent actors; the enemy
|
| 78 |
+
# cluster + east sentinel `fact` have no spawn_point so they
|
| 79 |
+
# ALWAYS place. On hard, both NORTH and SOUTH agent groups
|
| 80 |
+
# declare spawn_point so only ONE is selected per seed.
|
| 81 |
+
|
| 82 |
+
meta:
|
| 83 |
+
id: combat-prevent-retreat
|
| 84 |
+
title: 'Combat Encirclement — Cut Off the Enemy''s Retreat Before You Strike'
|
| 85 |
+
capability: action
|
| 86 |
+
real_world_meaning: >
|
| 87 |
+
A cluster of enemy rifle + rocket infantry sits at the centre of
|
| 88 |
+
the map. A head-on column charge brings every tank within rocket
|
| 89 |
+
range of the cluster and bleeds the strike force below the
|
| 90 |
+
survival cap. The winning play is the Cannae / encirclement
|
| 91 |
+
idiom: detach ONE tank on a flank route (around the enemy cluster
|
| 92 |
+
via y=5..10 or y=30..35, out of rocket range) to take the eastern
|
| 93 |
+
anvil position at (85,20), then commit the main body of THREE
|
| 94 |
+
tanks from the west. The win predicate explicitly requires the
|
| 95 |
+
agent to have ESTABLISHED an eastern cut-off (≥1 own unit at
|
| 96 |
+
(85,20,r=8)) at the moment the kill bar is met AND to have ≥3
|
| 97 |
+
tanks alive. Brute charging without the cut-off either bleeds
|
| 98 |
+
the force under the survival cap (attack-move east through the
|
| 99 |
+
cluster) or wins the centre fight with no tank east (attack-move
|
| 100 |
+
to the centre) — both LOSE. Stalling never opens fire, also a
|
| 101 |
+
LOSS on the clock.
|
| 102 |
+
robotics_analogue: >
|
| 103 |
+
Multi-agent strike geometry: the placement of a "blocker" /
|
| 104 |
+
"anvil" unit on the opposite side of the target BEFORE the main
|
| 105 |
+
engagement opens is what converts a shove into a kill. The
|
| 106 |
+
decision under test is spatial sequencing — establish the cut-
|
| 107 |
+
off via a path that avoids the enemy's effective weapon envelope,
|
| 108 |
+
THEN engage; reversing the order forfeits the capability that
|
| 109 |
+
the cut-off enables.
|
| 110 |
+
benchmark_anchor:
|
| 111 |
+
- "military encirclement"
|
| 112 |
+
- "Cannae doctrine"
|
| 113 |
+
- "SC2 encirclement"
|
| 114 |
+
- "the hammer needs an anvil"
|
| 115 |
+
author: openra-bench
|
| 116 |
+
|
| 117 |
+
base_map: rush-hour-arena
|
| 118 |
+
|
| 119 |
+
base:
|
| 120 |
+
agent: {faction: allies, cash: 0}
|
| 121 |
+
enemy: {faction: soviet, cash: 0}
|
| 122 |
+
tools: [move_units, attack_unit, attack_move, stop]
|
| 123 |
+
planning: true
|
| 124 |
+
# React the instant a tank is lost or an enemy unit is spotted —
|
| 125 |
+
# the encirclement is reactive; without these the policy only
|
| 126 |
+
# re-targets on the next turn boundary.
|
| 127 |
+
interrupts:
|
| 128 |
+
enemy_unit_spotted: true
|
| 129 |
+
own_unit_destroyed: true
|
| 130 |
+
termination: {max_ticks: 6000}
|
| 131 |
+
actors: []
|
| 132 |
+
|
| 133 |
+
levels:
|
| 134 |
+
# ── EASY ──────────────────────────────────────────────────────────
|
| 135 |
+
# Bare encirclement skill: 5-unit cluster (3× e1 + 2× e3 anti-armour)
|
| 136 |
+
# at the centre. The 2× e3 are enough to punish a frontal-column
|
| 137 |
+
# charge but not enough to overwhelm 3 attacking tanks from the
|
| 138 |
+
# west. Generous tick budget.
|
| 139 |
+
easy:
|
| 140 |
+
description: >
|
| 141 |
+
Four medium tanks (2tnk) stage at the west edge (x=6, y=18..21).
|
| 142 |
+
A five-unit enemy infantry cluster holds the centre at (60,
|
| 143 |
+
y=18..22): 3× e1 (rifle, small-arms) + 2× e3 (rocket, anti-
|
| 144 |
+
armour). To win the encirclement you must POSITION ≥1 tank in
|
| 145 |
+
the east cut-off region (85, 20, r=8) AND kill all 5 enemies
|
| 146 |
+
AND keep ≥3 tanks alive, before tick 4500. Detach ONE tank on
|
| 147 |
+
a flank route (via y=5..10 or y=30..35 to stay out of e3
|
| 148 |
+
Dragon range) and run it east to (85, 20); engage the centre
|
| 149 |
+
with the remaining THREE tanks. A head-on attack-move-east
|
| 150 |
+
through the cluster bleeds tanks below the survival cap and
|
| 151 |
+
LOSES; an attack-move-centre kills the e1+e3 but no tank
|
| 152 |
+
reaches the east region — also LOSES. Stall LOSES on the
|
| 153 |
+
clock.
|
| 154 |
+
overrides:
|
| 155 |
+
actors:
|
| 156 |
+
# Strike force — 4 medium tanks staged at the west edge.
|
| 157 |
+
# Stance:1 ReturnFire so they don't auto-charge across the
|
| 158 |
+
# map and break the agent's positional plan.
|
| 159 |
+
- {type: 2tnk, owner: agent, position: [6, 18], stance: 1}
|
| 160 |
+
- {type: 2tnk, owner: agent, position: [6, 19], stance: 1}
|
| 161 |
+
- {type: 2tnk, owner: agent, position: [6, 20], stance: 1}
|
| 162 |
+
- {type: 2tnk, owner: agent, position: [6, 21], stance: 1}
|
| 163 |
+
# ENEMY centre cluster — 3× e1 + 2× e3. Stationary defenders
|
| 164 |
+
# (no bot_type); stance defaults to return-fire when attacked.
|
| 165 |
+
- {type: e1, owner: enemy, position: [60, 18]}
|
| 166 |
+
- {type: e3, owner: enemy, position: [60, 19]}
|
| 167 |
+
- {type: e1, owner: enemy, position: [60, 20]}
|
| 168 |
+
- {type: e3, owner: enemy, position: [60, 21]}
|
| 169 |
+
- {type: e1, owner: enemy, position: [60, 22]}
|
| 170 |
+
# SENTINEL — unarmed enemy `fact` far in the north corner.
|
| 171 |
+
# Keeps the episode alive past enemy-cluster elimination so
|
| 172 |
+
# the in-region predicate evaluates on the terminal frame
|
| 173 |
+
# (per CLAUDE.md: without a persistent enemy actor the
|
| 174 |
+
# engine auto-`done`s on enemy-wipe and collapses to DRAW).
|
| 175 |
+
- {type: fact, owner: enemy, position: [120, 4]}
|
| 176 |
+
win_condition:
|
| 177 |
+
all_of:
|
| 178 |
+
- {units_killed_gte: 5}
|
| 179 |
+
- {units_in_region_gte: {x: 85, y: 20, radius: 8, n: 1}}
|
| 180 |
+
- {own_units_gte: 3}
|
| 181 |
+
- {within_ticks: 4500}
|
| 182 |
+
fail_condition:
|
| 183 |
+
any_of:
|
| 184 |
+
- {after_ticks: 4501}
|
| 185 |
+
- {not: {own_units_gte: 3}}
|
| 186 |
+
max_turns: 60
|
| 187 |
+
|
| 188 |
+
# ── MEDIUM ────────────────────────────────────────────────────────
|
| 189 |
+
# +1 controlled variable vs easy: the enemy cluster gains TWO more
|
| 190 |
+
# units (one e1 + one e3 → 7 total at y=17..23). Kill bar 7 makes
|
| 191 |
+
# the east-only solo-tank play decisively too slow; the e3 density
|
| 192 |
+
# makes brute-charge-east decisively bleed.
|
| 193 |
+
medium:
|
| 194 |
+
description: >
|
| 195 |
+
Four medium tanks (2tnk) stage at the west edge (x=6, y=18..21).
|
| 196 |
+
A seven-unit enemy infantry cluster holds the centre at (60,
|
| 197 |
+
y=17..23): 4× e1 + 3× e3 (rocket anti-armour). To win you must
|
| 198 |
+
POSITION ≥1 tank in the east cut-off region (85, 20, r=8) AND
|
| 199 |
+
kill all 7 enemies AND keep ≥3 tanks alive, before tick 4500.
|
| 200 |
+
Detach ONE tank on a flank route (via y=5..10 or y=30..35) and
|
| 201 |
+
run it east to (85, 20); engage the centre with the remaining
|
| 202 |
+
three. Head-on, east-only, and stall all LOSE.
|
| 203 |
+
overrides:
|
| 204 |
+
actors:
|
| 205 |
+
- {type: 2tnk, owner: agent, position: [6, 18], stance: 1}
|
| 206 |
+
- {type: 2tnk, owner: agent, position: [6, 19], stance: 1}
|
| 207 |
+
- {type: 2tnk, owner: agent, position: [6, 20], stance: 1}
|
| 208 |
+
- {type: 2tnk, owner: agent, position: [6, 21], stance: 1}
|
| 209 |
+
- {type: e1, owner: enemy, position: [60, 17]}
|
| 210 |
+
- {type: e3, owner: enemy, position: [60, 18]}
|
| 211 |
+
- {type: e1, owner: enemy, position: [60, 19]}
|
| 212 |
+
- {type: e3, owner: enemy, position: [60, 20]}
|
| 213 |
+
- {type: e1, owner: enemy, position: [60, 21]}
|
| 214 |
+
- {type: e3, owner: enemy, position: [60, 22]}
|
| 215 |
+
- {type: e1, owner: enemy, position: [60, 23]}
|
| 216 |
+
- {type: fact, owner: enemy, position: [120, 4]}
|
| 217 |
+
win_condition:
|
| 218 |
+
all_of:
|
| 219 |
+
- {units_killed_gte: 7}
|
| 220 |
+
- {units_in_region_gte: {x: 85, y: 20, radius: 8, n: 1}}
|
| 221 |
+
- {own_units_gte: 3}
|
| 222 |
+
- {within_ticks: 4500}
|
| 223 |
+
fail_condition:
|
| 224 |
+
any_of:
|
| 225 |
+
- {after_ticks: 4501}
|
| 226 |
+
- {not: {own_units_gte: 3}}
|
| 227 |
+
max_turns: 60
|
| 228 |
+
|
| 229 |
+
# ── HARD ──────────────────────────────────────────────────────────
|
| 230 |
+
# +1 controlled variable vs medium: TWO seed-driven agent spawn_point
|
| 231 |
+
# groups (NORTH staging y=12..15 OR SOUTH staging y=25..28),
|
| 232 |
+
# round-robined by seed so the natural flank corridor flips per
|
| 233 |
+
# seed (a memorised "always flank via the north" opening cannot
|
| 234 |
+
# generalise). The enemy cluster is symmetric across y=20 (y=16..23)
|
| 235 |
+
# so both spawns face the same encirclement geometry. The hard tier
|
| 236 |
+
# also adds one more e1 to the cluster (kill bar 8).
|
| 237 |
+
#
|
| 238 |
+
# Per the CLAUDE.md `spawn_point` contract: ALL agent actors carry
|
| 239 |
+
# an explicit spawn_point (the filter applies only to agent actors);
|
| 240 |
+
# the enemy actors are unchanged and always place.
|
| 241 |
+
hard:
|
| 242 |
+
description: >
|
| 243 |
+
Four medium tanks (2tnk) stage at ONE of two west-edge corridors
|
| 244 |
+
(NORTH y=12..15 OR SOUTH y=25..28, chosen by seed, anti-
|
| 245 |
+
memorisation). An eight-unit enemy infantry cluster holds the
|
| 246 |
+
centre at (60, y=16..23): 5× e1 + 3× e3 (rocket anti-armour).
|
| 247 |
+
To win you must POSITION ≥1 tank in the east cut-off region
|
| 248 |
+
(85, 20, r=8) AND kill all 8 enemies AND keep ≥3 tanks alive,
|
| 249 |
+
before tick 4500. From the NORTH spawn run the cutoff tank via
|
| 250 |
+
y=5..10 to (85, 20); from the SOUTH spawn run it via y=30..35.
|
| 251 |
+
Engage the centre with the remaining three tanks descending
|
| 252 |
+
onto the cluster from the staging latitude. Head-on, east-only,
|
| 253 |
+
and stall all LOSE on every seed.
|
| 254 |
+
overrides:
|
| 255 |
+
actors:
|
| 256 |
+
# spawn_point 0 — NORTH staging corridor (y=12..15). Already
|
| 257 |
+
# off-axis from the e1/e3 cluster (e3 Dragon range ~5, so a
|
| 258 |
+
# tank at y=5..10 transiting east at x=20..80 stays out of
|
| 259 |
+
# cluster fire from the y=16..23 cluster).
|
| 260 |
+
- {type: 2tnk, owner: agent, position: [6, 12], stance: 1, spawn_point: 0}
|
| 261 |
+
- {type: 2tnk, owner: agent, position: [6, 13], stance: 1, spawn_point: 0}
|
| 262 |
+
- {type: 2tnk, owner: agent, position: [6, 14], stance: 1, spawn_point: 0}
|
| 263 |
+
- {type: 2tnk, owner: agent, position: [6, 15], stance: 1, spawn_point: 0}
|
| 264 |
+
# spawn_point 1 — SOUTH staging corridor (y=25..28). Mirror.
|
| 265 |
+
- {type: 2tnk, owner: agent, position: [6, 25], stance: 1, spawn_point: 1}
|
| 266 |
+
- {type: 2tnk, owner: agent, position: [6, 26], stance: 1, spawn_point: 1}
|
| 267 |
+
- {type: 2tnk, owner: agent, position: [6, 27], stance: 1, spawn_point: 1}
|
| 268 |
+
- {type: 2tnk, owner: agent, position: [6, 28], stance: 1, spawn_point: 1}
|
| 269 |
+
# 8× cluster symmetric across y=20 at the centre.
|
| 270 |
+
- {type: e1, owner: enemy, position: [60, 16]}
|
| 271 |
+
- {type: e3, owner: enemy, position: [60, 17]}
|
| 272 |
+
- {type: e1, owner: enemy, position: [60, 18]}
|
| 273 |
+
- {type: e3, owner: enemy, position: [60, 19]}
|
| 274 |
+
- {type: e1, owner: enemy, position: [60, 20]}
|
| 275 |
+
- {type: e3, owner: enemy, position: [60, 21]}
|
| 276 |
+
- {type: e1, owner: enemy, position: [60, 22]}
|
| 277 |
+
- {type: e1, owner: enemy, position: [60, 23]}
|
| 278 |
+
- {type: fact, owner: enemy, position: [120, 4]}
|
| 279 |
+
win_condition:
|
| 280 |
+
all_of:
|
| 281 |
+
- {units_killed_gte: 8}
|
| 282 |
+
- {units_in_region_gte: {x: 85, y: 20, radius: 8, n: 1}}
|
| 283 |
+
- {own_units_gte: 3}
|
| 284 |
+
- {within_ticks: 4500}
|
| 285 |
+
fail_condition:
|
| 286 |
+
any_of:
|
| 287 |
+
- {after_ticks: 4501}
|
| 288 |
+
- {not: {own_units_gte: 3}}
|
| 289 |
+
max_turns: 60
|
tests/test_combat_prevent_retreat.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""combat-prevent-retreat — cut-off encirclement before engaging.
|
| 2 |
+
|
| 3 |
+
The bar: 4× medium tanks (2tnk) start at the west edge; a mixed e1+e3
|
| 4 |
+
infantry cluster holds the centre (60, 16..23). The win predicate
|
| 5 |
+
requires:
|
| 6 |
+
|
| 7 |
+
• `units_killed_gte: K` — the full cluster wiped
|
| 8 |
+
(K=5 easy / 7 medium / 8 hard)
|
| 9 |
+
• `units_in_region_gte:{85,20,r=8,n=1}` — ≥1 own tank in the east
|
| 10 |
+
cut-off region at evaluation time
|
| 11 |
+
• `own_units_gte: 3` — at least 3 tanks survive
|
| 12 |
+
• `within_ticks: 4500` — stallers can't draw
|
| 13 |
+
|
| 14 |
+
This combination forces the Cannae idiom: ONE flank tank routes
|
| 15 |
+
off-axis (via y=5..10 from a NORTH spawn or y=30..35 from a SOUTH
|
| 16 |
+
spawn, out of e3 Dragon range) to take the eastern anvil; the
|
| 17 |
+
remaining THREE engage the centre from the west. The cluster's
|
| 18 |
+
anti-armour e3s punish a head-on column charge (`brute_east` loses
|
| 19 |
+
≥2 tanks → survival cap busts); a centre-only charge leaves no tank
|
| 20 |
+
east (in-region clause fails); a solo east tank can't pull the kill
|
| 21 |
+
bar in budget.
|
| 22 |
+
|
| 23 |
+
Discrimination (verified per-level × per-seed 1–4):
|
| 24 |
+
|
| 25 |
+
• stall (observe-only) — LOSS on every level/seed
|
| 26 |
+
(no kills, deadline fires).
|
| 27 |
+
• brute_east (attack_move all to 85,20)
|
| 28 |
+
— LOSS: column bled by e3
|
| 29 |
+
Dragons; survival cap busts.
|
| 30 |
+
• brute_centre (attack_move all to 60,20)
|
| 31 |
+
— LOSS: cluster killed but
|
| 32 |
+
no tank east → in-region
|
| 33 |
+
clause fails → after_ticks.
|
| 34 |
+
• east_only (move 1 east, hold rest)— LOSS: kill bar never met
|
| 35 |
+
(1 tank vs cluster too slow).
|
| 36 |
+
• intended (cut-off then engage) — WIN every level/seed.
|
| 37 |
+
|
| 38 |
+
Validation is scripted (no model / network)."""
|
| 39 |
+
from __future__ import annotations
|
| 40 |
+
|
| 41 |
+
from pathlib import Path
|
| 42 |
+
|
| 43 |
+
import pytest
|
| 44 |
+
|
| 45 |
+
pytest.importorskip("openra_rl_training", reason="Rust env wheel not installed")
|
| 46 |
+
from openra_bench.scenarios import load_pack
|
| 47 |
+
from openra_bench.scenarios.loader import compile_level
|
| 48 |
+
from openra_bench.scenarios.win_conditions import WinContext, evaluate
|
| 49 |
+
|
| 50 |
+
PACKS = Path(__file__).parent.parent / "openra_bench" / "scenarios" / "packs"
|
| 51 |
+
PACK_PATH = PACKS / "combat-prevent-retreat.yaml"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# ── unit-level predicate / metadata checks (no engine) ──────────────
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_pack_compiles_and_meta_fields_populated():
|
| 58 |
+
pack = load_pack(PACK_PATH)
|
| 59 |
+
assert pack.meta.id == "combat-prevent-retreat"
|
| 60 |
+
assert pack.meta.capability == "action"
|
| 61 |
+
assert pack.meta.real_world_meaning, "real_world_meaning required"
|
| 62 |
+
assert pack.meta.robotics_analogue, "robotics_analogue required"
|
| 63 |
+
anchors = pack.meta.benchmark_anchor
|
| 64 |
+
assert isinstance(anchors, list) and len(anchors) >= 3, (
|
| 65 |
+
f"benchmark_anchor must list ≥3 anchors, got {anchors!r}"
|
| 66 |
+
)
|
| 67 |
+
joined = " ".join(anchors).lower()
|
| 68 |
+
for needle in ("encirclement", "cannae", "sc2"):
|
| 69 |
+
assert needle in joined, f"missing anchor keyword: {needle}"
|
| 70 |
+
for lvl in ("easy", "medium", "hard"):
|
| 71 |
+
c = compile_level(pack, lvl)
|
| 72 |
+
assert c.map_supported
|
| 73 |
+
assert c.win_condition is not None
|
| 74 |
+
assert c.fail_condition is not None
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _ctx(*, units=(), tick=1000, kills=0, lost=0):
|
| 78 |
+
"""Synthesize a WinContext for predicate-level checks."""
|
| 79 |
+
import types
|
| 80 |
+
|
| 81 |
+
sig = types.SimpleNamespace(
|
| 82 |
+
game_tick=tick,
|
| 83 |
+
units_killed=kills,
|
| 84 |
+
units_lost=lost,
|
| 85 |
+
cash=0,
|
| 86 |
+
resources=0,
|
| 87 |
+
power_provided=0,
|
| 88 |
+
power_drained=0,
|
| 89 |
+
own_buildings=[],
|
| 90 |
+
own_building_types=set(),
|
| 91 |
+
enemies_seen_ids=set(),
|
| 92 |
+
enemy_buildings_seen_ids=set(),
|
| 93 |
+
explored_percent=0.0,
|
| 94 |
+
then_progress={},
|
| 95 |
+
seq_progress={},
|
| 96 |
+
)
|
| 97 |
+
return WinContext(
|
| 98 |
+
signals=sig,
|
| 99 |
+
render_state={"units_summary": list(units)},
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def _tanks_at(n, x=85, y=20):
|
| 104 |
+
return [
|
| 105 |
+
{"cell_x": x, "cell_y": y, "type": "2tnk", "id": str(2000 + i)}
|
| 106 |
+
for i in range(n)
|
| 107 |
+
]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_predicates_per_level():
|
| 111 |
+
"""Region n=1 + kill bar + survival cap + deadline all load-bearing."""
|
| 112 |
+
pack = load_pack(PACK_PATH)
|
| 113 |
+
# (kill_bar, surv_min, within, after_fail)
|
| 114 |
+
expectations = {
|
| 115 |
+
"easy": (5, 3, 4500, 4501),
|
| 116 |
+
"medium": (7, 3, 4500, 4501),
|
| 117 |
+
"hard": (8, 3, 4500, 4501),
|
| 118 |
+
}
|
| 119 |
+
for lvl, (kb, surv, w, af) in expectations.items():
|
| 120 |
+
c = compile_level(pack, lvl)
|
| 121 |
+
# Intended win: ≥1 tank in east region + kill bar + ≥surv alive.
|
| 122 |
+
ctx_win = _ctx(units=_tanks_at(surv), tick=w - 100, kills=kb, lost=4 - surv)
|
| 123 |
+
assert evaluate(c.win_condition, ctx_win), f"{lvl}: intended should WIN"
|
| 124 |
+
# No tank in east region → in-region clause unmet.
|
| 125 |
+
ctx_no_east = _ctx(
|
| 126 |
+
units=[{"cell_x": 60, "cell_y": 20, "type": "2tnk", "id": str(3000 + i)}
|
| 127 |
+
for i in range(surv)],
|
| 128 |
+
tick=w - 100, kills=kb, lost=4 - surv,
|
| 129 |
+
)
|
| 130 |
+
assert not evaluate(c.win_condition, ctx_no_east), (
|
| 131 |
+
f"{lvl}: 0 tanks in east region must not satisfy win"
|
| 132 |
+
)
|
| 133 |
+
# Kill bar unmet → not a win.
|
| 134 |
+
ctx_low_kills = _ctx(units=_tanks_at(surv), tick=w - 100, kills=kb - 1, lost=0)
|
| 135 |
+
assert not evaluate(c.win_condition, ctx_low_kills), (
|
| 136 |
+
f"{lvl}: kills < {kb} must not satisfy win"
|
| 137 |
+
)
|
| 138 |
+
# Survival cap busted → not a win + fails.
|
| 139 |
+
ctx_lost = _ctx(units=_tanks_at(surv - 1), tick=w - 100, kills=kb, lost=4 - surv + 1)
|
| 140 |
+
assert not evaluate(c.win_condition, ctx_lost)
|
| 141 |
+
assert evaluate(c.fail_condition, ctx_lost), (
|
| 142 |
+
f"{lvl}: survival<{surv} must FAIL"
|
| 143 |
+
)
|
| 144 |
+
# Timeout busted → fails.
|
| 145 |
+
ctx_late = _ctx(units=_tanks_at(surv), tick=af + 1, kills=kb, lost=0)
|
| 146 |
+
assert evaluate(c.fail_condition, ctx_late), (
|
| 147 |
+
f"{lvl}: tick>after must FAIL"
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def test_timeout_reachable_inside_max_turns():
|
| 152 |
+
"""No DRAW degeneracy: after_ticks fail trigger must be reachable
|
| 153 |
+
within max_turns (engine advances ~90 ticks per turn ⇒ max tick
|
| 154 |
+
≈ 93 + 90·(max_turns-1))."""
|
| 155 |
+
pack = load_pack(PACK_PATH)
|
| 156 |
+
for lvl in ("easy", "medium", "hard"):
|
| 157 |
+
c = compile_level(pack, lvl)
|
| 158 |
+
max_tick = 93 + 90 * (c.max_turns - 1)
|
| 159 |
+
assert 4501 <= max_tick, (
|
| 160 |
+
f"{lvl}: after_ticks 4501 > max reachable tick {max_tick} "
|
| 161 |
+
f"(max_turns={c.max_turns}); deadline never bites"
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def test_tanks_are_2tnk_and_west_edge():
|
| 166 |
+
"""Agent strike force is 4× 2tnk at the west edge (x=6) on every
|
| 167 |
+
level — the encirclement geometry is load-bearing."""
|
| 168 |
+
pack = load_pack(PACK_PATH)
|
| 169 |
+
for lvl in ("easy", "medium", "hard"):
|
| 170 |
+
c = compile_level(pack, lvl)
|
| 171 |
+
agent = [a for a in c.scenario.actors if a.owner == "agent"]
|
| 172 |
+
for a in agent:
|
| 173 |
+
assert a.type == "2tnk", f"{lvl}: agent must be 2tnk; got {a.type}"
|
| 174 |
+
assert a.position[0] == 6, (
|
| 175 |
+
f"{lvl}: agent must start at x=6 (west edge); got {a.position}"
|
| 176 |
+
)
|
| 177 |
+
# Easy/medium: 4 tanks. Hard: 4 per spawn_point (8 declared
|
| 178 |
+
# actors total, but only one spawn_point group places per seed).
|
| 179 |
+
if lvl == "hard":
|
| 180 |
+
assert len(agent) == 8, f"hard: declares 4 tanks × 2 spawn_points = 8"
|
| 181 |
+
else:
|
| 182 |
+
assert len(agent) == 4, f"{lvl}: 4 tanks expected; got {len(agent)}"
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def test_enemy_cluster_e1_plus_e3_mix():
|
| 186 |
+
"""The centre cluster mixes e1 (filler) + e3 (anti-armour). The
|
| 187 |
+
e3 component is load-bearing — without it a brute attack-move
|
| 188 |
+
column charge wouldn't bleed below the survival cap."""
|
| 189 |
+
pack = load_pack(PACK_PATH)
|
| 190 |
+
for lvl in ("easy", "medium", "hard"):
|
| 191 |
+
c = compile_level(pack, lvl)
|
| 192 |
+
cluster = [
|
| 193 |
+
a for a in c.scenario.actors
|
| 194 |
+
if a.owner == "enemy" and a.type in ("e1", "e3")
|
| 195 |
+
]
|
| 196 |
+
assert cluster, f"{lvl}: no central cluster declared"
|
| 197 |
+
e3 = [a for a in cluster if a.type == "e3"]
|
| 198 |
+
assert len(e3) >= 2, (
|
| 199 |
+
f"{lvl}: cluster needs ≥2 e3 to bleed a frontal column charge; "
|
| 200 |
+
f"got {len(e3)}"
|
| 201 |
+
)
|
| 202 |
+
# No cluster member at a known silently-no-place cell.
|
| 203 |
+
for a in cluster:
|
| 204 |
+
assert tuple(a.position) != (50, 20), (
|
| 205 |
+
f"{lvl}: cluster member at (50,20) — CLAUDE.md no-place footgun"
|
| 206 |
+
)
|
| 207 |
+
assert a.position[0] == 60, (
|
| 208 |
+
f"{lvl}: cluster member off-column; got {a.position}"
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def test_persistent_far_enemy_marker_present():
|
| 213 |
+
"""Engine auto-`done` mitigation: a far unarmed enemy `fact` keeps
|
| 214 |
+
the episode alive past full cluster elimination so the in-region
|
| 215 |
+
predicate evaluates on the terminal frame (no DRAW collapse)."""
|
| 216 |
+
pack = load_pack(PACK_PATH)
|
| 217 |
+
for lvl in ("easy", "medium", "hard"):
|
| 218 |
+
c = compile_level(pack, lvl)
|
| 219 |
+
far_facts = [
|
| 220 |
+
a for a in c.scenario.actors
|
| 221 |
+
if a.owner == "enemy" and a.type == "fact"
|
| 222 |
+
and a.position[0] >= 100
|
| 223 |
+
]
|
| 224 |
+
assert far_facts, f"{lvl}: needs a far persistent enemy fact sentinel"
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def test_enemy_is_static_no_bot_type():
|
| 228 |
+
"""Enemies are stationary defenders (no `bot_type`) — a hunt bot
|
| 229 |
+
would chase the lone cutoff tank as it flanks, breaking the
|
| 230 |
+
off-axis safe-route assumption AND letting a staller win when
|
| 231 |
+
enemies walk into the tanks."""
|
| 232 |
+
pack = load_pack(PACK_PATH)
|
| 233 |
+
enemy = pack.base.get("enemy") if isinstance(pack.base, dict) else getattr(pack.base, "enemy", {})
|
| 234 |
+
assert (enemy or {}).get("bot_type") is None, (
|
| 235 |
+
"enemy must not declare a bot_type — see file header docstring"
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def test_hard_has_two_spawn_point_groups():
|
| 240 |
+
"""Hard-tier curation: ≥2 distinct agent spawn_point groups so the
|
| 241 |
+
seed round-robins which staging corridor (north y=12 or south y=28)
|
| 242 |
+
the tank column starts in. The natural flank route flips per seed
|
| 243 |
+
so no memorised opening generalises."""
|
| 244 |
+
c = compile_level(load_pack(PACK_PATH), "hard")
|
| 245 |
+
groups = {
|
| 246 |
+
(a.spawn_point if a.spawn_point is not None else 0)
|
| 247 |
+
for a in c.scenario.actors
|
| 248 |
+
if a.owner == "agent"
|
| 249 |
+
}
|
| 250 |
+
assert len(groups) >= 2, f"hard needs ≥2 spawn_point groups, got {groups}"
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
# ── engine-driven scripted policies ─────────────────────────────────
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _tank_ids(rs):
|
| 257 |
+
return [
|
| 258 |
+
str(u["id"])
|
| 259 |
+
for u in (rs.get("units_summary") or [])
|
| 260 |
+
if str(u.get("type", "")).lower() == "2tnk"
|
| 261 |
+
]
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def _stall(rs, Command):
|
| 265 |
+
"""Pure observe — no kills, no in-region, deadline LOSS."""
|
| 266 |
+
return [Command.observe()]
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def _brute_east(rs, Command):
|
| 270 |
+
"""All 4 tanks attack-move EAST through the cluster toward (85,20).
|
| 271 |
+
The column passes within e3 Dragon range and bleeds below the
|
| 272 |
+
survival cap → LOSS on every level."""
|
| 273 |
+
ids = _tank_ids(rs)
|
| 274 |
+
return [Command.attack_move(ids, 85, 20)] if ids else [Command.observe()]
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def _brute_centre(rs, Command):
|
| 278 |
+
"""All 4 tanks attack-move the centre cluster at (60,20). May clear
|
| 279 |
+
the cluster (kills bar met) but NO TANK IS IN THE EAST REGION at
|
| 280 |
+
evaluation time → in-region clause fails → after_ticks LOSS."""
|
| 281 |
+
ids = _tank_ids(rs)
|
| 282 |
+
return [Command.attack_move(ids, 60, 20)] if ids else [Command.observe()]
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def _east_only(rs, Command):
|
| 286 |
+
"""Send ONLY one tank east, hold the rest. The solo east tank
|
| 287 |
+
can't pull the kill bar in budget; held tanks don't engage →
|
| 288 |
+
kill bar fails → LOSS."""
|
| 289 |
+
ids = _tank_ids(rs)
|
| 290 |
+
if not ids:
|
| 291 |
+
return [Command.observe()]
|
| 292 |
+
return [
|
| 293 |
+
Command.move_units([ids[0]], target_x=85, target_y=20),
|
| 294 |
+
Command.stop(ids[1:]),
|
| 295 |
+
]
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def _make_intended():
|
| 299 |
+
"""Cannae intended play. Pick the off-axis safe latitude based on
|
| 300 |
+
the actual spawn (NORTH spawn → off-y=5; SOUTH spawn → off-y=35),
|
| 301 |
+
pick the cutoff tank closest to that latitude, route it via three
|
| 302 |
+
waypoints out of e3 Dragon range to (85,20). The remaining three
|
| 303 |
+
tanks attack-move the centre cluster from the west."""
|
| 304 |
+
state = {}
|
| 305 |
+
|
| 306 |
+
def policy(rs, Command):
|
| 307 |
+
units = [
|
| 308 |
+
u for u in (rs.get("units_summary") or [])
|
| 309 |
+
if str(u.get("type", "")).lower() == "2tnk"
|
| 310 |
+
]
|
| 311 |
+
if not units:
|
| 312 |
+
return [Command.observe()]
|
| 313 |
+
if "off_y" not in state:
|
| 314 |
+
avg = sum(int(u["cell_y"]) for u in units) / len(units)
|
| 315 |
+
state["off_y"] = 5 if avg < 20 else 35
|
| 316 |
+
us = sorted(units, key=lambda u: abs(int(u["cell_y"]) - state["off_y"]))
|
| 317 |
+
state["cutoff"] = str(us[0]["id"])
|
| 318 |
+
state["phase"] = 0
|
| 319 |
+
cmds = []
|
| 320 |
+
cutoff = state["cutoff"]
|
| 321 |
+
cu = next((u for u in units if str(u["id"]) == cutoff), None)
|
| 322 |
+
others = [str(u["id"]) for u in units if str(u["id"]) != cutoff]
|
| 323 |
+
off_y = state["off_y"]
|
| 324 |
+
if cu is not None:
|
| 325 |
+
cx, cy = int(cu["cell_x"]), int(cu["cell_y"])
|
| 326 |
+
wps = [(20, off_y), (85, off_y), (85, 20)]
|
| 327 |
+
tx, ty = wps[min(state["phase"], len(wps) - 1)]
|
| 328 |
+
cmds.append(Command.move_units([cutoff], target_x=tx, target_y=ty))
|
| 329 |
+
if (
|
| 330 |
+
abs(cx - tx) <= 2
|
| 331 |
+
and abs(cy - ty) <= 2
|
| 332 |
+
and state["phase"] < len(wps) - 1
|
| 333 |
+
):
|
| 334 |
+
state["phase"] += 1
|
| 335 |
+
if others:
|
| 336 |
+
cmds.append(Command.attack_move(others, 60, 20))
|
| 337 |
+
return cmds or [Command.observe()]
|
| 338 |
+
|
| 339 |
+
return policy
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
@pytest.mark.parametrize("level", ["easy", "medium", "hard"])
|
| 343 |
+
@pytest.mark.parametrize("seed", [1, 2, 3, 4])
|
| 344 |
+
def test_stall_loses(level, seed):
|
| 345 |
+
pytest.importorskip("openra_train")
|
| 346 |
+
from openra_bench.eval_core import run_level
|
| 347 |
+
|
| 348 |
+
c = compile_level(load_pack(PACK_PATH), level)
|
| 349 |
+
r = run_level(c, _stall, seed=seed)
|
| 350 |
+
assert r.outcome == "loss", (
|
| 351 |
+
f"{level} seed={seed}: stall must be a real timeout LOSS "
|
| 352 |
+
f"(no engagement → kill bar + region clause unmet); got {r.outcome}"
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
@pytest.mark.parametrize("level", ["easy", "medium", "hard"])
|
| 357 |
+
@pytest.mark.parametrize("seed", [1, 2, 3, 4])
|
| 358 |
+
def test_brute_east_loses(level, seed):
|
| 359 |
+
"""Attack-move all tanks east through the cluster. The e3 Dragon
|
| 360 |
+
fire bleeds the column below the survival cap → `own_units_gte:3`
|
| 361 |
+
fails → LOSS on every level/seed."""
|
| 362 |
+
pytest.importorskip("openra_train")
|
| 363 |
+
from openra_bench.eval_core import run_level
|
| 364 |
+
|
| 365 |
+
c = compile_level(load_pack(PACK_PATH), level)
|
| 366 |
+
r = run_level(c, _brute_east, seed=seed)
|
| 367 |
+
assert r.outcome == "loss", (
|
| 368 |
+
f"{level} seed={seed}: brute_east must LOSE (column bled by "
|
| 369 |
+
f"e3 Dragons); got {r.outcome} "
|
| 370 |
+
f"(kills={r.signals.units_killed}, lost={r.signals.units_lost})"
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
@pytest.mark.parametrize("level", ["easy", "medium", "hard"])
|
| 375 |
+
@pytest.mark.parametrize("seed", [1, 2, 3, 4])
|
| 376 |
+
def test_brute_centre_loses(level, seed):
|
| 377 |
+
"""Attack-move all tanks to the centre cluster (60,20). Even when
|
| 378 |
+
the cluster is wiped (kill bar met), NO TANK IS IN THE EAST CUT-
|
| 379 |
+
OFF REGION → in-region clause fails → after_ticks LOSS."""
|
| 380 |
+
pytest.importorskip("openra_train")
|
| 381 |
+
from openra_bench.eval_core import run_level
|
| 382 |
+
|
| 383 |
+
c = compile_level(load_pack(PACK_PATH), level)
|
| 384 |
+
r = run_level(c, _brute_centre, seed=seed)
|
| 385 |
+
assert r.outcome == "loss", (
|
| 386 |
+
f"{level} seed={seed}: brute_centre must LOSE (no tank in "
|
| 387 |
+
f"east region); got {r.outcome} "
|
| 388 |
+
f"(kills={r.signals.units_killed}, lost={r.signals.units_lost})"
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
@pytest.mark.parametrize("level", ["easy", "medium", "hard"])
|
| 393 |
+
@pytest.mark.parametrize("seed", [1, 2, 3, 4])
|
| 394 |
+
def test_east_only_loses(level, seed):
|
| 395 |
+
"""Send only one tank east; hold the rest. The solo east tank
|
| 396 |
+
can't pull the kill bar in budget → LOSS on every level/seed."""
|
| 397 |
+
pytest.importorskip("openra_train")
|
| 398 |
+
from openra_bench.eval_core import run_level
|
| 399 |
+
|
| 400 |
+
c = compile_level(load_pack(PACK_PATH), level)
|
| 401 |
+
r = run_level(c, _east_only, seed=seed)
|
| 402 |
+
assert r.outcome == "loss", (
|
| 403 |
+
f"{level} seed={seed}: east_only must LOSE (kill bar unmet); "
|
| 404 |
+
f"got {r.outcome} (kills={r.signals.units_killed}, "
|
| 405 |
+
f"lost={r.signals.units_lost})"
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
@pytest.mark.parametrize("level", ["easy", "medium", "hard"])
|
| 410 |
+
@pytest.mark.parametrize("seed", [1, 2, 3, 4])
|
| 411 |
+
def test_intended_cutoff_then_engage_wins(level, seed):
|
| 412 |
+
"""Cannae intended play: ONE tank flanks via the off-axis lane
|
| 413 |
+
(y=5 from NORTH spawn, y=35 from SOUTH spawn — both out of e3
|
| 414 |
+
Dragon range) to the eastern anvil at (85,20); the remaining
|
| 415 |
+
THREE attack-move the centre cluster. Kill bar AND in-region AND
|
| 416 |
+
survival all satisfied → WIN on every level/seed."""
|
| 417 |
+
pytest.importorskip("openra_train")
|
| 418 |
+
from openra_bench.eval_core import run_level
|
| 419 |
+
|
| 420 |
+
c = compile_level(load_pack(PACK_PATH), level)
|
| 421 |
+
r = run_level(c, _make_intended(), seed=seed)
|
| 422 |
+
assert r.outcome == "win", (
|
| 423 |
+
f"{level} seed={seed}: intended cut-off-then-engage should WIN, "
|
| 424 |
+
f"got {r.outcome} after {r.turns} turns "
|
| 425 |
+
f"(kills={r.signals.units_killed}, lost={r.signals.units_lost})"
|
| 426 |
+
)
|
tests/test_hard_tier.py
CHANGED
|
@@ -667,6 +667,19 @@ UPGRADED = [
|
|
| 667 |
# spawn variation via units_summary (the buy-vs-build base is
|
| 668 |
# otherwise building-only).
|
| 669 |
"econ-buy-vs-build-decision",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
]
|
| 671 |
|
| 672 |
# Consciously NOT spawn-varied, with the reason (keeps the curation
|
|
|
|
| 667 |
# spawn variation via units_summary (the buy-vs-build base is
|
| 668 |
# otherwise building-only).
|
| 669 |
"econ-buy-vs-build-decision",
|
| 670 |
+
# Wave-7 ACTION pack — cut-off encirclement (Cannae doctrine /
|
| 671 |
+
# SC2 encirclement / "the hammer needs an anvil"). Strike force
|
| 672 |
+
# must position ONE tank in the eastern cut-off region BEFORE
|
| 673 |
+
# engaging the centre cluster with the rest, otherwise either
|
| 674 |
+
# the column gets bled by e3 Dragon fire (brute-east) or the
|
| 675 |
+
# cluster is wiped with no tank east (brute-centre). Hard tier
|
| 676 |
+
# defines two agent spawn_point groups (NORTH staging y=12..15 /
|
| 677 |
+
# SOUTH staging y=25..28) round-robined by seed; the centre
|
| 678 |
+
# cluster is symmetric across y=20 so both spawns face the same
|
| 679 |
+
# encirclement geometry from a flipped flank latitude, and a
|
| 680 |
+
# memorised "always flank via the north" opening cannot
|
| 681 |
+
# generalise across seeds.
|
| 682 |
+
"combat-prevent-retreat",
|
| 683 |
]
|
| 684 |
|
| 685 |
# Consciously NOT spawn-varied, with the reason (keeps the curation
|