Public Group

# Design - Agent needs to see 'world'

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

## 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 on other sites
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 on other sites
That, of course, makes much more sense. Thanks. :-)

1. 1
2. 2
frob
15
3. 3
4. 4
Rutin
12
5. 5

• 13
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632120
• Total Posts
3004220

×