To whom has the AI to signal back stuff? Who is interested in the fact that the AI knows that a ship is in range / a planet in reach ? Does the human player tell it to someone too?
Just update all AIs each update() you do.
The AI does something or not (it just updates their current task to do whatever the tasks need to do).
The AI has the information which player it controls (eg "playerID:int").
When it wants to know what planets it has access to:
API: GetPlayerPlanets(AI.playerID)
or direct: space.GetPlanets(AI.playerID)
... use the way to make sure that a player (human or CPU) cannot fetch information they are not allowed to retrieve. Eg. all know who is the owner of a planet so this information is publically available (planet.GetOwnerID()). Other stuff needs to be secured.
planet.SendShips(targetID) would be uncool to be publically available as with GetPlayerPlanets(enemyPlayerID)[0].SendShips(otherEnemyPlayerID) you could send out stuff.
That is where the API approach helps - every "API" gets a playerID assigned. The instance of the API is directly linked to a single player. That way "player.commands(or API).SendShipsFromPlanet(planetID, targetID)" is able to verify that the planetID belongs to the playerID stored in the API/command instance.
You can keep it simple if the AI is never done in an external/moddable file. So if the AI is stored in your own source code you can already make sure that it does only valid things. Then keep it simple and use "if planet.ownerID = playerID then planet.SendShips(targetID)".
@ finished task
If the AI finished its task it moves on with the next task. No need to inform anybody? Why should it? As said at the top of my post: does the human player inform others too once he finished checking all planet's ship production states?
The AI is like the human player: you split up all the possibilities you have into little tasks:
- check diplomacy
- check planet productions
- do military operations
- ...
Do nothing in parallel as the human could not do that too. Task by Task - and if you do it serious you even limit the AI a bit to be not too fast (adjust according to difficulty).
With this time limit in mind you might understand why the tasks need priorities - you cannot execute all tasks in each AI cycle. You only have some ticks available (also to avoid lags - as some tasks are pretty time consuming). Means some tasks might even have to be split into multiple "cycles".
Imagine there are 1000 planets. Checking all of them each time means to check 1000 planets in milliseconds. Humans could not do that. Introduce "steps". Each AI cycle (or simple: during each ai.Update()) you increase the step. That way you know the progress of this task and could eg. scan the first 100, the second 100, ... planets. Like a human could do. One by one.
This cuts down AI processing time - i can tell you that a more complex AI (with more complex checks of properties, stored information about stuff happened in the past -> for proper estimations of what might happen next) can take some cpu cycles. So split up stuff.
Next to cutting down processing time this "step by step" and "priority" approach allows to "disturb" a task. Assume the human player is just checking some planets as the "under attack" sound is played and the screen turns red: of course he now reacts to this.
Doing a "step by step" thing means that you did not check every planet now (as the human was not able too). Yet the recalculation of priorities allows to now run the "UnderAttack" task for a quick reaction. Once this task is no longer of high priority (as the second-strike was executed and we are no longer under attack) the other tasks will be automatically executed then.
Goal of this to have a more "human like" reacting AI.
-----
In this case the AI has finished it's task and we modify the parent (given the key), by whatever we need to do.
It seems you think of the AI as a "decision maker". You ask the AI what it would do, fetch the information and then actually execute what the AI planned to do?
My approach is more of a "controller":
- human uses input device + GUI/HUD to execute commands (planet.SendShip())
- AI uses its own commands to do stuff (planet.SendShip())
In my idea the AI directly does its stuff, no further interaction or "return values" needed.
That way you could also easily replace the AI with a remote (network/internet) player as it just uses another layer (transport their "input device + GUI/HUD" via networking packages to you - and run the same commands then according to the incoming data).
Maybe at the end we talk about the same but as said I think you decouple the AI from the actual player object. More like a brain which you ask for decisions/help/what-to-do. While my idea is to give the player object an AI brain and let the player then do its stuff without my help.
bye
Ron