Office: Fella snaps, rages on a refilled will, drains, and settles calm for good

The rage goal gates on Breaks >= 1, refills his will on entry (EntryResolve 1.0), is
involuntary for RageOnsetSeconds (1 s) and then costs RageEffort (0.05) a second. When
that will runs dry and breaks a second time, the calm goal (priority 2, Breaks >= 2,
involuntary for good, his composed pose at normal strength) takes over and is terminal as
data (ruling lodur:ruling:fella-calm-after-rage). ReleaseGoalId defaults to calm and the
run ends ReleaseSeconds (6 s, the settle) after it, headless and body alike.

StressSession keeps the first break as the time to break (a second WillBroke is a row);
OfficeBody.RageTick reads the Rage row by goal; the CLI summary names the rage's span, its
end (calm, or clipped by --max) and the calm time.

Tests: the arc over seeds 1..20, calm is terminal (through a third break, on a bursty
cause), release by id, the rage weakening and the body settling. The office run's own
golden is re-captured (the run now has the arc); rung 3's rows up to the break and the pain
box golden and parity hashes pass unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 06:12:18 +01:00
commit 109bb784bb
7 changed files with 116 additions and 36 deletions

View file

@ -130,8 +130,12 @@ public static class Program
if (b.RageTick is { } rage)
{
int end = b.HandL.Count;
output.WriteLine($"rage from {b.Run.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged).TimeMs} ms for " +
$"{((end - rage) / (double)OfficeBody.Hz).ToString("F1", CultureInfo.InvariantCulture)} s; strikes {b.Strikes(rage, end)} " +
StressEntry? calm = b.Run.Timeline.Any(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm)
? b.Run.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm) : null;
int rageEnd = calm is null ? end : (int)Math.Round(calm.Value.TimeMs * OfficeBody.Hz / 1000.0);
string how = calm is null ? "clipped by --max, no calm" : $"to calm at {calm.Value.TimeMs} ms";
output.WriteLine($"rage from {b.Run.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Rage).TimeMs} ms for " +
$"{((rageEnd - rage) / (double)OfficeBody.Hz).ToString("F1", CultureInfo.InvariantCulture)} s ({how}); strikes {b.Strikes(rage, end)} " +
$"(left {OfficeBody.CountStrikes(b.HandL, rage, end)}, right {OfficeBody.CountStrikes(b.HandR, rage, end)}), " +
$"{b.Strikes(0, rage)} before it");
}

View file

@ -4,7 +4,7 @@ using Lodur;
namespace BadDay.Core;
/// <summary>What the office timeline's goal column names: the goal in force, by <see cref="OfficeBrain"/>'s index. Display only.</summary>
public enum OfficeGoal { KeepComposure, Rage }
public enum OfficeGoal { KeepComposure, Rage, Calm }
/// <summary>
/// The poses Office Fella's goals write, one rotation per muscle: the composed pose he holds while he keeps his
@ -21,18 +21,25 @@ public sealed record OfficePoses(Quat[] Composed, Quat[] Flinch, Quat[][] RageKe
/// <summary>
/// Office Fella's Brain: keep-composure (the job, pulling with <see cref="Cause.ObjectivePull"/>) until the will
/// breaks, then rage (a geyser: no pull, nothing held down, the rage keys in a loop). Authored as data; the Actor
/// commits the switch, so the timeline's goal column is read back from <see cref="Actor.GoalIndex"/>.
/// breaks, then rage (a geyser: no pull, nothing held down, the rage keys in a loop; it refills his will on entry, is
/// involuntary for its first <see cref="StressParameters.RageOnsetSeconds"/> and then costs will at
/// <see cref="StressParameters.RageEffort"/> a second), until that will runs dry and breaks a second time, and then calm:
/// his composed pose at normal strength, for good (ruling lodur:ruling:fella-calm-after-rage). Calm is terminal as
/// data: it gates on Breaks, which never falls, and nothing outranks it. Authored as data; the Actor commits the
/// switches, so the timeline's goal column is read back from <see cref="Actor.GoalIndex"/>.
/// </summary>
public static class OfficeBrain
{
public const int ComposureIndex = 0;
public const int RageIndex = 1;
public const int CalmIndex = 2;
/// <summary>The rage goal's id: what the scenario's release waits for.</summary>
public const string RageId = "rage";
public static OfficeGoal GoalAt(int index) => index == RageIndex ? OfficeGoal.Rage : OfficeGoal.KeepComposure;
/// <summary>The calm goal's id: what the scenario's release waits for (<see cref="StressParameters.ReleaseGoalId"/>).</summary>
public const string CalmId = "calm";
public static OfficeGoal GoalAt(int index) => index switch { RageIndex => OfficeGoal.Rage, CalmIndex => OfficeGoal.Calm, _ => OfficeGoal.KeepComposure };
public static Brain Build(StressParameters p, OfficePoses poses) => new()
{
@ -51,7 +58,10 @@ public static class OfficeBrain
Id = RageId,
Priority = 1.0,
Pull = 0.0,
When = new[] { new Condition(DriveQuantity.WillBroken, ConditionOp.AtLeast, 1.0) },
When = new[] { new Condition(DriveQuantity.Breaks, ConditionOp.AtLeast, 1.0) },
EntryResolve = 1.0,
Effort = p.RageEffort,
InvoluntarySeconds = p.RageOnsetSeconds,
Behaviour = new PoseBehaviour
{
Keys = poses.RageKeys,
@ -60,6 +70,14 @@ public static class OfficeBrain
Hold = p.Hold with { HoldStrength = 1f, FlinchGain = 0.0, StrainShake = 0.0 },
},
},
new GoalSpec
{
Id = CalmId,
Priority = 2.0,
When = new[] { new Condition(DriveQuantity.Breaks, ConditionOp.AtLeast, 2.0) },
InvoluntarySeconds = double.PositiveInfinity,
Behaviour = new PoseBehaviour { Keys = new[] { poses.Composed }, FlinchPose = poses.Flinch, Hold = p.Hold },
},
},
};
}

View file

@ -11,14 +11,20 @@ public sealed record StressParameters
public double MaxSeconds { get; init; } = 180.0;
public double SampleEverySeconds { get; init; } = 1.0;
/// <summary>How long the run goes on after the rage takes over, seconds [P]: the geyser is seen, then the run ends.</summary>
/// <summary>How long the run goes on after the release goal (calm) takes over, seconds [P]: the settle time. Calibrated on the body so the seated puppet is still by the end (hand speed under 0.05 m/s from 5 s after calm, seeds 1-5); the headless run ends at the same time, one rule for every path.</summary>
public double ReleaseSeconds { get; init; } = 6.0;
/// <summary>What the rage costs his will per second while it is voluntary, resolve units [P]: the rage refills his will, and this is how fast it runs dry (about 20 s from full, so the rage lasts 5-20 s with the senses still pressing).</summary>
public double RageEffort { get; init; } = 0.05;
/// <summary>How long after it takes over the rage is involuntary, seconds [P]: full weight and no cost, the snap itself, before it becomes something he sustains.</summary>
public double RageOnsetSeconds { get; init; } = 1.0;
/// <summary>Seconds from one rage key to the next [P]: wind-up left, strike left, wind-up right, strike right.</summary>
public double RageKeySeconds { get; init; } = 0.25;
/// <summary>The id of the Brain goal whose takeover starts the release: the run ends <see cref="ReleaseSeconds"/> after that goal's GoalChanged, and a change to any other goal does not. The session refuses an id the Brain lacks.</summary>
public string ReleaseGoalId { get; init; } = OfficeBrain.RageId;
public string ReleaseGoalId { get; init; } = OfficeBrain.CalmId;
public Setting Setting { get; init; } = Setting.Office;
public Character Character { get; init; } = Character.OfficeFella;

View file

