2016-11-25 06:05:29 +00:00
|
|
|
|
namespace SpriteCompiler.AI
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public abstract class AbstractSearchNode<A, S, T, C> : ISearchNode<A, S, T, C>
|
|
|
|
|
where T : ISearchNode<A, S, T, C>
|
2016-12-12 06:41:35 +00:00
|
|
|
|
where C : ICost<C>, new()
|
2016-11-25 06:05:29 +00:00
|
|
|
|
{
|
|
|
|
|
protected readonly S state;
|
|
|
|
|
protected readonly T parent;
|
|
|
|
|
protected A action = default(A);
|
|
|
|
|
|
2016-11-29 06:20:29 +00:00
|
|
|
|
protected C pathCost = new C();
|
|
|
|
|
protected C stepCost = new C();
|
2016-11-25 06:05:29 +00:00
|
|
|
|
protected readonly int depth;
|
|
|
|
|
|
|
|
|
|
public AbstractSearchNode(T node, S state)
|
|
|
|
|
{
|
|
|
|
|
this.state = state;
|
|
|
|
|
this.parent = node;
|
|
|
|
|
this.depth = HasParent ? parent.Depth + 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool HasParent { get { return !EqualityComparer<T>.Default.Equals(parent, default(T)); } }
|
|
|
|
|
|
|
|
|
|
public A Action { get { return action; } set { action = value; } }
|
|
|
|
|
public T Parent { get { return parent; } }
|
|
|
|
|
public C PathCost { get { return pathCost; } }
|
|
|
|
|
public int Depth { get { return depth; } }
|
|
|
|
|
public S State { get { return state; } }
|
|
|
|
|
|
2016-12-12 06:41:35 +00:00
|
|
|
|
public C EstCost { get { return PathCost; } }
|
|
|
|
|
|
2016-11-25 06:05:29 +00:00
|
|
|
|
public C StepCost
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return stepCost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
stepCost = value;
|
|
|
|
|
pathCost = HasParent ? parent.PathCost.Add(value) : value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|