mirror of
https://github.com/lscharen/iigs-sprite-compiler.git
synced 2024-11-15 10:05:14 +00:00
29 lines
870 B
C#
29 lines
870 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace SpriteCompiler.AI
|
|
{
|
|
public abstract class InformedNodeExpander<A, S, T, C> : INodeExpander<A, S, T, C>
|
|
where T : HeuristicSearchNode<A, S, T, C>
|
|
where C : IPathCost<C>
|
|
{
|
|
public abstract T CreateNode(T parent, S state);
|
|
|
|
public IEnumerable<T> Expand(ISearchProblem<A, S, C> problem, T node)
|
|
{
|
|
foreach (var successor in problem.Successors(node.State))
|
|
{
|
|
var action = successor.Key;
|
|
var state = successor.Value;
|
|
var next = CreateNode(node, state);
|
|
|
|
next.Action = action;
|
|
next.StepCost = problem.StepCost(node.State, action, state);
|
|
next.Heuristic = problem.Heuristic(state);
|
|
|
|
yield return next;
|
|
}
|
|
}
|
|
}
|
|
}
|