"""Execute production HQ reinforcement policy against confidence and force scenarios.""" from policy_harness import ROOT, run import re source=(ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_AirSupportPolicy.c').read_text().split('// One immutable')[0] source=source.replace('class ', 'struct ').replace('\n}', '\n};').replace('ERR_AirSupportSituation s','ERR_AirSupportSituation* s').replace('s.', 's->').replace('ERR_HQMemoryRules.','ERR_HQMemoryRules::').replace('Math.','Math::') source=source.replace('ERR_HQMemoryRules->', 'ERR_HQMemoryRules::') source=re.sub(r'\b(bool|int|float) (\w+);',r'\1 \2{};',source) run(r''' #include #include #include #include #include struct string:std::string{using std::string::string;bool IsEmpty(){return empty();}}; struct Math {static int Clamp(int x,int a,int b){return std::clamp(x,a,b);}static float Max(float a,float b){return std::max(a,b);}}; struct ERR_HQMemoryRules{static bool Finite(float v){return std::isfinite(v);}}; '''+source+r''' int main(){ ERR_AirSupportSituation s{};s.AircraftReady=true;s.BeliefId=1;s.Samples=3;s.Spotted=3;s.Age=5;s.Confidence=.9;s.Radius=20;s.MotionKnown=true;s.Infantry=true;s.Speed=1; ERR_AirSupportPolicy p;assert(!p.Consider(&s,0));assert(!p.Consider(&s,44999));assert(p.Consider(&s,45000)); p.Committed(45000);assert(!p.Consider(&s,50000));assert(!p.Consider(&s,525000));assert(p.Consider(&s,570000)); s.CommittedFit=6;assert(!p.Consider(&s,600000));s.CommittedFit=0;s.GroundFit=6;assert(!p.Consider(&s,600000)); s.ConfirmedLosses=2;assert(!p.Consider(&s,600000));assert(p.Consider(&s,620000)); s.ArtilleryBusy=true;assert(!p.Consider(&s,630000));s.ArtilleryBusy=false;assert(p.Consider(&s,640000));assert(p.Consider(&s,660000)); s.BeliefId=2;assert(!p.Consider(&s,670000));assert(!p.Consider(&s,689999));assert(p.Consider(&s,690000)); auto good=s; s.Age=91;assert(!p.Consider(&s,700000));s=good;s.Confidence=.69;assert(!p.Consider(&s,700000)); s=good;s.Radius=161;assert(!p.Consider(&s,700000));s=good;s.Samples=1;assert(!p.Consider(&s,700000)); s=good;s.Infantry=false;assert(!p.Consider(&s,700000));s=good;s.Speed=7;assert(!p.Consider(&s,700000)); s=good;s.MotionKnown=false;assert(!p.Consider(&s,700000));s=good;s.AircraftReady=false;assert(!p.Consider(&s,700000)); s=good;s.Age=std::numeric_limits::quiet_NaN();assert(!p.Consider(&s,700000)); assert(!p.Consider(nullptr,700000));assert(!p.Consider(&good,std::numeric_limits::infinity())); // Artillery blocks authorization, not the history of fresh sightings and // ground-force shortage. Repeated <45-second clear windows used to starve // airborne support by restarting its confirmation timer on every salvo. ERR_AirSupportPolicy blocked;auto contact=good;contact.BeliefId=9;contact.GroundFit=0;contact.ConfirmedLosses=0; assert(!blocked.Consider(&contact,0)); contact.ArtilleryBusy=true; assert(!blocked.Consider(&contact,10000)); assert(!blocked.Consider(&contact,46000)); contact.ArtilleryBusy=false;assert(blocked.Consider(&contact,47000)); // Stale intelligence and a changed target still invalidate confirmation. contact.Age=91;assert(!blocked.Consider(&contact,48000)); contact.Age=5;assert(!blocked.Consider(&contact,49000)); contact.BeliefId=10;assert(!blocked.Consider(&contact,90000)); assert(!blocked.Consider(&contact,134999));assert(blocked.Consider(&contact,135000)); // Busy airspace must not preconfirm a new drop during the 8-minute cooldown. blocked.Committed(135000);contact.ArtilleryBusy=true; assert(!blocked.Consider(&contact,614999)); contact.ArtilleryBusy=false;assert(!blocked.Consider(&contact,615000)); assert(!blocked.Consider(&contact,659999));assert(blocked.Consider(&contact,660000)); } ''') print('PASS: production airborne memory confidence, persistence, ground coverage, confirmed losses, artillery veto, cooldown and invalid-input rules') from policy_harness import body load=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_AirAssaultLoad.c' cover=body(load,'bool Cover(').replace('out vector center','int& center').replace('m_Order.Target','m_Order->Target') service=body(load,'bool NeedsService(') run(r''' #include struct Order {int Target=730;}; struct Load { Order* m_Order=nullptr;bool m_Used=false,m_Approaching=false;float m_CoverUntil=300000; '''+cover+service+r''' }; int main(){ Load load;Order order;int center=-1; assert(!load.Cover(0,center)&¢er==-1&&!load.NeedsService(0)); load.m_Order=ℴload.m_Used=true;load.m_Approaching=true; assert(!load.Cover(1,center)&&!load.NeedsService(300001)); load.m_Approaching=false;assert(load.Cover(299999,center)&¢er==730&&!load.NeedsService(299999)); center=-1;assert(!load.Cover(300000,center)&¢er==-1&&load.NeedsService(300000)); } ''') print('PASS: production cover retains the carried HQ target until its deadline; airport reload waits until the drop pass and cover have finished')