using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpriteCompiler.AI
{
public class IterativeDeepeningSearch : ISearch
where T : ISearchNode
where C : ICost, new()
{
private readonly ISearchStrategy search;
private readonly int limit;
public IterativeDeepeningSearch(ISearchStrategy search, int limit)
{
this.search = search;
this.limit = limit;
}
public IEnumerable Search(ISearchProblem problem, S initialState)
{
for (int depth = 1; depth <= limit; depth++)
{
var dls = new DepthLimitedSearch(search, new DepthNodeLimiter(depth));
var result = dls.Search(problem, initialState);
if (!dls.IsCutoff(result))
{
return result;
}
}
return Enumerable.Empty();
}
}
}