I have a requirement to implement a type of AI for a project, the issue is that I am having trouble visualizing how the AI should actually be implemented.
Essentially, I want the AI to be as dynamic as possible. That is, if I decide in the future to add another type of AI Action (as we'll call it), I don't need to rewrite the class using the AI or AI Action.
What I have now, is a very rough idea, but it should help clarify.
public interface IAiAction
{
List<IAiProperty> Properties { get; }
DateTime LastUpdate { get; }
bool Update(Entity e);
}
public interface IAiProperty
{
}
Then I have something like:
public class WanderAction : IAiAction
{
private List<IAiProperty> _Properties = new List<IAiProperty>();
public List<IAiProperty> Properties { get { return _Properties; } }
private DateTime _LastUpdate;
public DateTime LastUpdate { get { return _LastUpdate; } }
private Point _WanderTo;
public bool Update(Entity e)
{
// Do stuff here
return true;
}
}
public struct WanderDistance : IAiProperty
{
private Point _Home;
private float _MaxDistance;
public Point Home { get { return _Home; } private set { _Home = value; } }
public float MaxDistance { get { return _MaxDistance; } private set { _MaxDistance = value; } }
public WanderDistance(Point h, float m)
{
_Home = h;
_MaxDistance = m;
}
}
Then, in the class with the actions:
private List<IAiAction> _AiActions = new List<IAiAction>();
public List<IAiAction> AiActions { get { return _AiActions; } }
public override void Update(Vector2F force)
{
foreach (IAiAction action in AiActions)
action.Update(this);
base.Update(force);
}
The problem is that this does not extend well. I'm not even sure how I got to this stage, as I've never had to do something like this before.
This code is by no means a requirement. If anyone has any other ideas for how it can be done (even if they are far separate from what this indicates) I am up for it.
For example, if I had an IAiAction
that was to determine what the Entity
was going to say randomly, this leaves very poor room to do that. I also, for the WanderAction
as an example, need to return a Vector2F
to the calling class, to add it to the force
parameter of the Update(Vector2F)
method.
If any clarification beyond this is necessary, please let me know. This isn't holding up the project, but it is causing me issue.
The only other method I can think of is to implement a sort of state that is carried through the programme. This would technically satisfy my requirements, but I'm curious if there is a better way.