2016-12-09 03:59:21 +00:00
|
|
|
|
namespace SpriteCompiler.AI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class that taken a search node and detemines whether or not to terminate the
|
|
|
|
|
/// search at the node. This is different than a goal test and is used in the
|
|
|
|
|
/// contect of depth-limited searches.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CostNodeLimiter<T, C> : INodeLimiter<T, C>
|
|
|
|
|
where T : ISearchNode<C>
|
2016-12-12 06:41:35 +00:00
|
|
|
|
where C : ICost<C>, new()
|
2016-12-09 03:59:21 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly C maxCost;
|
2016-12-12 06:41:35 +00:00
|
|
|
|
private C nextCost;
|
2016-12-09 03:59:21 +00:00
|
|
|
|
|
2016-12-12 06:41:35 +00:00
|
|
|
|
public CostNodeLimiter(C maxCost, C infinity)
|
2016-12-09 03:59:21 +00:00
|
|
|
|
{
|
|
|
|
|
this.maxCost = maxCost;
|
2016-12-12 06:41:35 +00:00
|
|
|
|
this.nextCost = infinity;
|
2016-12-09 03:59:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 06:41:35 +00:00
|
|
|
|
public C NextCost { get { return nextCost; } }
|
|
|
|
|
|
2016-12-09 03:59:21 +00:00
|
|
|
|
public bool Cutoff(T node)
|
|
|
|
|
{
|
2016-12-12 06:41:35 +00:00
|
|
|
|
// If we find a value that exceeds the current maximum, return false,
|
|
|
|
|
// but keep track of the smallest value that is larger than the maximum
|
|
|
|
|
// cost.
|
|
|
|
|
if (node.PathCost.CompareTo(maxCost) > 0)
|
|
|
|
|
{
|
|
|
|
|
nextCost = (node.PathCost.CompareTo(nextCost) < 0) ? node.PathCost : nextCost;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2016-12-09 03:59:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|