2016-11-27 05:39:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SpriteCompiler.AI
|
|
|
|
|
{
|
|
|
|
|
public class SearchProblem<A, S, C> : ISearchProblem<A, S, C>
|
|
|
|
|
where C : IPathCost<C>
|
|
|
|
|
{
|
|
|
|
|
private readonly IGoalTest<S> goalTest;
|
|
|
|
|
private readonly IStepCostFunction<A, S, C> stepCost;
|
|
|
|
|
private readonly ISuccessorFunction<A, S> successorFn;
|
|
|
|
|
private readonly IHeuristicFunction<S, C> heuristicFn;
|
|
|
|
|
|
|
|
|
|
public SearchProblem(IGoalTest<S> goalTest, IStepCostFunction<A, S, C> stepCost, ISuccessorFunction<A, S> successor, IHeuristicFunction<S, C> heuristicFn)
|
|
|
|
|
{
|
|
|
|
|
this.goalTest = goalTest;
|
|
|
|
|
this.stepCost = stepCost;
|
|
|
|
|
this.successorFn = successor;
|
|
|
|
|
this.heuristicFn = heuristicFn;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 22:13:43 +00:00
|
|
|
|
public IEnumerable<Tuple<A, S>> Successors(S state)
|
2016-11-27 05:39:50 +00:00
|
|
|
|
{
|
|
|
|
|
return successorFn.Successors(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsGoal(S state)
|
|
|
|
|
{
|
|
|
|
|
return goalTest.IsGoal(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public C StepCost(S fromState, A action, S toState)
|
|
|
|
|
{
|
|
|
|
|
return stepCost.StepCost(fromState, action, toState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public C Heuristic(S state)
|
|
|
|
|
{
|
|
|
|
|
return heuristicFn.Eval(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|