In the previous episode, we laid down the concepts and “lexical” language about autonomous agents. We can start to design interfaces for each concept identified previously. Here’s a concept summary to get started:
On top of those concepts, remember that we are going to work with the System.Components model-container-services interfaces: IComponent, IContainer.
public interface IAgent : IComponent, IVisualizable{ IBody Body { get;} IBehavior Behavior { get;} IVision Vision { get;}}
public interface IBehavior : IArtifact{ PointF ComputeSteering();}
public interface IBody : IArtifact{ float Mass { get;}
PointF Position { get;} float Direction { get;} Referential Anchor { get;}
PointF Velocity { get;} PointF Acceleration { get;}
IPointSaturator VelocitySaturator { get; set;} IPointSaturator AccelerationSaturator { get; set;}
void Update( PointF acceleration, PointF velocity, PointF position);}
There are some comments to do about this interface. 1. IPointSaturator is the interface defining PointF saturator. In fact, it is very important to make sure that the agents have a maximum speed! 2. Referential is the local referential attached to the agent. 3. There is one major lack in this interface, the inertia, the rotation velocity and acceleration. For the sake of simplicity, I decided to leave those aside for now.
public interface IVision : IArtifact{ float MaxRange { get;} bool CanSee(IAgent agent);}
public interface IIntegrator{ void Integrate(IBody body, PointF steering);}
It also provides a way to determine the maximum vector norm (norm-2) depending on the “attack” angle.
public interface IScalarSaturator{ float Saturate(IBody body, float value);} public interface IPointSaturator{ PointF Saturate(IBody body, PointF vector); float GetMaxNormFromAngle(float value);}
public interface IScene : IComponent{ void Prepare(); void Flush();
void DrawLine(Pen pen, PointF start, PointF end); ...
void PushTranslateTransform(float dx, float dy); ... void PopTransform();}
public interface IVisualizable{ bool Visible { get;set;} void Render(IScene scene);}
public interface ISprite : IVisualizable, IDisposable{ string Name { get;} Font Font { get;set;} Color BackgroundColor { get;set;} Color StrokeColor { get;set;} float StrokeWidth { get;set;}}
I’ve added the name for debugging reasons.
public interface IArtifact : ISprite, IOwned<IAgent>{}public interface IOwned<T>{ event EventHandler OwnerChanged; T Owner { get;set;}}
public interface IWorld{ Size WorldSize { get;} Size ScreenSize { get;} PointF ScreenToWorld(PointF point); PointF WorldToScreen(PointF point); PointF ToWorldRatio{get;} PointF ToScreenRatio {get;}}
I’ll skip the service concepts for now. They basically provide access to the different instances of neighborhood, obstacle manager, agent list, etc... For now, it’s to time have a break and a well-deserved cool beer.
Page rendered at Thursday, December 04, 2008 7:02:36 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.