@ -18,7 +18,7 @@ public sealed record StressResult(
ulong Seed,
/// <summary>WillBroke (the run goes on through the release) or Endured; the office has no box to disable.</summary>
Outcome Outcome,
/// <summary>When the run ended: the release after the rage took over, or MaxSeconds.</summary>
/// <summary>When the run ended: the release after calm took over, or MaxSeconds.</summary>
long EndMs,
/// <summary>Time resolve hit zero, ms; null unless the will broke.</summary>
long? TimeToBreakMs,

View file

@ -9,8 +9,8 @@ namespace BadDay.Core;
/// <see cref="Actor"/>, and the recorder. The headless run, the sweep, the CLI and a client all drive it one
/// <see cref="Tick"/> per step, and the player's lever is <see cref="Silence"/>. The session never writes drive
/// state, computes load or arousal, or holds a stress field: rows are end-of-tick state read from the Actor, and
/// nothing reads them back. The rage is the Brain's (<see cref="OfficeBrain"/>): the session goes on past the break, logs the
/// tick the Actor commits the switch, and ends ReleaseSeconds after the Brain's release goal (<see cref="StressParameters.ReleaseGoalId"/>) takes over, or at MaxSeconds.
/// nothing reads them back. The rage and the calm after it are the Brain's (<see cref="OfficeBrain"/>): the session goes on past the break, logs each
/// tick the Actor commits a switch, and ends ReleaseSeconds after the Brain's release goal (<see cref="StressParameters.ReleaseGoalId"/>) takes over, or at MaxSeconds.
/// </summary>
public sealed class StressSession
{
@ -84,7 +84,7 @@ public sealed class StressSession
/// <summary>Ticks run so far; the tick the next <see cref="Tick"/> runs.</summary>
public long TickIndex => Actor.TickCount;
/// <summary>True once the release after the rage took over is over, or the time ran out.</summary>
/// <summary>True once the release after calm took over is over, or the time ran out.</summary>
public bool Finished { get; private set; }
/// <summary>
@ -121,7 +121,7 @@ public sealed class StressSession
if ((events & TickEvents.WillBroke) != 0)
{
_breakTick = tick;
if (_breakTick < 0) _breakTick = tick; // the snap; the rage's own break is a row, not the time to break
_outcome = Outcome.WillBroke;
Log(tick, StressEntryKind.WillBroke);
}

View file

@ -18,9 +18,9 @@ public readonly record struct BodyPoint(float X, float Y, float Z);
public sealed record OfficeBodyResult(
StressResult Run, IReadOnlyList<BodyPoint> HandL, IReadOnlyList<BodyPoint> HandR, IReadOnlyList<BodyPoint> Pelvis)
{
/// <summary>The tick the rage took over (the GoalChanged row); null if the will held.</summary>
public int? RageTick => Run.Timeline.Any(e => e.Kind == StressEntryKind.GoalChanged)
? (int)Math.Round(Run.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged).TimeMs * OfficeBody.Hz / 1000.0)
/// <summary>The tick the rage took over (the GoalChanged row whose goal is Rage); null if the will held.</summary>
public int? RageTick => Run.Timeline.Any(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Rage)
? (int)Math.Round(Run.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Rage).TimeMs * OfficeBody.Hz / 1000.0)
: null;
/// <summary>Strikes by both hands from tick <paramref name="from"/> up to <paramref name="to"/>, see <see cref="OfficeBody.CountStrikes"/>.</summary>
@ -31,7 +31,7 @@ public sealed record OfficeBodyResult(
/// Office Fella on the seated puppet: <see cref="SeatedPuppet"/>'s world, the desk's emitters moved to where the head
/// sits and sensed there, and the same <see cref="StressSession"/> the headless run drives. Per step: the body reports its
/// points, the session decides (Lodur's Actor commits the Brain's goals, <see cref="OfficeBrain"/>), the ragdoll is driven,
/// the world steps. The run ends as the session ends, the release after the rage takes over.
/// the world steps. The run ends as the session ends, the release after calm takes over.
/// </summary>
public static class OfficeBody
{

View file

@ -776,7 +776,7 @@ public static class Program
}
}),
("office golden [P]: the rows up to the break are rung 3's bytes, the 50-seed sweep ends in its captured line, and the run's own bytes are captured", () =>
("office golden [P]: the rows up to the break are rung 3's bytes, the 50-seed sweep ends in its captured line, and the run's own bytes are captured (re-captured with the arc: the rage refills his will, a second break and calm follow)", () =>
{
string Out(params string[] a)
{
@ -792,37 +792,63 @@ public static class Program
for (int i = 2; i <= brk; i++) rung3.Add(lines[i].Replace(" KeepComposure", i == brk ? " Withdraw" : " HoldHand"));
rung3.Add(lines[^1]);
Check(Hash(string.Join('\n', rung3) + "\n") == "66098b69834c3c8b5e5b694f0059b8ed566e31d332f36be7e57baf70ae650823", "the office's rows up to the break differ from rung 3's");
Check(Hash(string.Join('\n', lines) + "\n") == "006f712ff35052ff3f1497d67ecd6d20bd679de6bb3922714695a709fffa6ce4", $"office --seed 1 changed: {Hash(string.Join('\n', lines) + "\n")}");
Check(Hash(string.Join('\n', lines) + "\n") == "b4e56329126e49192d2212b5acfcb63bd5691845571ff727fafec6745e7c42fc", $"office --seed 1 changed: {Hash(string.Join('\n', lines) + "\n")}");
var last = Out("office-sweep", "--seed", "1", "--count", "50").TrimEnd('\n').Split('\n')[^1];
Check(last == "runs 50: broke 50, endured 0; time to break min/median/max ms: 72670/86570/113420; min resolve of endured runs: -", $"sweep line changed: {last}");
}),
("office rage: the Actor switches once, 100 ms after the break, KeepComposure before and Rage from it, and the run ends ReleaseSeconds after the switch", () =>
("office arc: the snap, then a rage on a refilled will, a second break 5-20 s later, and calm for good: every switch 100 ms after its break, nothing after calm, and the run ends ReleaseSeconds after calm", () =>
{
foreach (ulong seed in new ulong[] { 1, 2, 3, 4, 5 })
for (ulong seed = 1; seed <= 20; seed++)
{
var r = Office(new StressParameters(), seed);
var brk = r.Timeline.Single(e => e.Kind == StressEntryKind.WillBroke);
var sw = r.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged);
Check(sw.TimeMs - brk.TimeMs == 100 && brk.TimeMs == r.TimeToBreakMs, $"seed {seed}: the switch row is {sw.TimeMs - brk.TimeMs} ms after the break");
Check(r.Timeline.Where(e => e.TimeMs < sw.TimeMs).All(e => e.Goal == OfficeGoal.KeepComposure), $"seed {seed}: a row before the switch is not KeepComposure");
Check(r.Timeline.Where(e => e.TimeMs >= sw.TimeMs).All(e => e.Goal == OfficeGoal.Rage), $"seed {seed}: a row from the switch on is not Rage");
Check(r.Outcome == Outcome.WillBroke && r.EndMs == sw.TimeMs + 6000, $"seed {seed}: ended at {r.EndMs}, the switch was at {sw.TimeMs}");
Check(r.Timeline.Where(e => e.TimeMs >= brk.TimeMs).All(e => e.Resolve == 0.0), $"seed {seed}: resolve came back after the break");
var breaks = r.Timeline.Where(e => e.Kind == StressEntryKind.WillBroke).ToList();
var switches = r.Timeline.Where(e => e.Kind == StressEntryKind.GoalChanged).ToList();
Check(breaks.Count == 2 && switches.Count == 2, $"seed {seed}: {breaks.Count} breaks and {switches.Count} switches, wanted 2 and 2");
var rage = switches[0];
var calm = switches[1];
Check(breaks[0].TimeMs == r.TimeToBreakMs, $"seed {seed}: the time to break is not the first break");
Check(rage.Goal == OfficeGoal.Rage && rage.TimeMs - breaks[0].TimeMs == 100 && rage.Resolve == 1.0, $"seed {seed}: the rage row is {rage.Goal} {rage.TimeMs - breaks[0].TimeMs} ms after the snap with resolve {rage.Resolve}");
long lasted = breaks[1].TimeMs - breaks[0].TimeMs;
Check(lasted >= 5000 && lasted <= 20000, $"seed {seed}: the second break came {lasted} ms after the snap");
Check(calm.Goal == OfficeGoal.Calm && calm.TimeMs - breaks[1].TimeMs == 100, $"seed {seed}: the calm row is {calm.Goal} {calm.TimeMs - breaks[1].TimeMs} ms after the second break");
Check(r.Timeline.Where(e => e.TimeMs < rage.TimeMs).All(e => e.Goal == OfficeGoal.KeepComposure), $"seed {seed}: a row before the rage is not KeepComposure");
Check(r.Timeline.Where(e => e.TimeMs >= rage.TimeMs && e.TimeMs < calm.TimeMs).All(e => e.Goal == OfficeGoal.Rage), $"seed {seed}: a row in the rage is not Rage");
Check(r.Timeline.Where(e => e.TimeMs >= calm.TimeMs).All(e => e.Goal == OfficeGoal.Calm), $"seed {seed}: a row from calm on is not Calm");
Check(r.Outcome == Outcome.WillBroke && r.EndMs == calm.TimeMs + 6000, $"seed {seed}: ended at {r.EndMs}, calm was at {calm.TimeMs}");
}
var short_ = Office(new StressParameters { ReleaseSeconds = 2.0 }, 1);
Check(short_.EndMs == short_.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged).TimeMs + 2000, "ReleaseSeconds did not set the length of the rage");
Check(short_.EndMs == short_.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm).TimeMs + 2000, "ReleaseSeconds did not set the settle time");
var clipped = Office(new StressParameters { MaxSeconds = 85.0 }, 1);
Check(clipped.Outcome == Outcome.WillBroke && clipped.EndMs == 85000 && clipped.Timeline.All(e => e.Kind != StressEntryKind.Endured), $"a release past MaxSeconds ended at {clipped.EndMs}");
Check(clipped.Outcome == Outcome.WillBroke && clipped.EndMs == 85000 && clipped.Timeline.All(e => e.Kind != StressEntryKind.Endured && e.Goal != OfficeGoal.Calm), $"a release past MaxSeconds ended at {clipped.EndMs}");
}),
("office calm is terminal: with the release moved off calm the run goes to MaxSeconds, and after the Calm row the goal never changes again, whatever the senses and the mending will do", () =>
{
// Bursts of heavy load with quiet between: the will breaks, mends in the quiet, and breaks again, which the office's steady load never does.
var Bursty = Cause.Office with { Stressors = new[] { new Stressor("printer", "printer", 5.0, 0.0, 100.0, 40.0, 1.0, 0.0) } };
int thirdBreaks = 0;
for (ulong seed = 1; seed <= 5; seed++)
{
var r = Office(new StressParameters { ReleaseGoalId = "keep-composure", Cause = Bursty }, seed);
var calm = r.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm);
Check(r.EndMs == 180000, $"seed {seed}: ended at {r.EndMs}");
Check(r.Timeline.Count(e => e.Kind == StressEntryKind.GoalChanged) == 2, $"seed {seed}: a goal changed after calm");
Check(r.Timeline.Where(e => e.TimeMs >= calm.TimeMs).All(e => e.Goal == OfficeGoal.Calm), $"seed {seed}: the goal column left Calm");
thirdBreaks += r.Timeline.Count(e => e.Kind == StressEntryKind.WillBroke && e.TimeMs > calm.TimeMs);
}
Check(thirdBreaks > 0, "no run broke the will a third time after calm; the test no longer exercises the rule");
}),
("office release: the run ends on the Brain's release goal, by id, not on any goal change; an id the Brain lacks is refused", () =>
{
var r = Office(new StressParameters { ReleaseGoalId = "keep-composure" }, 1);
Check(r.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged).TimeMs == 83380 && r.EndMs == 180000 && r.Outcome == Outcome.WillBroke,
$"releasing on a goal the Brain never switches to ended the run at {r.EndMs}");
Check(r.EndMs == 180000 && r.Outcome == Outcome.WillBroke, $"releasing on a goal the Brain never switches to ended the run at {r.EndMs}");
var rage = Office(new StressParameters { ReleaseGoalId = OfficeBrain.RageId }, 1);
var sw = rage.Timeline.First(e => e.Kind == StressEntryKind.GoalChanged);
Check(sw.Goal == OfficeGoal.Rage && rage.EndMs == sw.TimeMs + 6000, $"releasing on the rage ended the run at {rage.EndMs}, the rage was at {sw.TimeMs}");
bool threw = false;
try { NewOffice(new StressParameters { ReleaseGoalId = "calm" }, 1); } catch (ArgumentException) { threw = true; }
try { NewOffice(new StressParameters { ReleaseGoalId = "nowhere" }, 1); } catch (ArgumentException) { threw = true; }
Check(threw, "a release goal the Brain lacks was accepted");
}),
@ -843,7 +869,9 @@ public static class Program
Check(a.Run.Render() == b.Run.Render() && a.HandL.SequenceEqual(b.HandL) && a.HandR.SequenceEqual(b.HandR) && a.Pelvis.SequenceEqual(b.Pelvis), "two body runs differ");
Check(a.Run.Outcome == Outcome.WillBroke && a.RageTick is not null, $"outcome {a.Run.Outcome}");
int sw = a.RageTick!.Value;
Check(a.HandL.Count == sw + 6 * Hz + 1, $"the run has {a.HandL.Count} steps, the switch is at {sw}");
var calmRow = a.Run.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm);
int calmTick = (int)Math.Round(calmRow.TimeMs * Hz / 1000.0);
Check(a.HandL.Count == calmTick + 6 * Hz + 1, $"the run has {a.HandL.Count} steps, calm is at {calmTick}");
double Rms(IReadOnlyList<BodyPoint> h, int from, int to)
{
double sum = 0;
@ -869,6 +897,30 @@ public static class Program
Check(drift < 0.01f, $"the pelvis moved {drift:F4} m");
}),
("office body: the rage weakens as it drains his will (each hand slower in its last 2 s than in the 2 s after onset), and he settles: no hand moves faster than 0.05 m/s over the run's last second", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
for (ulong seed = 1; seed <= 3; seed++)
{
var a = OfficeBody.Run(p, seed);
int rage = a.RageTick!.Value;
int calm = (int)Math.Round(a.Run.Timeline.Single(e => e.Kind == StressEntryKind.GoalChanged && e.Goal == OfficeGoal.Calm).TimeMs * Hz / 1000.0);
double Speed(IReadOnlyList<BodyPoint> h, int i)
{
double dx = h[i].X - h[i - 1].X, dy = h[i].Y - h[i - 1].Y, dz = h[i].Z - h[i - 1].Z;
return Math.Sqrt(dx * dx + dy * dy + dz * dz) * Hz;
}
double Rms(IReadOnlyList<BodyPoint> h, int from, int to) => Math.Sqrt(Enumerable.Range(from + 1, to - from - 1).Average(i => Speed(h, i) * Speed(h, i)));
foreach (var (name, hand) in new[] { ("left", a.HandL), ("right", a.HandR) })
{
double onset = Rms(hand, rage, rage + 2 * Hz), late = Rms(hand, calm - 2 * Hz, calm);
Check(late < onset, $"seed {seed} {name} hand: {late:F3} m/s in the rage's last 2 s, {onset:F3} m/s in the 2 s after onset");
double still = Enumerable.Range(hand.Count - Hz, Hz).Max(i => Speed(hand, i));
Check(still < 0.05, $"seed {seed} {name} hand: {still:F3} m/s at its fastest in the run's last second");
}
}
}),
("office body: the desk's emitters are sensed at the head, so the body breaks within 0.5 s of the headless run (sensed at a hand it is 3.6 s off)", () =>
{
var body = OfficeBody.Run(new StressParameters { TickSeconds = OfficeBody.TickSeconds }, 1).Run;