iigs-sprite-compiler/SpriteCompiler/AI/CostNodeLimiter.cs
Lucas Scharenbroich 69599c5643 Additional tests
2016-12-18 00:03:23 -06:00

40 lines
1.2 KiB
C#

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>
where C : ICost<C>, new()
{
private readonly C maxCost;
private C nextCost;
public CostNodeLimiter(C maxCost, C infinity)
{
this.maxCost = maxCost;
this.nextCost = infinity;
}
public C NextCost { get { return nextCost; } }
public bool Cutoff(T node)
{
// 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.
// Current bug -- three line sprite, never exceeds cost of 23
if (node.PathCost.CompareTo(maxCost) > 0)
{
nextCost = (node.PathCost.CompareTo(nextCost) < 0) ? node.PathCost : nextCost;
return true;
}
return false;
}
}
}