Archived

This topic is now archived and is closed to further replies.

Interaction world-agent

This topic is 5016 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

Hi! I''m new here at the forums, so... Hi! Well... I''m developing a strategy game where you tell your troops what to do and they decide how to do it. The game is being made in Java, as I intend to make a not too complex interface for the game n HTML and use servlets so that anyone with a browser can play the game. But i digress. My question is actually about ellegant coding and design: What I don''t know is how should the agents interact with the world. First I thought about placing a pointer to the world as one of the agent''s attributes. Then the agent would call the proper world methods to do whatever it wants to do. However, with this approach not only I will have hundreds of pointers to the same thing but each agent will have more information than it needs (Of course it would only be able to call a few methods, not all of them but its not easy to make public just the right ones). My other idea was to let the world coordinate the actions (of course the world has a pointer to the agents, in the right cell), so that the agent would act in response to a world call (Its a really hard restriction, the actions would be encoded in the return value of a method). However this approach makes agent-agent interaction really complicated, cause they would have the world between them coordinating the "talk". What is the best/most used strategy? Is there a third one that is even better? Thanks! Cesar

Share this post


Link to post
Share on other sites
Well, I think the idea of having the agent have a ptr to the world seems fine to me. For starters, you seem to mainly concerned about memory. So you have to ask, how many agents will there be loaded at one time? Unless it is like 10 million, i dont see how those extra ptr''s will really consume all the much ram, this of coz assumes you target computer isnt something with like 16MB ram

As for your other concern, the agent having to much information, you dont have to give the agent a ptr to the "real" world, but the world could implement an interface that is minimal subset of functionality the agent needs, and then that agent can have a ptr to that interface (which is in turn implemented by the world).

You alternative idea, with the world calling a func in the agent is not too bad (this would be some kind of quantum based system) but the idea of using the return value the way you suggests strikes me as a very bad design decision. Also I dont see how that would limit agent to agent interaction.



An advantage to your first idea is that it would technically support "multiple" worlds, if you ever needed that.

Ultimately though it comes down to a trade off of memory vs speed in many ways.

And then finally, you overlooked one simple solution, if you know your game will only have one world, then why not make the world a singleton, and then no agent needs a ptr to that world at all. Even if you had multiple worlds you could make some global func like GetWorld(x), although I do not code in java so I don''t know if global funcs/variables are allowed.

BTW: I know the global func idea might be "bad design" but in this case, if the memory overhead is so bad, it is the only alternative i see.

Jeff

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why not make the world an agent, you could use a fixed index in the agent-array to access it, eg 0
i think its also done in q3, but i''m not sure (ok there it''s an ''entity'', but i think this is just a naming problem)
in my opinion this a quite elegant solution, because now you have a system relying only on agents and you dont have the ptr. problem, but still there''s the global var problem, because you would need a ptr to the agent-array, but it could be passed as an argument, so there is just one ptr for this array.

Share this post


Link to post
Share on other sites
Yes, I thought about the idea of the world being an agent. In fact, the 2 approach, of the world coordinating everything, is almost that. And its a good thing to have the world policing agent actions because there will be several different agents and I want to make their creation easy. So if i can prevent an agent coding error to bug the world, its good. And easier to implement with the world being the active agent, the others being reactive.

I really like the idea of giving each agent a vision of the world. With the agent approach, every turn, the world gives the agent its vision of the world, which is no different then having the agent asking the world for its vision. But when I think about the concepts involved, I like better the idea of the agent being active and not the world.




Share this post


Link to post
Share on other sites
Guest Anonymous Poster
for startes i''m the same ap
i would also use the active agents, and i think it''s not harder to implement, you just have to loop throught the whole array and call a function like void think(cWorld* world), where the world just returns from this function.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
me again
i thougt about it, and i came up with a slightly different version: use void think(void) and a function called cAgent* getAgentByName(string name), this way you don''t have to treat any agent specially, all agents seem basicly the same, and based on your implementation of these function there is no really big performance hit

Share this post


Link to post
Share on other sites
I''m not sure I understand what you mean. If I call a function void think(void) from inside the agent, this means it will have a world pointer inside it, from which it will get sensory information. What would the getAgentByName method do? Where would it be? Its sounds interesting!

Share this post


Link to post
Share on other sites
I am not sure if you realize how small a pointer is. If each agent has a pointer to the world, that is still going to be an insignificant amount of meomory. In pretty much all games, you really only have to worry about how much memory the graphics are taking up; data is virtually free.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i don''t know exactly how it works in java but in c++ i would write:

class iAgent{
public:
virtual void think(void) = 0; // so this is an abstract class


// interface functions for the agent array

static void addAgent(iAgent*);

void remove(void); // removes the current agent


protected:
iAgent* getAgentByName(string& name);

private:
stl::vector<iAgent*> m_AgentArray;
};


// now the think implementation of an example agent:

void cExampleAgent::think()
{
cWorld* world = dynamic_cast<cWorld*>(iAgent::getAgentByName("world"));
if(world)
{
// do some stuff with the world

}
}


@Unsuspected i consider it more as a design issue than as a memory problem, because:
1) the world pointer could change
2) the world is no agent, but i would try to create a system only based on agents
3) if you would pass the world pointer as an parameter, you would treat some agents specially, but now you have to ask, wich agent should be special, wich not

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
some slight changes to the code above, both getAgentByName and m_AgentArray have to be static

Share this post


Link to post
Share on other sites
Like AP said, its more of a design issue.

Now I understood.

I will think more about this, the name idea is good.

Now I have some other doubts...
All the agent actions are send to the world for validation (so that the agent does not cheat, I know I''m doing all the coding, but its a matter of consistency). I have to find a way to do that. Sending the actions in a package is the easiest way to make sure it doesn''t cheat. But again I don''t like the idea very much and would rather have the agent calling different methods to do different actions. But this makes action checking harder (it could call 2 different methods and the world you have to know it already called an action method to reject the second request, which is more complicated). But I will figure this one out too.

Thanks for the answers!

Share this post


Link to post
Share on other sites