Hand-out is the start of a sustained exit; Summary reads it; the idle-hold bound is measured
PainBoxResult carries HandOutMs (headless: the deliberate withdrawal; body: the start of the first exit after the break that the hand held for 200 ms without re-entering, so a flinch excursion is not an exit) and Summary prints hand out only when there is one. The run ends at the Actor's Withdrew once the exit is confirmed or the 1 s settle is over. The sustained-exit test runs five non-default hold sets over 30 seeds. The idle-hold limits cite the drift measured over substeps 1 to 8. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0e9e1ee837
commit
a218c55090
5 changed files with 75 additions and 19 deletions
|
|
@ -58,9 +58,9 @@ public static class Program
|
|||
output.WriteLine(Title);
|
||||
output.Write(b.Run.Render());
|
||||
output.WriteLine(b.Run.Summary());
|
||||
output.WriteLine(b.HandOutMs is { } out_
|
||||
output.WriteLine(b.Run.HandOutMs is { } out_
|
||||
? $"hand out at {out_} ms, {out_ - b.Run.TimeToBreakMs} ms after the will broke; {b.Excursions} excursions from the box before the break"
|
||||
: $"hand still in the box at {b.Run.EndMs} ms; {b.Excursions} excursions from the box before the break");
|
||||
: $"hand not out for good by {b.Run.EndMs} ms; {b.Excursions} excursions from the box before the break");
|
||||
return 0;
|
||||
}
|
||||
if (opts.ContainsKey("body")) throw new ArgumentException("--body applies to run");
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ public sealed record PainBoxResult(
|
|||
/// <summary>Time resolve hit zero, ms; null unless <see cref="Outcome"/> is WillBroke.</summary>
|
||||
long? TimeToBreakMs,
|
||||
int Flinches,
|
||||
IReadOnlyList<TimelineEntry> Timeline)
|
||||
IReadOnlyList<TimelineEntry> Timeline,
|
||||
/// <summary>Time the hand was out of the box for good, ms; null if it never was. Headless: the deliberate withdrawal. Body: the start of a sustained exit.</summary>
|
||||
long? HandOutMs = null)
|
||||
{
|
||||
/// <summary>
|
||||
/// Deterministic text form (invariant culture, fixed precision). Two runs
|
||||
|
|
@ -54,7 +56,9 @@ public sealed record PainBoxResult(
|
|||
|
||||
public string Summary() => Outcome switch
|
||||
{
|
||||
Outcome.WillBroke => $"seed {Seed}: will broke at {TimeToBreakMs} ms, hand out at {EndMs} ms, {Flinches} flinches",
|
||||
Outcome.WillBroke => HandOutMs is { } out_
|
||||
? $"seed {Seed}: will broke at {TimeToBreakMs} ms, hand out at {out_} ms, {Flinches} flinches"
|
||||
: $"seed {Seed}: will broke at {TimeToBreakMs} ms, hand not out by {EndMs} ms, {Flinches} flinches",
|
||||
Outcome.BoxDisabled => $"seed {Seed}: box disabled at {EndMs} ms, will held, {Flinches} flinches",
|
||||
_ => $"seed {Seed}: endured to {EndMs} ms, will held, {Flinches} flinches",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public static class PainBoxSimulation
|
|||
session.Tick(point, point, point, strengths, targets);
|
||||
if (session.Withdrew) break;
|
||||
}
|
||||
return session.Result();
|
||||
var r = session.Result();
|
||||
// The headless hand is fixed in the box; the deliberate withdrawal is what takes it out.
|
||||
return r.Outcome == Outcome.WillBroke ? r with { HandOutMs = r.EndMs } : r;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,14 @@ public readonly record struct HandSample(float X, float Y, float Z, bool InBox);
|
|||
/// <summary>
|
||||
/// The body run's result: the same timeline and outcome as the headless run, plus what only a body has.
|
||||
/// The outcome comes from the Actor's events (the run goes on to the deliberate withdrawal, then settles up to a second
|
||||
/// for the hand to come out), so <see cref="Run"/>'s EndMs is the later of the Withdrew event and the hand-out time.
|
||||
/// for the hand to leave the box for good). <see cref="PainBoxResult.HandOutMs"/> is the start of the first exit after the break
|
||||
/// that the hand held for <see cref="OutHoldSeconds"/> without re-entering (a flinch excursion is not an exit); null if there was none.
|
||||
/// <see cref="Run"/>'s EndMs is when the run stopped.
|
||||
/// </summary>
|
||||
/// <param name="HandOutMs">First step at or after the will broke with the hand point outside the box; null if it did not come out by the end of the settle. It can precede the Withdrew event.</param>
|
||||
/// <param name="Excursions">Times the hand left the box between the end of the ramp and the break.</param>
|
||||
/// <param name="Hand">The hand after every step; the index is the tick.</param>
|
||||
public sealed record BodyPainBoxResult(
|
||||
PainBoxResult Run, long? HandOutMs, int Excursions, IReadOnlyList<HandSample> Hand);
|
||||
PainBoxResult Run, int Excursions, IReadOnlyList<HandSample> Hand);
|
||||
|
||||
/// <summary>
|
||||
/// The pain box on the body: BDS creates the Ymir world (a ground, a static stool box welded to the pelvis
|
||||
|
|
@ -44,6 +45,9 @@ public static class BodyPainBox
|
|||
/// <summary>After the deliberate withdrawal begins the run waits this long for the hand to come out.</summary>
|
||||
private const double SettleSeconds = 1.0;
|
||||
|
||||
/// <summary>The hand is out when it has stayed outside the box this long after the break.</summary>
|
||||
public const double OutHoldSeconds = 0.2;
|
||||
|
||||
public static BodyPainBoxResult Run(PainBoxParameters p, ulong seed)
|
||||
{
|
||||
if (Math.Abs(p.TickSeconds - TickSeconds) > 1e-12)
|
||||
|
|
@ -77,11 +81,13 @@ public static class BodyPainBox
|
|||
|
||||
var samples = new List<HandSample>();
|
||||
long rampEnd = (long)Math.Round(p.BoxRampSeconds / p.TickSeconds);
|
||||
long outSince = -1; // first tick of the current continuous stay outside the box after the break
|
||||
long? handOut = null;
|
||||
int excursions = 0;
|
||||
bool wasIn = false;
|
||||
long breakTick = -1, withdrewTick = -1;
|
||||
long settleTicks = (long)Math.Round(SettleSeconds / p.TickSeconds);
|
||||
long outHoldTicks = Math.Max(1, (long)Math.Round(OutHoldSeconds / p.TickSeconds));
|
||||
|
||||
HandSample ReadHand()
|
||||
{
|
||||
|
|
@ -113,9 +119,15 @@ public static class BodyPainBox
|
|||
if (tick > rampEnd && wasIn && !inBox) excursions++;
|
||||
wasIn = inBox;
|
||||
}
|
||||
else if (!inBox && handOut is null)
|
||||
else if (inBox)
|
||||
{
|
||||
handOut = session.Ms(tick);
|
||||
outSince = -1; // back in: whatever exit this was, it was a flinch
|
||||
handOut = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outSince < 0) outSince = tick;
|
||||
if (tick - outSince + 1 >= outHoldTicks) handOut = session.Ms(outSince);
|
||||
}
|
||||
|
||||
// The run ends on the Actor's events, never on the hand: after the deliberate withdrawal, once the
|
||||
|
|
@ -127,6 +139,6 @@ public static class BodyPainBox
|
|||
}
|
||||
}
|
||||
|
||||
return new BodyPainBoxResult(session.Result(), handOut, excursions, samples);
|
||||
return new BodyPainBoxResult(session.Result() with { HandOutMs = handOut }, excursions, samples);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public static class Program
|
|||
{
|
||||
var a = BodyPainBox.Run(OnBody, 1);
|
||||
var b = BodyPainBox.Run(OnBody, 1);
|
||||
Check(a.Run.Render() == b.Run.Render() && a.HandOutMs == b.HandOutMs && a.Excursions == b.Excursions, "body runs differ");
|
||||
Check(a.Run.Render() == b.Run.Render() && a.Run.HandOutMs == b.Run.HandOutMs && a.Excursions == b.Excursions, "body runs differ");
|
||||
Check(a.Hand.Count == b.Hand.Count && a.Hand[^1] == b.Hand[^1], "hand tracks differ");
|
||||
}),
|
||||
|
||||
|
|
@ -133,15 +133,15 @@ public static class Program
|
|||
bool moved = flinches.Any(f => r.Hand.Skip(f).Take(Hz / 5 + 1).Any(h => Dist(h) > 0.023f));
|
||||
Check(moved, "no flinch moved the hand over 2.3 cm from the hold point");
|
||||
|
||||
Check(r.HandOutMs is { } o && o - broke <= 300, $"hand out at {r.HandOutMs}, will broke at {broke}");
|
||||
Check(r.Run.EndMs == r.HandOutMs, "the run should end when the hand is out");
|
||||
Check(r.Run.HandOutMs is { } o && o - broke <= 300, $"hand out at {r.Run.HandOutMs}, will broke at {broke}");
|
||||
Check(r.Run.EndMs >= r.Run.HandOutMs, "the run ended before the hand was out");
|
||||
}),
|
||||
|
||||
("body: switching the box off at 5 s ends the run with the will intact and the hand still in the box", () =>
|
||||
{
|
||||
var r = BodyPainBox.Run(OnBody with { BoxDisableAtSeconds = 5.0 }, 1);
|
||||
Check(r.Run.Outcome == Outcome.BoxDisabled && r.Run.TimeToBreakMs is null, $"outcome {r.Run.Outcome}");
|
||||
Check(r.HandOutMs is null && r.Hand[^1].InBox, "the hand left the box");
|
||||
Check(r.Run.HandOutMs is null && r.Hand[^1].InBox, "the hand left the box");
|
||||
Check(r.Run.Timeline.Last().Resolve > 0.0, "resolve should be above zero");
|
||||
}),
|
||||
|
||||
|
|
@ -153,11 +153,16 @@ public static class Program
|
|||
Check(late > early, $"speed RMS {late:F4} m/s in the 2 s before the break, {early:F4} m/s in the 2 s after the ramp");
|
||||
}),
|
||||
|
||||
("body: a box at intensity 0 for 10 s: no flinch, no break, the hand holds still", () =>
|
||||
("body: a box at intensity 0 for 10 s: no flinch, no break, the hand stays near its hold point", () =>
|
||||
{
|
||||
var r = BodyPainBox.Run(OnBody with { BoxIntensity = 0.0, MaxSeconds = 10.0 }, 1);
|
||||
Check(r.Run.Outcome == Outcome.Endured && r.Run.Flinches == 0 && r.Run.TimeToBreakMs is null, r.Run.Summary());
|
||||
for (int i = 3 * Hz; i < r.Hand.Count; i++) Check(Dist(r.Hand[i]) <= 0.023f, $"drift {Dist(r.Hand[i]):F3} m at tick {i}");
|
||||
// Measured idle drift from the hold point (seed-independent without pain), substeps 1 to 8: the arm settles
|
||||
// slowly and sags about 1 cm under gravity, so from 3 s the largest drift is 2.0 to 2.3 cm (2.31 at 8 substeps),
|
||||
// from 8 s 1.1 to 1.5 cm. A flinch moves the hand over 2.3 cm from where a leak-free arm is; the limits sit
|
||||
// 50% and 35% above the largest measurement.
|
||||
for (int i = 3 * Hz; i < r.Hand.Count; i++) Check(Dist(r.Hand[i]) <= 0.035f, $"drift {Dist(r.Hand[i]):F3} m at tick {i}");
|
||||
for (int i = 8 * Hz; i < r.Hand.Count; i++) Check(Dist(r.Hand[i]) <= 0.020f, $"late drift {Dist(r.Hand[i]):F3} m at tick {i}");
|
||||
}),
|
||||
|
||||
("body: the stimulus and the flinches are the right hand's: the timeline's stimulus column is live while the hand is in the box", () =>
|
||||
|
|
@ -174,10 +179,10 @@ public static class Program
|
|||
for (ulong seed = 1; seed <= 6; seed++)
|
||||
{
|
||||
var r = BodyPainBox.Run(heavy, seed);
|
||||
Check(r.Run.Outcome == Outcome.WillBroke, $"seed {seed}: outcome {r.Run.Outcome}, break {r.Run.TimeToBreakMs}, hand out {r.HandOutMs}");
|
||||
Check(r.Run.Outcome == Outcome.WillBroke, $"seed {seed}: outcome {r.Run.Outcome}, break {r.Run.TimeToBreakMs}, hand out {r.Run.HandOutMs}");
|
||||
var withdrew = r.Run.Timeline.Single(e => e.Kind == EntryKind.Withdrew);
|
||||
Check(withdrew.TimeMs - r.Run.TimeToBreakMs == 100, $"seed {seed}: Withdrew row {withdrew.TimeMs - r.Run.TimeToBreakMs} ms after the break");
|
||||
Check(r.Run.EndMs >= withdrew.TimeMs && (r.HandOutMs is null || r.Run.EndMs >= r.HandOutMs), $"seed {seed}: ended before the withdrawal or the hand-out");
|
||||
Check(r.Run.EndMs >= withdrew.TimeMs && (r.Run.HandOutMs is null || r.Run.EndMs >= r.Run.HandOutMs), $"seed {seed}: ended before the withdrawal or the hand-out");
|
||||
}
|
||||
}),
|
||||
|
||||
|
|
@ -197,6 +202,39 @@ public static class Program
|
|||
}
|
||||
}),
|
||||
|
||||
("body: hand-out is the start of a sustained exit: under five non-default holds over 30 seeds a reported hand-out is never followed by re-entry and starts at the first step out", () =>
|
||||
{
|
||||
var sets = new (string Name, PainBoxParameters P)[]
|
||||
{
|
||||
("heavy", OnBody with { Hold = new Lodur.HoldParameters { FlinchGain = 1.0, StrainShake = 0.3 } }),
|
||||
("flinch 1", OnBody with { Hold = new Lodur.HoldParameters { FlinchGain = 1.0 } }),
|
||||
("shake 0.3", OnBody with { Hold = new Lodur.HoldParameters { StrainShake = 0.3 } }),
|
||||
("flinch 2 shake 0.5", OnBody with { Hold = new Lodur.HoldParameters { FlinchGain = 2.0, StrainShake = 0.5 } }),
|
||||
("intensity 1 heavy", OnBody with { BoxIntensity = 1.0, Hold = new Lodur.HoldParameters { FlinchGain = 1.0, StrainShake = 0.3 } }),
|
||||
};
|
||||
int broke = 0, exited = 0;
|
||||
foreach (var (name, p0) in sets)
|
||||
{
|
||||
var p = p0 with { MaxSeconds = 30.0 }; // a hand that flinches out of the box early stops the pain, and the will may never break
|
||||
for (ulong seed = 1; seed <= 30; seed++)
|
||||
{
|
||||
var r = BodyPainBox.Run(p, seed);
|
||||
string who = $"{name} seed {seed}";
|
||||
if (r.Run.Outcome != Outcome.WillBroke) continue;
|
||||
broke++;
|
||||
string summary = r.Run.Summary();
|
||||
Check(r.Run.HandOutMs is null == summary.Contains("hand not out"), $"{who}: summary '{summary}' disagrees with hand-out {r.Run.HandOutMs}");
|
||||
if (r.Run.HandOutMs is not { } ms) continue;
|
||||
exited++;
|
||||
int outTick = Tick(ms), breakTick = Tick(r.Run.TimeToBreakMs!.Value);
|
||||
for (int i = outTick; i < r.Hand.Count; i++) Check(!r.Hand[i].InBox, $"{who}: hand out at tick {outTick} but back in the box at tick {i}");
|
||||
Check(outTick >= breakTick && (outTick == breakTick || r.Hand[outTick - 1].InBox), $"{who}: hand-out at tick {outTick} is not the first step out of the exit (break {breakTick})");
|
||||
Check(r.Hand.Count - outTick >= (int)Math.Round(BodyPainBox.OutHoldSeconds * Hz), $"{who}: the exit was held {r.Hand.Count - outTick} ticks");
|
||||
}
|
||||
}
|
||||
Check(broke >= 75 && exited >= 50, $"only {broke} of 150 runs broke the will and {exited} got the hand out; the test no longer exercises the rule");
|
||||
}),
|
||||
|
||||
("body: a box disabled at tick 0 ends at once with the will intact and a hand track to read", () =>
|
||||
{
|
||||
var r = BodyPainBox.Run(OnBody with { BoxDisableAtSeconds = 0.0 }, 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue