using System;
using System.Collections.Generic;
namespace SpriteCompiler.AI
{
public class GraphSearch : AbstractAISearch
where T : ISearchNode
where C : IPathCost
{
private readonly ISet closed = new HashSet();
public GraphSearch(INodeExpander expander)
: base(expander)
{
}
///
/// Generic graph search. See page 83 in Russell and Norvig. This only works in informed
/// search if the heuristic is admissible.However, if a heuristic is not admissible and
/// you still want to use, that means you should know enough to extend this class or write
/// your own Search class.
///
public override IEnumerable Search(ISearchProblem problem, IQueue fringe, S initialState)
{
closed.Clear();
return base.Search(problem, fringe, initialState);
}
protected override void AddNodes(IQueue fringe, T node, ISearchProblem problem)
{
if (!closed.Contains(node.State))
{
closed.Add(node.State);
fringe.AddRange(Expand(problem, node));
}
}
}
}