using System;
using System.Collections.Generic;
namespace SpriteCompiler.AI
{
using System.Linq;
public abstract class InformedNodeExpander : INodeExpander
where T : HeuristicSearchNode
where C : IPathCost, new()
{
public abstract T CreateNode(T parent, S state);
public IEnumerable Expand(ISearchProblem problem, T node)
{
var successors = problem.Successors(node.State);
// Debug
#if DEBUG
Console.WriteLine(String.Format("There are {0} successors for {1}", successors.Count(), node));
Console.WriteLine(String.Format("This node has a current path cost of {0}", node.PathCost));
#endif
foreach (var successor in successors)
{
var action = successor.Item1;
var state = successor.Item2;
var next = CreateNode(node, state);
next.Action = action;
next.StepCost = problem.StepCost(node.State, action, state);
next.Heuristic = problem.Heuristic(state);
#if DEBUG
Console.WriteLine(" Action = " + next.Action + ", g(n') = " + next.PathCost + ", h(n') = " + next.Heuristic);
#endif
yield return next;
}
}
}
}