Skip to content

Commit

Permalink
refactor: rename AnyOfTactic to RandomTactic (#74)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rename AnyOfTactic to RandomTactic
  • Loading branch information
JensSteenmetz authored Jun 23, 2024
1 parent 5fd567c commit 6ab1728
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions Aplib.Core.Tests/CombinatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public void AnyOfTacticCombinator_WhenCalled_GivesExpectedTactic
System.Predicate<IBeliefSet> guard = _ => false;

// Act
AnyOfTactic<IBeliefSet> anyOfTactic =
AnyOf(metadata, guard, Primitive(action1, _ => true), Primitive(action2, _ => false));
RandomTactic<IBeliefSet> anyOfTactic =
Random(metadata, guard, Primitive(action1, _ => true), Primitive(action2, _ => false));

IAction<IBeliefSet>? selectedAction = anyOfTactic.GetAction(It.IsAny<IBeliefSet>());

Expand All @@ -254,8 +254,8 @@ public void AnyOfTacticCombinator_WithoutMetadata_GivesExpectedTactic()
System.Predicate<IBeliefSet> guard = _ => false;

// Act
AnyOfTactic<IBeliefSet> anyOfTactic =
AnyOf(guard, Primitive(action1, _ => true), Primitive(action2, _ => false));
RandomTactic<IBeliefSet> anyOfTactic =
Random(guard, Primitive(action1, _ => true), Primitive(action2, _ => false));

IAction<IBeliefSet>? selectedAction = anyOfTactic.GetAction(It.IsAny<IBeliefSet>());

Expand All @@ -274,8 +274,8 @@ public void AnyOfTacticCombinator_WithoutGuard_GivesExpectedTactic
Action<IBeliefSet> action2 = new(_ => { });

// Act
AnyOfTactic<IBeliefSet> anyOfTactic =
AnyOf(metadata, Primitive(action1, _ => true), Primitive(action2, _ => false));
RandomTactic<IBeliefSet> anyOfTactic =
Random(metadata, Primitive(action1, _ => true), Primitive(action2, _ => false));

IAction<IBeliefSet>? selectedAction = anyOfTactic.GetAction(It.IsAny<IBeliefSet>());

Expand All @@ -292,7 +292,7 @@ public void AnyOfTacticCombinator_WithoutMetadataWithoutGuard_GivesExpectedTacti
Action<IBeliefSet> action2 = new(_ => { });

// Act
AnyOfTactic<IBeliefSet> anyOfTactic = AnyOf(Primitive(action1, _ => true), Primitive(action2, _ => false));
RandomTactic<IBeliefSet> anyOfTactic = Random(Primitive(action1, _ => true), Primitive(action2, _ => false));

IAction<IBeliefSet>? selectedAction = anyOfTactic.GetAction(It.IsAny<IBeliefSet>());

Expand Down
8 changes: 4 additions & 4 deletions Aplib.Core.Tests/Intent/Tactics/TacticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void PrimitveTacticExecute_WhenGuardReturnsTrue_ActionIsSelected()
public void AnyOfTactic_WithoutMetadata_ContainsDefaultMetadata()
{
// Act
AnyOfTactic<IBeliefSet> tactic = new(_ => true);
RandomTactic<IBeliefSet> tactic = new(_ => true);

// Assert
tactic.Metadata.Id.Should().NotBeEmpty();
Expand All @@ -151,7 +151,7 @@ public void AnyOfTactic_WithoutMetadata_ContainsDefaultMetadata()
}

/// <summary>
/// Given a parent of type <see cref="AnyOfTactic{TBeliefSet}" /> with two subtactics,
/// Given a parent of type <see cref="RandomTactic{TBeliefSet}" /> with two subtactics,
/// When getting the next tactic,
/// Then the result should be the action of an enabled tactic.
/// </summary>
Expand All @@ -163,7 +163,7 @@ public void AnyOfTacticGetAction_WhenASubtacticIsEnabled_ReturnsActionOfEnabledS
Action<IBeliefSet> action2 = new(_ => { });
PrimitiveTactic<IBeliefSet> tactic1 = new(action1, _ => true);
PrimitiveTactic<IBeliefSet> tactic2 = new(action2, _ => false);
AnyOfTactic<IBeliefSet> parentTactic = new(tactic1, tactic2);
RandomTactic<IBeliefSet> parentTactic = new(tactic1, tactic2);

// Act
IAction<IBeliefSet>? selectedAction = parentTactic.GetAction(It.IsAny<IBeliefSet>());
Expand All @@ -178,7 +178,7 @@ public void AnyOfTactic_WithFalseGuard_ReturnsNoAction()
// Arrange
Action<IBeliefSet> action = new(_ => { });
PrimitiveTactic<IBeliefSet> tactic = new(action, _ => true);
AnyOfTactic<IBeliefSet> parentTactic = new(_ => false, tactic);
RandomTactic<IBeliefSet> parentTactic = new(_ => false, tactic);

// Act
IAction<IBeliefSet>? selectedAction = parentTactic.GetAction(It.IsAny<IBeliefSet>());
Expand Down
2 changes: 1 addition & 1 deletion Aplib.Core.Tests/LoggableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void PrimitiveTactic_WhenGettingTree_ReturnsCorrectTree()
public void AnyOfTactic_WhenGettingTree_ReturnsCorrectTree()
{
// Arrange
AnyOfTactic<IBeliefSet> tactic = new(_tactic1, _tactic2);
RandomTactic<IBeliefSet> tactic = new(_tactic1, _tactic2);

LogNode tactic1Node = new(_tactic1, 1, [new LogNode(_action1, 2)]);
LogNode tactic2Node = new(_tactic2, 1, [new LogNode(_action2, 2)]);
Expand Down
16 changes: 8 additions & 8 deletions Aplib.Core/Combinators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ public static SequentialGoalStructure<TBeliefSet> Seq<TBeliefSet>(params IGoalSt

#region Tactic combinators

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public static AnyOfTactic<TBeliefSet> AnyOf<TBeliefSet>
/// <inheritdoc cref="RandomTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public static RandomTactic<TBeliefSet> Random<TBeliefSet>
(IMetadata metadata, System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subTactics)
where TBeliefSet : IBeliefSet =>
new(metadata, guard, subTactics);

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public static AnyOfTactic<TBeliefSet> AnyOf<TBeliefSet>
/// <inheritdoc cref="RandomTactic{TBeliefSet}(System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public static RandomTactic<TBeliefSet> Random<TBeliefSet>
(System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subTactics)
where TBeliefSet : IBeliefSet =>
new(guard, subTactics);

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(IMetadata,ITactic{TBeliefSet}[])" />
public static AnyOfTactic<TBeliefSet> AnyOf<TBeliefSet>
/// <inheritdoc cref="RandomTactic{TBeliefSet}(IMetadata,ITactic{TBeliefSet}[])" />
public static RandomTactic<TBeliefSet> Random<TBeliefSet>
(IMetadata metadata, params ITactic<TBeliefSet>[] subTactics)
where TBeliefSet : IBeliefSet =>
new(metadata, subTactics);

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(ITactic{TBeliefSet}[])" />
public static AnyOfTactic<TBeliefSet> AnyOf<TBeliefSet>(params ITactic<TBeliefSet>[] subTactics)
/// <inheritdoc cref="RandomTactic{TBeliefSet}(ITactic{TBeliefSet}[])" />
public static RandomTactic<TBeliefSet> Random<TBeliefSet>(params ITactic<TBeliefSet>[] subTactics)
where TBeliefSet : IBeliefSet =>
new(subTactics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace Aplib.Core.Intent.Tactics
{
/// <summary>
/// Represents a tactic that executes any of the provided subtactics.
/// Represents a tactic that executes a random tactic from the provided subtactics.
/// </summary>
public class AnyOfTactic<TBeliefSet> : Tactic<TBeliefSet>
public class RandomTactic<TBeliefSet> : Tactic<TBeliefSet>
where TBeliefSet : IBeliefSet
{
/// <summary>
Expand All @@ -18,37 +18,37 @@ public class AnyOfTactic<TBeliefSet> : Tactic<TBeliefSet>
protected internal readonly LinkedList<ITactic<TBeliefSet>> _subtactics;

/// <summary>
/// Initializes a new instance of the <see cref="AnyOfTactic{TBeliefSet}"/> class with the specified subtactics
/// Initializes a new instance of the <see cref="RandomTactic{TBeliefSet}"/> class with the specified subtactics
/// and an optional guard condition.
/// </summary>
/// <param name="metadata">
/// Metadata about this tactic, used to quickly display the tactic in several contexts.
/// </param>
/// <param name="guard">The guard condition.</param>
/// <param name="subtactics">The list of subtactics.</param>
public AnyOfTactic
public RandomTactic
(
IMetadata metadata,
System.Predicate<TBeliefSet> guard,
params ITactic<TBeliefSet>[] subtactics
)
: base(metadata, guard) => _subtactics = new LinkedList<ITactic<TBeliefSet>>(subtactics);

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])"/>
public AnyOfTactic
/// <inheritdoc cref="RandomTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])"/>
public RandomTactic
(System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subtactics)
: this(new Metadata(), guard, subtactics)
{
}

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public AnyOfTactic(IMetadata metadata, params ITactic<TBeliefSet>[] subtactics)
/// <inheritdoc cref="RandomTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public RandomTactic(IMetadata metadata, params ITactic<TBeliefSet>[] subtactics)
: this(metadata, _ => true, subtactics)
{
}

/// <inheritdoc cref="AnyOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public AnyOfTactic(params ITactic<TBeliefSet>[] subtactics)
/// <inheritdoc cref="RandomTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])" />
public RandomTactic(params ITactic<TBeliefSet>[] subtactics)
: this(new Metadata(), _ => true, subtactics)
{
}
Expand Down

0 comments on commit 6ab1728

Please sign in to comment.