diff --git a/Aplib.Core.Tests/Intent/Tactics/TacticTests.cs b/Aplib.Core.Tests/Intent/Tactics/TacticTests.cs index aaa1517..b9ee185 100644 --- a/Aplib.Core.Tests/Intent/Tactics/TacticTests.cs +++ b/Aplib.Core.Tests/Intent/Tactics/TacticTests.cs @@ -34,25 +34,25 @@ public class TestFirstOfTactic : FirstOfTactic { public System.Predicate Guard => _guard; - public LinkedList> SubTactics => _subTactics; + public LinkedList> Subtactics => _subtactics; public TestFirstOfTactic - (Metadata metadata, System.Predicate guard, params ITactic[] subTactics) - : base(metadata, guard, subTactics) + (Metadata metadata, System.Predicate guard, params ITactic[] subtactics) + : base(metadata, guard, subtactics) { } - public TestFirstOfTactic(Metadata metadata, params ITactic[] subTactics) - : base(metadata, subTactics) + public TestFirstOfTactic(Metadata metadata, params ITactic[] subtactics) + : base(metadata, subtactics) { } - public TestFirstOfTactic(System.Predicate guard, params ITactic[] subTactics) - : base(guard, subTactics) + public TestFirstOfTactic(System.Predicate guard, params ITactic[] subtactics) + : base(guard, subtactics) { } - public TestFirstOfTactic(params ITactic[] subTactics) : base(subTactics) { } + public TestFirstOfTactic(params ITactic[] subtactics) : base(subtactics) { } } @@ -193,15 +193,15 @@ public void FirstOfTacticTactic_WhenConstructed_HasExpectedData() // Arrange Metadata metadata = It.IsAny(); System.Predicate guard = It.IsAny>(); - ITactic[] subTactics = [It.IsAny>()]; + ITactic[] subtactics = [It.IsAny>()]; // Act - TestFirstOfTactic tactic = new(metadata, guard, subTactics); + TestFirstOfTactic tactic = new(metadata, guard, subtactics); // Assert tactic.Metadata.Should().Be(metadata); tactic.Guard.Should().Be(guard); - tactic.SubTactics.Should().BeEquivalentTo(subTactics); + tactic.Subtactics.Should().BeEquivalentTo(subtactics); } [Fact] @@ -209,15 +209,15 @@ public void FirstOfTacticTactic_WithoutGuard_HasExpectedData() { // Arrange Metadata metadata = It.IsAny(); - ITactic[] subTactics = [It.IsAny>()]; + ITactic[] subtactics = [It.IsAny>()]; // Act - TestFirstOfTactic tactic = new(metadata, subTactics); + TestFirstOfTactic tactic = new(metadata, subtactics); // Assert tactic.Metadata.Should().Be(metadata); tactic.Guard(It.IsAny()).Should().BeTrue(); - tactic.SubTactics.Should().BeEquivalentTo(subTactics); + tactic.Subtactics.Should().BeEquivalentTo(subtactics); } [Fact] @@ -225,34 +225,34 @@ public void FirstOfTacticTactic_WithoutMetadata_HasExpectedData() { // Arrange System.Predicate guard = It.IsAny>(); - ITactic[] subTactics = [It.IsAny>()]; + ITactic[] subtactics = [It.IsAny>()]; // Act - TestFirstOfTactic tactic = new(guard, subTactics); + TestFirstOfTactic tactic = new(guard, subtactics); // Assert tactic.Metadata.Id.Should().NotBeEmpty(); tactic.Metadata.Name.Should().BeNull(); tactic.Metadata.Description.Should().BeNull(); tactic.Guard.Should().Be(guard); - tactic.SubTactics.Should().BeEquivalentTo(subTactics); + tactic.Subtactics.Should().BeEquivalentTo(subtactics); } [Fact] public void FirstOfTacticTactic_WithoutMetadataWithoutGuard_HasExpectedData() { // Arrange - ITactic[] subTactics = [It.IsAny>()]; + ITactic[] subtactics = [It.IsAny>()]; // Act - TestFirstOfTactic tactic = new(subTactics); + TestFirstOfTactic tactic = new(subtactics); // Assert tactic.Metadata.Id.Should().NotBeEmpty(); tactic.Metadata.Name.Should().BeNull(); tactic.Metadata.Description.Should().BeNull(); tactic.Guard(It.IsAny()).Should().BeTrue(); - tactic.SubTactics.Should().BeEquivalentTo(subTactics); + tactic.Subtactics.Should().BeEquivalentTo(subtactics); } /// diff --git a/Aplib.Core/Intent/Tactics/AnyOfTactic.cs b/Aplib.Core/Intent/Tactics/AnyOfTactic.cs index b6afa7d..8db67a9 100644 --- a/Aplib.Core/Intent/Tactics/AnyOfTactic.cs +++ b/Aplib.Core/Intent/Tactics/AnyOfTactic.cs @@ -7,49 +7,49 @@ namespace Aplib.Core.Intent.Tactics { /// - /// Represents a tactic that executes any of the provided sub-tactics. + /// Represents a tactic that executes any of the provided subtactics. /// public class AnyOfTactic : Tactic where TBeliefSet : IBeliefSet { /// - /// Gets or sets the sub-tactics of the tactic. + /// Gets or sets the subtactics of the tactic. /// - protected readonly LinkedList> _subTactics; + protected internal readonly LinkedList> _subtactics; /// - /// Initializes a new instance of the class with the specified sub-tactics + /// Initializes a new instance of the class with the specified subtactics /// and an optional guard condition. /// /// /// Metadata about this tactic, used to quickly display the tactic in several contexts. /// /// The guard condition. - /// The list of subtactics. + /// The list of subtactics. public AnyOfTactic ( IMetadata metadata, System.Predicate guard, - params ITactic[] subTactics + params ITactic[] subtactics ) - : base(metadata, guard) => _subTactics = new LinkedList>(subTactics); + : base(metadata, guard) => _subtactics = new LinkedList>(subtactics); /// public AnyOfTactic - (System.Predicate guard, params ITactic[] subTactics) - : this(new Metadata(), guard, subTactics) + (System.Predicate guard, params ITactic[] subtactics) + : this(new Metadata(), guard, subtactics) { } /// - public AnyOfTactic(IMetadata metadata, params ITactic[] subTactics) - : this(metadata, _ => true, subTactics) + public AnyOfTactic(IMetadata metadata, params ITactic[] subtactics) + : this(metadata, _ => true, subtactics) { } /// - public AnyOfTactic(params ITactic[] subTactics) - : this(new Metadata(), _ => true, subTactics) + public AnyOfTactic(params ITactic[] subtactics) + : this(new Metadata(), _ => true, subtactics) { } @@ -60,7 +60,7 @@ public AnyOfTactic(params ITactic[] subTactics) List> actions = new(); - foreach (ITactic subTactic in _subTactics) + foreach (ITactic subTactic in _subtactics) { IAction? action = subTactic.GetAction(beliefSet); @@ -73,6 +73,6 @@ public AnyOfTactic(params ITactic[] subTactics) } /// - public override IEnumerable GetLogChildren() => _subTactics.OfType(); + public override IEnumerable GetLogChildren() => _subtactics.OfType(); } } diff --git a/Aplib.Core/Intent/Tactics/FirstOfTactic.cs b/Aplib.Core/Intent/Tactics/FirstOfTactic.cs index 44f9e31..dc1fd27 100644 --- a/Aplib.Core/Intent/Tactics/FirstOfTactic.cs +++ b/Aplib.Core/Intent/Tactics/FirstOfTactic.cs @@ -1,55 +1,67 @@ using Aplib.Core.Belief.BeliefSets; using Aplib.Core.Intent.Actions; +using Aplib.Core.Logging; +using System.Collections.Generic; using System.Linq; namespace Aplib.Core.Intent.Tactics { /// - /// Represents a tactic that executes the first enabled action from a list of sub-tactics. + /// Represents a tactic that executes the first enabled action from a list of subtactics. /// - public class FirstOfTactic : AnyOfTactic + public class FirstOfTactic : Tactic where TBeliefSet : IBeliefSet { + /// + /// Gets or sets the subtactics of the tactic. + /// + protected internal readonly LinkedList> _subtactics; + /// /// Initializes a new instance of the class with the specified - /// sub-tactics and guard condition. + /// subtactics and guard condition. /// /// /// Metadata about this tactic, used to quickly display the tactic in several contexts. /// /// The guard condition. - /// The list of subtactics. + /// The list of subtactics. public FirstOfTactic - (IMetadata metadata, System.Predicate guard, params ITactic[] subTactics) - : base(metadata, guard, subTactics) - { - } + ( + IMetadata metadata, + System.Predicate guard, + params ITactic[] subtactics + ) + : base(metadata, guard) => _subtactics = new LinkedList>(subtactics); /// - public FirstOfTactic(IMetadata metadata, params ITactic[] subTactics) - : this(metadata, _ => true, subTactics) + public FirstOfTactic(IMetadata metadata, params ITactic[] subtactics) + : this(metadata, _ => true, subtactics) { } /// public FirstOfTactic - (System.Predicate guard, params ITactic[] subTactics) - : this(new Metadata(), guard, subTactics) + (System.Predicate guard, params ITactic[] subtactics) + : this(new Metadata(), guard, subtactics) { } /// - public FirstOfTactic(params ITactic[] subTactics) : this(new Metadata(), _ => true, subTactics) { } + public FirstOfTactic(params ITactic[] subtactics) : this(new Metadata(), _ => true, subtactics) { } /// public override IAction? GetAction(TBeliefSet beliefSet) { if (!IsActionable(beliefSet)) return null; - return _subTactics + return _subtactics .Select(subTactic => subTactic.GetAction(beliefSet)) .OfType>() .FirstOrDefault(); } + + /// + public override IEnumerable GetLogChildren() => _subtactics.OfType(); } }