• Advertisement
Sign in to follow this  

Design - Agent needs to see 'world'

This topic is 4041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been playing with some emergent behaviour things recently, and I thought I'd try to get a little flocking simulation up and running. Thinking it through, I'm not sure how to design it. Each agent needs to know where the rest of the agents are (well, possibly with a little culling to remove agents which are so distant that they don't matter, so that that computation doesn't become too intensive with larger numbers of agents), in order to follow/avoid them or whatever. It occurs to me that having something like (very OTOH):
class Agent
{
    // ...
    void updatePosition(std::vector Agents);
    // ...
}
is a bit ugly. Is this an appropriate time to use the Model/View/Controller pattern I've come across occasionally?

Share this post


Link to post
Share on other sites
Advertisement
I take it that the parameter to:

void updatePosition(std::vector Agents);

is the culled list of agents in the vicinity of the agent being updated?

I think this is slightly backwards in that only the agent itself knows what subset of all agents it's interested in. In which case I'd be tempted to do:

class Agent
{
void Update (void)
{
// get agents in my vicinity...
vector <Agent *>
neighbours = m_world->FindAgents (this, centre, search_radius, search_predicate);
// where:
// m_world is a link to the world containing the agent
// search radius and centre define a world sphere
// search_predicate is a predicate class applied to each item in the sphere
// (so you could get those items infront of the agent say)
}
};

By letting the agent specify which neighbours it's interested in, you increase the flexibility of the searches and remove any unnecessary searches.

Skizz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement