-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: make FirstOfTactic derive Tactic * feat: make subtactics protected internal * refactor: rename forgotten subTactics to subtactics
- Loading branch information
1 parent
87c0b53
commit cfff980
Showing
3 changed files
with
61 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public class FirstOfTactic<TBeliefSet> : AnyOfTactic<TBeliefSet> | ||
public class FirstOfTactic<TBeliefSet> : Tactic<TBeliefSet> | ||
where TBeliefSet : IBeliefSet | ||
{ | ||
/// <summary> | ||
/// Gets or sets the subtactics of the tactic. | ||
/// </summary> | ||
protected internal readonly LinkedList<ITactic<TBeliefSet>> _subtactics; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FirstOfTactic{TBeliefSet}"/> class with the specified | ||
/// sub-tactics and guard condition. | ||
/// subtactics and 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> | ||
/// <param name="subtactics">The list of subtactics.</param> | ||
public FirstOfTactic | ||
(IMetadata metadata, System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subTactics) | ||
: base(metadata, guard, subTactics) | ||
{ | ||
} | ||
( | ||
IMetadata metadata, | ||
System.Predicate<TBeliefSet> guard, | ||
params ITactic<TBeliefSet>[] subtactics | ||
) | ||
: base(metadata, guard) => _subtactics = new LinkedList<ITactic<TBeliefSet>>(subtactics); | ||
|
||
/// <inheritdoc cref="FirstOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])"/> | ||
public FirstOfTactic(IMetadata metadata, params ITactic<TBeliefSet>[] subTactics) | ||
: this(metadata, _ => true, subTactics) | ||
public FirstOfTactic(IMetadata metadata, params ITactic<TBeliefSet>[] subtactics) | ||
: this(metadata, _ => true, subtactics) | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="FirstOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])"/> | ||
public FirstOfTactic | ||
(System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subTactics) | ||
: this(new Metadata(), guard, subTactics) | ||
(System.Predicate<TBeliefSet> guard, params ITactic<TBeliefSet>[] subtactics) | ||
: this(new Metadata(), guard, subtactics) | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="FirstOfTactic{TBeliefSet}(IMetadata,System.Predicate{TBeliefSet},ITactic{TBeliefSet}[])"/> | ||
public FirstOfTactic(params ITactic<TBeliefSet>[] subTactics) : this(new Metadata(), _ => true, subTactics) { } | ||
public FirstOfTactic(params ITactic<TBeliefSet>[] subtactics) : this(new Metadata(), _ => true, subtactics) { } | ||
|
||
/// <inheritdoc /> | ||
public override IAction<TBeliefSet>? GetAction(TBeliefSet beliefSet) | ||
{ | ||
if (!IsActionable(beliefSet)) return null; | ||
|
||
return _subTactics | ||
return _subtactics | ||
.Select(subTactic => subTactic.GetAction(beliefSet)) | ||
.OfType<IAction<TBeliefSet>>() | ||
.FirstOrDefault(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<ILoggable> GetLogChildren() => _subtactics.OfType<ILoggable>(); | ||
} | ||
} |