Forecast all-down recovery and preserve self-rescue; record Workshop 0.0.133
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
from policy_harness import ROOT, body, run
|
||||
p=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_RecoveryForecast.c'
|
||||
s='\n'.join(body(p,x) for x in ('static bool KeepsRound(', 'static bool Awake(', 'static float Overlap(', 'static float Predict('))
|
||||
s=s.replace('array<ref ERR_RecoveryFlow> flows','std::vector<ERR_RecoveryFlow*> flows').replace('foreach (ERR_RecoveryFlow flow : flows)', 'for (auto flow : flows)').replace('foreach (ERR_RecoveryFlow rate : flows)','for (auto rate : flows)')
|
||||
s=s.replace('flow.','flow->').replace('rate.','rate->').replace('Math.Max','maxf').replace('Math.Min','minf').replace('Math.Clamp','clampf').replace('float db, dr;','float db=0, dr=0;')
|
||||
run('''#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
float maxf(float a,float b){return std::max(a,b);} float minf(float a,float b){return std::min(a,b);} float clampf(float v,float a,float b){return std::clamp(v,a,b);}
|
||||
struct ERR_RecoveryFlow{float BloodRate=0,ResilienceRate=0,Delay=0,End=301;};
|
||||
'''+s+'''
|
||||
int main(){
|
||||
assert(KeepsRound(-1,true,false));
|
||||
assert(!KeepsRound(-1,false,true));
|
||||
assert(KeepsRound(-2,false,true));
|
||||
assert(!KeepsRound(-2,false,false));
|
||||
assert(KeepsRound(300,false,false));
|
||||
assert(Predict(1,1,.3,.5,{})==0);
|
||||
assert(Predict(.2,0,.3,.5,{})==-1);
|
||||
ERR_RecoveryFlow r;r.ResilienceRate=.002;
|
||||
assert(Predict(1,0,.3,.5,{&r})>249 && Predict(1,0,.3,.5,{&r})<252);
|
||||
r.End=100;assert(Predict(1,0,.3,.5,{&r})==-1);
|
||||
r.End=301;r.Delay=60;assert(Predict(1,0,.3,.5,{&r})==-1);
|
||||
r.Delay=0;r.ResilienceRate=.001;assert(Predict(1,0,.3,.5,{&r})==-1);
|
||||
r.ResilienceRate=.002;
|
||||
ERR_RecoveryFlow b;b.BloodRate=.001;
|
||||
assert(Predict(0,0,.4,.5,{&b,&r})==-1);
|
||||
b.BloodRate=.004;assert(Predict(0,0,.4,.5,{&b,&r})>=250);
|
||||
ERR_RecoveryFlow bleed;bleed.BloodRate=-.005;
|
||||
assert(Predict(.2,0,.4,.5,{&b,&r,&bleed})==-1);
|
||||
assert(Overlap(0,1,.5,.75)==.25);
|
||||
// Use exactly representable fractions for the inclusive 300-second horizon.
|
||||
r.ResilienceRate=1.0/512;r.Delay=44;
|
||||
assert(Predict(1,0,.3,255.0/512,{&r})==300);
|
||||
r.Delay=45;assert(Predict(1,0,.3,255.0/512,{&r})==-1);
|
||||
}
|
||||
''')
|
||||
print('PASS: real forecast code: joint thresholds, five-minute boundary, delays, medicine expiry and bleeding')
|
||||
@@ -28,8 +28,10 @@ source=body(p,'protected string ERR_TrySelfEpinephrine(')
|
||||
assert 'if (!Replication.IsServer()) return "";' in source
|
||||
assert 'GetControlledEntity()' in source and 'life.Actor == actor' in source and 'mode.Players().CurrentActor(actor) == life' in source
|
||||
assert 'mode.Settings().Get("selfEpinephrine") == 1' in source
|
||||
assert 'inventory.Contains(injector)' in source and 'items.Count() > 512' in source
|
||||
assert source.index('effect.CanApplyEffect(') < source.index('item.ApplyItemEffect(')
|
||||
inventory_source=body(p,'static IEntity FindUsable(')
|
||||
assert 'inventory.Contains(injector)' in inventory_source and 'items.Count() > 512' in inventory_source
|
||||
assert 'ERR_SelfEpinephrineInventory.FindUsable(actor)' in source
|
||||
assert 'effect.CanApplyEffect(' in inventory_source and 'item.ApplyItemEffect(' in source
|
||||
assert 'effect.GetDeleteOnUse()' in source and 'Spawn(' not in source and 'SetHealth' not in source
|
||||
settings=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_Settings.c'
|
||||
assert '"selfEpinephrine"' in body(settings,'static array<string> Keys(')
|
||||
|
||||
Reference in New Issue
Block a user