diff --git a/src/Lodur.Core/Actor.cs b/src/Lodur.Core/Actor.cs
index dab7755..68a2c7d 100644
--- a/src/Lodur.Core/Actor.cs
+++ b/src/Lodur.Core/Actor.cs
@@ -82,6 +82,13 @@ namespace Lodur
/// A snapshot of the drive; nothing but writes it.
public DriveState Drive => _drive;
+ /// Sets the drive's Attention and Consciousness slots; a seam for the tests until lodur-startle-attention and lodur-physiology drive them.
+ internal void SetWillSlots(double attention, double consciousness)
+ {
+ _drive.Attention = attention;
+ _drive.Consciousness = consciousness;
+ }
+
public Brain Brain => _brain;
/// The index in 's goals of the goal in force; it changes only on the tick that reports .
diff --git a/src/Lodur.Core/DriveState.cs b/src/Lodur.Core/DriveState.cs
index 5b59a66..6d493b9 100644
--- a/src/Lodur.Core/DriveState.cs
+++ b/src/Lodur.Core/DriveState.cs
@@ -90,16 +90,16 @@ namespace Lodur
/// How many times the will has broken.
public int Breaks { get; private set; }
- /// The fraction of resolve that attention lets through, 0..1. A slot: nothing lowers it yet (lodur-startle-attention fills it).
- public double Attention => 1.0;
+ /// The fraction of resolve that attention lets through, 0..1. A slot, 1 until lodur-startle-attention fills it.
+ public double Attention { get; internal set; }
- /// The ceiling on the will that wakefulness sets, 0..1. A slot: nothing lowers it yet (lodur-physiology fills it).
- public double Consciousness => 1.0;
+ /// The ceiling on the will that wakefulness sets, 0..1. A slot, 1 until lodur-physiology fills it.
+ public double Consciousness { get; internal set; }
/// The will that is available to hold reflexes down and to power voluntary behaviour: resolve through attention, capped by consciousness.
public double Will => Math.Min(Resolve * Attention, Consciousness);
- internal static DriveState Fresh => new DriveState { Resolve = 1.0 };
+ internal static DriveState Fresh => new DriveState { Resolve = 1.0, Attention = 1.0, Consciousness = 1.0 };
/// A goal's entry effect: sets resolve, then the mend check runs (a break the entry lifts past is mended). It is not a break and counts none.
internal void Enter(DriveParameters p, double resolve)
diff --git a/src/Lodur.Core/Lodur.Core.csproj b/src/Lodur.Core/Lodur.Core.csproj
index 9588aab..b39e30e 100644
--- a/src/Lodur.Core/Lodur.Core.csproj
+++ b/src/Lodur.Core/Lodur.Core.csproj
@@ -7,4 +7,9 @@
Lodur
+
+
+
+
+
diff --git a/tests/Lodur.Core.Tests/WillTests.cs b/tests/Lodur.Core.Tests/WillTests.cs
index 0351846..c1c720d 100644
--- a/tests/Lodur.Core.Tests/WillTests.cs
+++ b/tests/Lodur.Core.Tests/WillTests.cs
@@ -397,4 +397,100 @@ public sealed class WillTests
var calm = new Actor(0.01, 1, new NerveParameters(), new WithdrawalParameters(), new DriveParameters(), brain with { Start = 0 });
Assert.Equal(1.0, calm.Drive.Resolve);
}
+
+ // The slots read 1 in the core today; these tests lower them through the internal seam and watch every consumer of Will move.
+
+ private static Actor Hold(double attention, double consciousness, DriveParameters? drive = null)
+ {
+ var brain = new Brain { Goals = new[] { new GoalSpec { Id = "g", Behaviour = new PoseBehaviour { Keys = new[] { PainBoxBrain.Hold }, FlinchPose = PainBoxBrain.Withdraw, Hold = Hold07 } } } };
+ var actor = new Actor(0.01, 1, new NerveParameters(), new WithdrawalParameters(), drive ?? new DriveParameters(), brain);
+ actor.SetWillSlots(attention, consciousness);
+ return actor;
+ }
+
+ private static readonly float[] NoPoint = { 0f };
+
+ private static TickEvents Step(Actor a, double boxIntensity, float[] strengths, Quat[] targets)
+ {
+ var box = new[] { new BoxStimulus(0f, 0f, 0f, 1f, 1f, 1f) { Intensity = boxIntensity } };
+ return a.Tick(NoPoint, NoPoint, NoPoint, box, strengths, targets);
+ }
+
+ [Theory]
+ [InlineData(1.0, 1.0)]
+ [InlineData(0.5, 1.0)]
+ [InlineData(1.0, 0.3)]
+ [InlineData(0.5, 0.3)]
+ [InlineData(0.5, 0.9)]
+ [InlineData(0.0, 1.0)]
+ public void Will_is_resolve_times_attention_capped_by_consciousness(double attention, double consciousness)
+ {
+ var a = Hold(attention, consciousness);
+ var s = new float[2];
+ var q = new Quat[2];
+ for (var i = 0; i < 300; i++)
+ {
+ Step(a, 0.6, s, q);
+ var d = a.Drive;
+ Assert.Equal(Math.Min(d.Resolve * attention, consciousness), d.Will);
+ }
+ }
+
+ [Fact]
+ public void Reflex_suppression_reads_Will_so_a_lowered_slot_releases_it_though_resolve_is_full()
+ {
+ // A held reflex accrues strain; with attention gone nothing is held, whatever resolve says.
+ double StrainAfter(double attention, double consciousness)
+ {
+ var a = Hold(attention, consciousness);
+ var s = new float[2];
+ var q = new Quat[2];
+ for (var i = 0; i < 100; i++) Step(a, 0.8, s, q);
+ Assert.True(a.Drive.Resolve > 0.9);
+ return a.Drive.Strain;
+ }
+
+ var full = StrainAfter(1.0, 1.0);
+ Assert.True(full > 0.1);
+ Assert.Equal(0.0, StrainAfter(0.0, 1.0));
+ Assert.Equal(0.0, StrainAfter(1.0, 0.0));
+ var half = StrainAfter(0.5, 1.0);
+ Assert.True(half > 0.0 && half < full);
+ var capped = StrainAfter(1.0, 0.5);
+ Assert.True(capped > 0.0 && capped < full);
+ }
+
+ [Fact]
+ public void The_flinch_gate_reads_Will_so_no_flinch_is_reported_when_there_is_no_will_to_leak_from()
+ {
+ int Flinches(double attention)
+ {
+ var a = Hold(attention, 1.0);
+ var s = new float[2];
+ var q = new Quat[2];
+ var n = 0;
+ for (var i = 0; i < 400; i++) if ((Step(a, 0.9, s, q) & TickEvents.Flinch) != 0) n++;
+ Assert.True(a.Drive.Resolve > 0.5);
+ return n;
+ }
+
+ Assert.True(Flinches(0.3) > 0);
+ Assert.Equal(0, Flinches(0.0));
+ }
+
+ [Theory]
+ [InlineData(0.5, 1.0)]
+ [InlineData(1.0, 0.2)]
+ [InlineData(0.5, 0.4)]
+ public void The_voluntary_weight_reads_Will_so_a_lowered_slot_slackens_the_hold(double attention, double consciousness)
+ {
+ var a = Hold(attention, consciousness, new DriveParameters { WillCurve = 0.5 });
+ var s = new float[2];
+ var q = new Quat[2];
+ for (var i = 0; i < 20; i++)
+ {
+ Step(a, 0.0, s, q); // no stimulus, no leak
+ Assert.Equal(0.7f * (float)Math.Sqrt(Math.Min(a.Drive.Resolve * attention, consciousness)), s[0]);
+ }
+ }
}