Chamber: the release is the declared withdraw goal, and the withdrawal is one-way and involuntary
PainBoxSession read any GoalChanged as the withdrawal; PainBoxParameters.ReleaseGoalId (default ChamberBrain.WithdrawId) now names the goal, resolved at construction and refused if the Brain lacks it. The withdraw goal gates on Breaks >= 1 (never falls) and is involuntary for good, so the will mending neither gives the hand back nor weakens the withdrawal. Disabled() reads Breaks, BodyPainBox keeps the first break as the snap. Tests: the one-way chamber, release by id, and the flinch-gain-0 control run with a will that costs no strength (its premise, that the arm does not feed back into the drive, fails once strength follows will). Pain box golden and parity hashes unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1b7dea0d06
commit
f98f3f9cf1
5 changed files with 57 additions and 11 deletions
|
|
@ -14,6 +14,9 @@ public static class ChamberBrain
|
|||
public const int HoldIndex = 0;
|
||||
public const int WithdrawIndex = 1;
|
||||
|
||||
/// <summary>The withdraw goal's id: what the pain box's release waits for (<see cref="PainBoxParameters.ReleaseGoalId"/>).</summary>
|
||||
public const string WithdrawId = "withdraw";
|
||||
|
||||
/// <summary>The objective's pull for the payment: 0 for nothing, 0.5 at <see cref="PainBoxParameters.DollarsAtHalfPull"/>, toward 1 for more.</summary>
|
||||
public static double Pull(PainBoxParameters p)
|
||||
{
|
||||
|
|
@ -27,8 +30,10 @@ public static class ChamberBrain
|
|||
|
||||
/// <summary>
|
||||
/// hold-hand: always eligible, priority 0, the payment's pull, the hold pose with the reflex leak and strain shake
|
||||
/// pulling toward the withdraw pose. withdraw: eligible once the will has broken, priority 1, no pull, the withdraw
|
||||
/// pose with no leak or shake.
|
||||
/// pulling toward the withdraw pose. withdraw: eligible once the will has broken (<see cref="DriveQuantity.Breaks"/>, which
|
||||
/// never falls, so the goal is one-way: the will mending does not give the hand back), priority 1, no pull, involuntary
|
||||
/// for good (the withdrawal is the body's, it costs no will and does not weaken as the will mends), the withdraw pose
|
||||
/// with no leak or shake.
|
||||
/// </summary>
|
||||
public static Brain Build(PainBoxParameters p, ReadOnlySpan<Quat> hold, ReadOnlySpan<Quat> withdraw)
|
||||
{
|
||||
|
|
@ -48,10 +53,11 @@ public static class ChamberBrain
|
|||
},
|
||||
new GoalSpec
|
||||
{
|
||||
Id = "withdraw",
|
||||
Id = WithdrawId,
|
||||
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) },
|
||||
InvoluntarySeconds = double.PositiveInfinity,
|
||||
Behaviour = new PoseBehaviour
|
||||
{
|
||||
Keys = new[] { withdrawPose },
|
||||
|
|
|
|||
|
|
@ -34,5 +34,8 @@ public sealed record PainBoxParameters
|
|||
// Per-seed trait spread (fraction): nociceptor gain and resolve drain. The seed's draw multiplies Nerve.Gain and Drive.DrainTrait.
|
||||
public double TraitJitter { get; init; } = 0.2;
|
||||
|
||||
/// <summary>The id of the Brain goal whose takeover is the withdrawal: the session's Withdrew, its Withdrew row and its WillBroke outcome come from that goal's GoalChanged and no other. The session refuses an id the Brain lacks.</summary>
|
||||
public string ReleaseGoalId { get; init; } = ChamberBrain.WithdrawId;
|
||||
|
||||
public double SampleEverySeconds { get; init; } = 1.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public sealed class PainBoxSession
|
|||
private readonly long _maxTick;
|
||||
private readonly long _sampleEvery;
|
||||
private readonly int _handRegion;
|
||||
private readonly int _releaseGoal;
|
||||
private double _stimulus;
|
||||
private long _breakTick = -1;
|
||||
private int _flinches;
|
||||
|
|
@ -40,6 +41,9 @@ public sealed class PainBoxSession
|
|||
Seed = seed;
|
||||
Actor = new Actor(p.TickSeconds, regionCount, p.Nerve with { Gain = p.Nerve.Gain * gainTrait }, p.Reflex,
|
||||
p.Drive with { DrainTrait = p.Drive.DrainTrait * drainTrait }, ChamberBrain.Build(p, holdPose, withdrawPose));
|
||||
_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");
|
||||
_box = new PainBox(p, rng);
|
||||
_sources = new[] { box };
|
||||
_maxTick = Ticks(p.MaxSeconds);
|
||||
|
|
@ -59,7 +63,7 @@ public sealed class PainBoxSession
|
|||
/// <summary>True once the run is over: the box was disabled, the time ran out, or the caller ended it.</summary>
|
||||
public bool Finished { get; private set; }
|
||||
|
||||
/// <summary>True from the tick the Brain's withdraw goal takes over, its deliberate latency after the will breaks.</summary>
|
||||
/// <summary>True from the tick the Brain's release goal (<see cref="PainBoxParameters.ReleaseGoalId"/>, the withdraw goal) takes over, its deliberate latency after the will breaks.</summary>
|
||||
public bool Withdrew { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -77,12 +81,12 @@ public sealed class PainBoxSession
|
|||
|
||||
/// <summary>
|
||||
/// The disable check, before ticking: if the box switches off now while the will still holds, the run ends
|
||||
/// with the will intact and this returns true. A will already broken is not given back by the box going off.
|
||||
/// with the will intact and this returns true. A will that has broken is not given back by the box going off, even once it mends.
|
||||
/// </summary>
|
||||
public bool Disabled()
|
||||
{
|
||||
long tick = TickIndex;
|
||||
if (tick != _box.DisableTick || Actor.Drive.WillBroken) return false;
|
||||
if (tick != _box.DisableTick || Actor.Drive.Breaks > 0) return false;
|
||||
_stimulus = 0.0;
|
||||
_outcome = Outcome.BoxDisabled;
|
||||
_endTick = tick;
|
||||
|
|
@ -114,7 +118,7 @@ public sealed class PainBoxSession
|
|||
Log(tick, EntryKind.WillBroke);
|
||||
}
|
||||
if (tick % _sampleEvery == 0) Log(tick, EntryKind.Sample);
|
||||
if ((events & TickEvents.GoalChanged) != 0)
|
||||
if ((events & TickEvents.GoalChanged) != 0 && Actor.GoalIndex == _releaseGoal)
|
||||
{
|
||||
Withdrew = true;
|
||||
_outcome = Outcome.WillBroke;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public sealed class BodyPainBoxSession : IDisposable
|
|||
_hand = sample;
|
||||
if (!ticked) return;
|
||||
|
||||
if ((events & TickEvents.WillBroke) != 0) _breakTick = tick;
|
||||
if ((events & TickEvents.WillBroke) != 0 && _breakTick < 0) _breakTick = tick; // the snap: a later break after a mend is not the first
|
||||
bool inBox = sample.InBox;
|
||||
|
||||
if (_breakTick < 0)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ public static class Program
|
|||
{
|
||||
private static readonly PainBoxParameters Default = new();
|
||||
private static readonly PainBoxParameters OnBody = new() { TickSeconds = BodyPainBox.TickSeconds };
|
||||
/// <summary>OnBody with a will that costs no strength (WillCurve toward 0 makes Will^WillCurve 1): the arm's strength is the same whatever the will, so a flinch-gain-0 control feeds nothing different back into the drive. The flinch test's premise.</summary>
|
||||
private static readonly PainBoxParameters Steady = OnBody with { Drive = new Lodur.DriveParameters { WillCurve = 1e-9 } };
|
||||
private const int Hz = 120;
|
||||
|
||||
private static readonly (string Name, Action Body)[] Tests =
|
||||
|
|
@ -210,8 +212,8 @@ public static class Program
|
|||
{
|
||||
for (ulong seed = 1; seed <= 3; seed++)
|
||||
{
|
||||
var full = BodyPainBox.Run(OnBody, seed);
|
||||
var control = BodyPainBox.Run(OnBody with { Hold = new Lodur.HoldParameters { FlinchGain = 0.0 } }, seed);
|
||||
var full = BodyPainBox.Run(Steady, seed);
|
||||
var control = BodyPainBox.Run(Steady with { Hold = new Lodur.HoldParameters { FlinchGain = 0.0 } }, seed);
|
||||
Check(full.Run.Flinches == control.Run.Flinches, $"seed {seed}: the nervous state changed with the arm");
|
||||
var flinches = full.Run.Timeline.Where(e => e.Kind == EntryKind.Flinch).Select(e => Tick(e.TimeMs)).ToList();
|
||||
float Gap(int i) => MathF.Sqrt(MathF.Pow(full.Hand[i].X - control.Hand[i].X, 2) + MathF.Pow(full.Hand[i].Y - control.Hand[i].Y, 2) + MathF.Pow(full.Hand[i].Z - control.Hand[i].Z, 2));
|
||||
|
|
@ -222,6 +224,37 @@ public static class Program
|
|||
}
|
||||
}),
|
||||
|
||||
("chamber: the withdrawal is one-way: ticked 90 s past it with the box off and the will mended, the goal stays Withdraw, and a box going off does not end the run as if the will held", () =>
|
||||
{
|
||||
var pose = new[] { Lodur.Quat.Identity };
|
||||
var session = new PainBoxSession(Default, 1, new Lodur.BoxStimulus(0f, 0f, 0f, 1f, 1f, 1f), 1, pose, pose);
|
||||
var point = new float[1];
|
||||
var strengths = new float[1];
|
||||
var targets = new Quat[1];
|
||||
while (!session.Withdrew) session.Tick(point, point, point, strengths, targets);
|
||||
session.SwitchOff();
|
||||
bool mended = false;
|
||||
for (int i = 0; i < 9000; i++)
|
||||
{
|
||||
session.Tick(point, point, point, strengths, targets);
|
||||
mended |= !session.Actor.Drive.WillBroken;
|
||||
Check(session.Actor.GoalIndex == ChamberBrain.WithdrawIndex, $"the goal left Withdraw {i} ticks after the withdrawal");
|
||||
}
|
||||
Check(mended, "the will never mended: the test no longer exercises the rule");
|
||||
Check(!session.Actor.Drive.WillBroken && session.Actor.Drive.Breaks > 0, "the will should be mended and the break still counted");
|
||||
Check(!session.Disabled(), "a box going off ended the run of a will that had broken and mended");
|
||||
}),
|
||||
|
||||
("chamber release: the withdrawal is the Brain's release goal by id, not any goal change; an id the Brain lacks is refused", () =>
|
||||
{
|
||||
var r = PainBoxSimulation.Run(Default with { ReleaseGoalId = "hold-hand", MaxSeconds = 30.0 }, 1);
|
||||
Check(r.Outcome == Outcome.Endured && r.Timeline.All(e => e.Kind != EntryKind.Withdrew) && r.TimeToBreakMs == 14730,
|
||||
$"releasing on a goal the Brain never switches to: outcome {r.Outcome}, break {r.TimeToBreakMs}");
|
||||
bool threw = false;
|
||||
try { PainBoxSimulation.Run(Default with { ReleaseGoalId = "nowhere" }, 1); } catch (ArgumentException) { threw = true; }
|
||||
Check(threw, "a release goal the Brain lacks was accepted");
|
||||
}),
|
||||
|
||||
("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)[]
|
||||
|
|
|
|||
Loading…
Reference in a new issue