2016-11-25 06:05:29 +00:00
|
|
|
|
namespace SpriteCompiler.AI
|
|
|
|
|
{
|
2016-11-27 05:39:50 +00:00
|
|
|
|
using Adapters;
|
2016-11-25 06:05:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public class BestFirstSearch<A, S, T, C> : ISearch<A, S, T, C>
|
|
|
|
|
where T : ISearchNode<A, S, T, C>
|
|
|
|
|
where C : IPathCost<C>
|
|
|
|
|
{
|
|
|
|
|
protected readonly AbstractAISearch<A, S, T, C> search;
|
|
|
|
|
protected readonly IQueue<T> fringe;
|
|
|
|
|
|
|
|
|
|
public BestFirstSearch(AbstractAISearch<A, S, T, C> search, IQueue<T> fringe)
|
|
|
|
|
{
|
|
|
|
|
this.search = search;
|
|
|
|
|
this.fringe = fringe;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 05:39:50 +00:00
|
|
|
|
public BestFirstSearch(AbstractAISearch<A, S, T, C> search)
|
2016-11-25 06:05:29 +00:00
|
|
|
|
{
|
|
|
|
|
this.search = search;
|
2016-11-27 05:39:50 +00:00
|
|
|
|
this.fringe = new QueueAdapter<T, C>();
|
2016-11-25 06:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<T> Search(ISearchProblem<A, S, C> problem, S initialState)
|
|
|
|
|
{
|
|
|
|
|
fringe.Clear();
|
|
|
|
|
return search.Search(problem, fringe, initialState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<T> ExtendSearch(ISearchProblem<A, S, C> problem)
|
|
|
|
|
{
|
|
|
|
|
return search.ExtendSearch(problem, fringe);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|