diff --git a/README.md b/README.md
index 6a6bbd1..aa9ece2 100644
--- a/README.md
+++ b/README.md
@@ -95,8 +95,8 @@ Actor's state at the end of its tick:
- **Drive:** pain rises with the signal and decays; resolve drains with pain
and strain, scaled by `(1 - pull)` of the goal in force, and recovers only when pain is low.
Two seeded traits (nociceptor gain, resolve drain) make each seed a different person.
-- **Goals:** the volunteer is paid to keep his hand in, and his Brain is data
- (`ChamberBrain`): `HoldHand` pulls with `Payment / (Payment + DollarsAtHalfPull)` (both
+- **Goals:** the volunteer is paid to keep his hand in, and his Brain is data, built in code for now
+ (`ChamberBrain`; it becomes CultCache content with Lodur's Brain content, follow-up `npc-brains-as-content`): `HoldHand` pulls with `Payment / (Payment + DollarsAtHalfPull)` (both
100 by default, so $100 pulls 0.5; $0 pulls nothing and $400 pulls 0.8), and `Withdraw`
is eligible once resolve has reached zero and outranks it. Lodur's Actor commits the
switch after its deliberate latency (100 ms), so the break row still reads `HoldHand`;
@@ -141,16 +141,17 @@ run on Windows and on Linux.
## The office stress scenario (rungs 3 and 4)
The office's stressors fill the stress bar until the will breaks, and then Office Fella goes into a rage:
-headless, one tick at a time, or on the seated puppet. The scenario is data in two parts. The **setting** names the emitters (printer, ceiling light, desk
+headless, one tick at a time, or on the seated puppet. The scenario is data in three parts. The **setting** names the emitters (printer, ceiling light, desk
phone, desktop notifications) and where they sit. The **cause** holds the stressors that drive them (each with
-an onset, ramp, period, duration, intensity and jitter), the job's pull (0.6, the keep-composure goal's) and the sense nerve the
-character hears and sees with. Lodur owns what the stimulus does: sensing, load, arousal, and the arousal
+an onset, ramp, period, duration, intensity and jitter), and the job's pull (0.6, the keep-composure goal's). The **character** holds the sense nerve he
+hears and sees with. Lodur owns what the stimulus does: sensing, load, arousal, and the arousal
drain on resolve. `StressSession` only writes the emitters' intensities each tick and logs the Actor's state;
-the player's lever is `Silence(stressorId)`, from the current tick on. Office Fella's Brain is data too
-(`OfficeBrain`): `KeepComposure` pulls with the job's pull; `Rage` (eligible once the will has broken, outranks it,
+the player's lever is `Silence(stressorId)`, from the current tick on. Office Fella's Brain is data too, built in code for now (`OfficeBrain`; content later, as above): `KeepComposure` pulls with the job's pull; `Rage` (eligible once the will has broken, outranks it,
no pull) loops wind-up and strike with each arm at 0.25 s a key. The Actor commits the switch 100 ms after the break,
-the session logs a `GoalChanged` row, and the run goes on `ReleaseSeconds` (6 s) after it, or to 180 s if the will
-holds. Headless the rage moves nothing; `office --body` runs it on the puppet.
+the session logs a `GoalChanged` row, and the run goes on `ReleaseSeconds` (6 s) after the Brain's release goal
+(`ReleaseGoalId`, `rage`) takes over, or to 180 s if the will holds. Who has the day is a `Character` (his senses; `Character.OfficeFella`),
+apart from the setting and the cause. Each scenario builds its own Brain from its own parameters; one entry point keyed by character id
+waits for Brains as content. Headless the rage moves nothing; `office --body` runs it on the puppet.
The stress bar is `1 - resolve` and reads **lost composure**; the label is one constant
(`StressResult.StressBarLabel`) pending `lodur:question:stress-bar-meaning`.
diff --git a/src/BadDay.Cli/Program.cs b/src/BadDay.Cli/Program.cs
index ef64860..a84da66 100644
--- a/src/BadDay.Cli/Program.cs
+++ b/src/BadDay.Cli/Program.cs
@@ -135,6 +135,7 @@ public static class Program
$"(left {OfficeBody.CountStrikes(b.HandL, rage, end)}, right {OfficeBody.CountStrikes(b.HandR, rage, end)}), " +
$"{b.Strikes(0, rage)} before it");
}
+ else if (b.Run.Outcome == Outcome.WillBroke) output.WriteLine($"the will broke but --max ended the run at {b.Run.EndMs} ms, before the rage took over");
else output.WriteLine($"no rage: the will held to {b.Run.EndMs} ms");
return 0;
}
diff --git a/src/BadDay.Core/Cause.cs b/src/BadDay.Core/Cause.cs
index a281b15..bb8bb03 100644
--- a/src/BadDay.Core/Cause.cs
+++ b/src/BadDay.Core/Cause.cs
@@ -33,22 +33,11 @@ public sealed record Stressor(
}
///
-/// What goes wrong: the stressors, the objective's pull, and the sense nerve the character hears and sees them
-/// with. It holds no geometry (that is the 's). Code defaults, not persisted.
+/// What goes wrong: the stressors and the objective's pull (the job). It holds no geometry (the 's)
+/// and no senses (the 's). Code defaults, not persisted.
///
-public sealed record Cause(IReadOnlyList Stressors, double ObjectivePull, NerveParameters Senses)
+public sealed record Cause(IReadOnlyList Stressors, double ObjectivePull)
{
- ///
- /// The office's sense nerve: threshold 0.05, no sensitisation, no conduction delay. The office's break near
- /// 90 s at pull 0.6 holds only with these; Lodur's NerveParameters defaults break at about 100 s.
- ///
- public static NerveParameters OfficeSenses { get; } = new()
- {
- Threshold = 0.05,
- SensitisationGrowth = 0.0,
- ConductionDelaySeconds = 0.0,
- };
-
///
/// The office's sensory-load cause [P]: printer audio 5 s on, every 8 s for 1 s at 0.25; ceiling light 15 s
/// every 11 s for 2 s at 0.2; desk phone 25 s every 14 s for 3 s at 0.35; desktop interrupt 75 s every 20 s for
@@ -60,7 +49,7 @@ public sealed record Cause(IReadOnlyList Stressors, double ObjectivePu
new Stressor("ceiling-light", "ceiling-light", 15.0, 0.0, 11.0, 2.0, 0.2, 0.1),
new Stressor("desk-phone", "desk-phone", 25.0, 0.0, 14.0, 3.0, 0.35, 0.1),
new Stressor("desktop-interrupt", "desktop", 75.0, 0.0, 20.0, 1.0, 0.3, 0.1),
- }, 0.6, OfficeSenses);
+ }, 0.6);
/// Every stressor's intensity times .
public Cause Scaled(double factor) => this with
diff --git a/src/BadDay.Core/Character.cs b/src/BadDay.Core/Character.cs
new file mode 100644
index 0000000..0dad4d3
--- /dev/null
+++ b/src/BadDay.Core/Character.cs
@@ -0,0 +1,22 @@
+using Lodur;
+
+namespace BadDay.Core;
+
+///
+/// Who has the bad day: the character's own nervous parameters, apart from the (where) and the
+/// (why). Today that is the sense nerve he hears and sees with; his goals are 's.
+/// A character is code for now and becomes content with the Brains (follow-up npc-brains-as-content).
+///
+public sealed record Character(string Id, NerveParameters Senses)
+{
+ ///
+ /// Office Fella: threshold 0.05, no sensitisation, no conduction delay. The office's break near 90 s at pull 0.6
+ /// holds only with these; Lodur's NerveParameters defaults break at about 100 s.
+ ///
+ public static Character OfficeFella { get; } = new("office-fella", new NerveParameters
+ {
+ Threshold = 0.05,
+ SensitisationGrowth = 0.0,
+ ConductionDelaySeconds = 0.0,
+ });
+}
diff --git a/src/BadDay.Core/OfficeBrain.cs b/src/BadDay.Core/OfficeBrain.cs
index d2363ec..6778495 100644
--- a/src/BadDay.Core/OfficeBrain.cs
+++ b/src/BadDay.Core/OfficeBrain.cs
@@ -29,6 +29,9 @@ public static class OfficeBrain
public const int ComposureIndex = 0;
public const int RageIndex = 1;
+ /// The rage goal's id: what the scenario's release waits for.
+ public const string RageId = "rage";
+
public static OfficeGoal GoalAt(int index) => index == RageIndex ? OfficeGoal.Rage : OfficeGoal.KeepComposure;
public static Brain Build(StressParameters p, OfficePoses poses) => new()
@@ -45,7 +48,7 @@ public static class OfficeBrain
},
new GoalSpec
{
- Id = "rage",
+ Id = RageId,
Priority = 1.0,
Pull = 0.0,
When = new[] { new Condition(DriveQuantity.WillBroken, ConditionOp.AtLeast, 1.0) },
diff --git a/src/BadDay.Core/StressParameters.cs b/src/BadDay.Core/StressParameters.cs
index 642da4b..670a4d4 100644
--- a/src/BadDay.Core/StressParameters.cs
+++ b/src/BadDay.Core/StressParameters.cs
@@ -17,7 +17,11 @@ public sealed record StressParameters
/// Seconds from one rage key to the next [P]: wind-up left, strike left, wind-up right, strike right.
public double RageKeySeconds { get; init; } = 0.25;
+ /// The id of the Brain goal whose takeover starts the release: the run ends after that goal's GoalChanged, and a change to any other goal does not. The session refuses an id the Brain lacks.
+ public string ReleaseGoalId { get; init; } = OfficeBrain.RageId;
+
public Setting Setting { get; init; } = Setting.Office;
+ public Character Character { get; init; } = Character.OfficeFella;
public Cause Cause { get; init; } = Cause.Office;
// Lodur's records. The noxious nerve and the reflex idle here (no box); Hold is the composure goal's pose behaviour, which only a body reads.
diff --git a/src/BadDay.Core/StressSession.cs b/src/BadDay.Core/StressSession.cs
index 829dd1a..d04d7a4 100644
--- a/src/BadDay.Core/StressSession.cs
+++ b/src/BadDay.Core/StressSession.cs
@@ -10,7 +10,7 @@ namespace BadDay.Core;
/// per step, and the player's lever is . 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 (): the session goes on past the break, logs the
-/// tick the Actor commits the switch, and ends ReleaseSeconds after it, or at MaxSeconds.
+/// tick the Actor commits the switch, and ends ReleaseSeconds after the Brain's release goal () takes over, or at MaxSeconds.
///
public sealed class StressSession
{
@@ -24,6 +24,7 @@ public sealed class StressSession
private readonly long _maxTick;
private readonly long _sampleEvery;
private readonly long _releaseTicks;
+ private readonly int _releaseGoal;
private long _breakTick = -1;
private double _minResolve = 1.0;
private Outcome _outcome = Outcome.Endured;
@@ -64,10 +65,13 @@ public sealed class StressSession
Actor = new Actor(p.TickSeconds, regionCount, p.Nerve, p.Reflex,
p.Drive with { DrainTrait = p.Drive.DrainTrait * drainTrait },
OfficeBrain.Build(p, poses),
- p.Cause.Senses with { Gain = p.Cause.Senses.Gain * gainTrait }, senseRegion);
+ p.Character.Senses with { Gain = p.Character.Senses.Gain * gainTrait }, senseRegion);
_maxTick = Ticks(p.MaxSeconds);
_sampleEvery = Math.Max(1, Ticks(p.SampleEverySeconds));
_releaseTicks = Ticks(p.ReleaseSeconds);
+ _releaseGoal = -1;
+ for (int g = 0; g < Actor.Brain.Goals.Count; g++) if (Actor.Brain.Goals[g].Id == p.ReleaseGoalId) _releaseGoal = g;
+ if (_releaseGoal < 0) throw new ArgumentException($"the Brain has no goal '{p.ReleaseGoalId}' to release on");
_endTick = _maxTick;
}
@@ -124,7 +128,7 @@ public sealed class StressSession
if (tick % _sampleEvery == 0) Log(tick, StressEntryKind.Sample);
if ((events & TickEvents.GoalChanged) != 0)
{
- _endTick = Math.Min(_maxTick, tick + _releaseTicks);
+ if (Actor.GoalIndex == _releaseGoal) _endTick = Math.Min(_maxTick, tick + _releaseTicks);
Log(tick, StressEntryKind.GoalChanged);
}
if (tick >= _endTick)
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index 31c9235..355f08c 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -491,8 +491,8 @@ public static class Program
var ids = Setting.Office.Emitters.Select(e => e.Id).ToHashSet();
Check(Cause.Office.Stressors.All(s => ids.Contains(s.EmitterId)), "a stressor names an emitter the setting lacks");
Check(Setting.Office.Emitters.All(e => e.Emitter.Intensity == 0.0), "the setting carries an intensity");
- Check(Cause.Office.Senses.Threshold == 0.05 && Cause.Office.Senses.SensitisationGrowth == 0.0 && Cause.Office.Senses.ConductionDelaySeconds == 0.0,
- "the office does not pass its own sense parameters");
+ Check(Character.OfficeFella.Senses.Threshold == 0.05 && Character.OfficeFella.Senses.SensitisationGrowth == 0.0 && Character.OfficeFella.Senses.ConductionDelaySeconds == 0.0,
+ "Office Fella does not carry his own sense parameters");
}),
("office: the same seed gives the same bytes, and sessions stepped in turn equal each run alone", () =>
@@ -529,7 +529,7 @@ public static class Program
("office: the break sits near 90 s at pull 0.6 with the office sense nerve, and Lodur's default nerve breaks later", () =>
{
long own = MedianBreak(new StressParameters(), 1, 20);
- long lodurDefault = MedianBreak(new StressParameters { Cause = Cause.Office with { Senses = new Lodur.NerveParameters() } }, 1, 20);
+ long lodurDefault = MedianBreak(new StressParameters { Character = Character.OfficeFella with { Senses = new Lodur.NerveParameters() } }, 1, 20);
Check(own is > 75000 and < 100000, $"median break {own} ms");
Check(lodurDefault > own * 1.05, $"default nerve breaks at {lodurDefault} ms, office nerve at {own} ms");
}),
@@ -670,6 +670,14 @@ public static class Program
}
}),
+ ("office --body: a break whose rage --max clipped is reported as clipped, not as a will that held", () =>
+ {
+ var w = new StringWriter();
+ BadDay.Cli.Program.Execute(new[] { "office", "--seed", "1", "--max", "83.4", "--body" }, w);
+ var text = w.ToString();
+ Check(text.Contains("will broke at 83358 ms") && text.Contains("--max") && !text.Contains("the will held"), $"clipped run reads: {text.Split((char)10, StringSplitOptions.RemoveEmptyEntries)[^1]}");
+ }),
+
("office: a silence at S seconds lands on the tick S falls on: exactly, rounded to nearest, never early or late", () =>
{
long SilencedAt(double seconds) =>
@@ -704,7 +712,7 @@ public static class Program
var spelledOut = p with
{
TraitJitter = 0.0,
- Cause = steady with { Senses = steady.Senses with { Gain = steady.Senses.Gain * gain } },
+ Character = p.Character with { Senses = p.Character.Senses with { Gain = p.Character.Senses.Gain * gain } },
Drive = p.Drive with { DrainTrait = p.Drive.DrainTrait * drain },
};
Check(Office(p, seed).Render() == Office(spelledOut, seed).Render(), $"seed {seed}: the traits are not the first two draws, gain then drain");
@@ -751,6 +759,16 @@ public static class Program
Check(clipped.Outcome == Outcome.WillBroke && clipped.EndMs == 85000 && clipped.Timeline.All(e => e.Kind != StressEntryKind.Endured), $"a release past MaxSeconds ended at {clipped.EndMs}");
}),
+ ("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}");
+ bool threw = false;
+ try { NewOffice(new StressParameters { ReleaseGoalId = "calm" }, 1); } catch (ArgumentException) { threw = true; }
+ Check(threw, "a release goal the Brain lacks was accepted");
+ }),
+
("office rage: a will that holds never switches, and the job's pull is the composure goal's alone", () =>
{
var quiet = Office(new StressParameters { Cause = Cause.Office with { Stressors = Array.Empty() } }, 1);
@@ -760,7 +778,7 @@ public static class Program
Check(brain.Goals[OfficeBrain.ComposureIndex].Pull == p.Cause.ObjectivePull && brain.Goals[OfficeBrain.RageIndex].Pull == 0.0, "the pulls are not the cause's and zero");
}),
- ("office body: the rage is visible: both hands move at least 3x faster, and over 0.5 m/s, in the 2 s after the switch than in the 2 s before, the pelvis stays within 1 cm, and two runs agree", () =>
+ ("office body: the rage is visible: both hands move at least 3x faster, and over 1 m/s (a limp rage gives 0.6), in the 2 s after the switch than in the 2 s before, the pelvis stays within 1 cm, and two runs agree", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
var a = OfficeBody.Run(p, 1);
@@ -782,18 +800,23 @@ public static class Program
foreach (var (name, hand) in new[] { ("left", a.HandL), ("right", a.HandR) })
{
double before = Rms(hand, sw - 2 * Hz, sw), after = Rms(hand, sw, sw + 2 * Hz);
- Check(after >= 3 * before && after > 0.5, $"{name} hand: {after:F3} m/s after the switch, {before:F3} m/s before");
+ Check(after >= 3 * before && after > 1.0, $"{name} hand: {after:F3} m/s after the switch, {before:F3} m/s before");
}
- Check(a.Strikes(0, sw) == 0 && a.Strikes(sw, a.HandL.Count) >= 8, $"strikes: {a.Strikes(0, sw)} before the switch, {a.Strikes(sw, a.HandL.Count)} after");
+ Check(a.Strikes(0, sw) == 0 && a.Strikes(sw, a.HandL.Count) >= 11, $"strikes: {a.Strikes(0, sw)} before the switch, {a.Strikes(sw, a.HandL.Count)} after");
+ // The strike reaches forward: the shoulder's angle shows in how far the fist gets ahead of where the composed hand hung.
+ double Reach(IReadOnlyList h) => h.Skip(sw).Max(q => q.Z) - h[sw - 1].Z;
+ Check(Reach(a.HandL) > 0.58 && Reach(a.HandR) > 0.54, $"the strikes reach {Reach(a.HandL):F3} m (left) and {Reach(a.HandR):F3} m (right) ahead of the composed hand");
+ var rage = OfficeBrain.Build(p, OfficeBody.Poses).Goals[OfficeBrain.RageIndex].Behaviour;
+ Check(rage.Hold.HoldStrength == 1f, "the rage does not write full muscle strength");
float drift = a.Pelvis.Max(q => MathF.Sqrt(MathF.Pow(q.X - a.Pelvis[0].X, 2) + MathF.Pow(q.Y - a.Pelvis[0].Y, 2) + MathF.Pow(q.Z - a.Pelvis[0].Z, 2)));
Check(drift < 0.01f, $"the pelvis moved {drift:F4} m");
}),
- ("office body: the desk's emitters are sensed at the head, so the body breaks within 5 s of the headless run", () =>
+ ("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;
var headless = Office(new StressParameters(), 1);
- Check(Math.Abs(body.TimeToBreakMs!.Value - headless.TimeToBreakMs!.Value) < 5000, $"body {body.TimeToBreakMs} ms, headless {headless.TimeToBreakMs} ms");
+ Check(Math.Abs(body.TimeToBreakMs!.Value - headless.TimeToBreakMs!.Value) < 500, $"body {body.TimeToBreakMs} ms, headless {headless.TimeToBreakMs} ms");
}),
};