This might be kind of a trivial question, but I am having trouble understanding this. Would very much appreciate your help.
In game development using object oriented design, I want to understand how AI-agents access the information they need from the game world in order to perform their actions.
As we all know, in games very often AI agents need to 'perceive their environment' and act according to what is happening around them. For example, an agent might be programmed to chase the player if he/she gets close enough, avoid obstacles while moving (using the Obstacle Avoidance steering behavior), etc.
My problem is I'm not sure how to do that. How can an AI agent access the information it needs about the game world?
One possible approach is that the agents simply request the information they need directly from the game world.
There's a class called GameWorld. It handles important game logic (game loop, collision detection, etc), and also holds references to all of the entities in the game.
I could make this class a Singleton. When an agent needs information from the game world, it simply gets it directly from the GameWorld instance.
For example, an agent might be programmed to
Seek the player when he/she is close. In order to do this the agent has to get the player's position. So it can simply request it directly:
An agent could also just get the list of all the entities in the game, and analyze it for it's needs (to figure out what entities are close by , or anything else):
This is the simplest approach: agents contact the GameWorld class directly and get the information they need. However, this is the only approach I know. is there a better one?
How would an experienced game developer design this? Is the "get a list of all the entities and look for whatever you need" approach naive? What approaches and mechanisms are there to allow AI agents to access the information they need in order to perform their actions?