Jump to content

AI system improvement ideas


rjs23
 Share

Recommended Posts

As I'm working on my AI bot and trying to keep it efficient in term of performance, there are some improvements that would benefit 0ad AI system greatly, especially in performance:

1. Currently, the AI bots has to loop through all entity objects to keep updating itself about its changes every turns. Once you store entity object to the variable, its properties doesn't always remain up-to-date. To update its properties, you have to keep updating the entity variable each loop. What if I want to update only one entity without looping through the objects? It would be very unefficient to go through loops just to find one or two entity to update its properties. This hurts performance, especially when it has to update itself everytime for each turns. It is fast, but wastes performance unnecessarily.

My proposed solution: add a native function that accepts entity's ID as the argument and returns it's entity object properties directly from game Engine.

2. Please, add a function or class that directly informs the AI bots that a new unit/object has just generated from game engine. Same thing when a unit or object becomes deleted from the map. This will also help with performance area and reduce the need of managing of each entity status through loop. I've seen some AI bots going through loops every turns just to find out if there is an new entity or not. By having game engine directly informing AI that new/removed objects has occured and return its entity can eliminate the need to loop through entity. See post #2

3. I don't see how to program AI bot to train technologies. Is it too early for that?

Edit: might have some more later

Edited by rjs23
Link to comment
Share on other sites

Point 2 is actually already in there. Check qBot, it has code for "events".

Ah, I see. Thats good enough!

I have one more:

3. Let AI assign an "onChange" function callback to engine that calls this function every time its target ID is changed or its orders are updated. Each time its properties are updated, the engine would call that function callback letting AI know its orders or target ID are changed.

Link to comment
Share on other sites

@ wratii: I'm so glad u pointed out for those events! I've reworked part of my scripts to take advantage of that and it made my bot lag less.

@ hirovard: There is a pop cap. It's at 300 at the moment. As for crashes, if it crashes then you've already lost to AI. The AI are clever enough to keep spamming them until to the point where game ends. You must defeat the AI before it crashes 0AD. :lol2:

Link to comment
Share on other sites

I noticed there is research command in helpers/command.js. Is it safe to use that to force AI to research? I already use rally-setpoint from it and it works but am not sure if it's ready for to use case "research": yet? I'll add it to play around with it but it seems this would let AI research any technology without restriction.

Link to comment
Share on other sites

And you'd have little way to know which techs you have researched.

I would have to track it. Like, when I start researching something. I would append it to array called TechnologyBeingResearched. Not reliable because what if building that was researching it was destroyed and didn't finish researching it? AI would still think it sucessfully researched that. But for now, I think that would good enough.

Link to comment
Share on other sites

  • 2 weeks later...

New idea:

Let AI be able to use team/ally chat and be able to retrieve chat inputs from player.

For example, AI with teams (players) could interact and come up with a plan together.

AI may output a team chat to its ally:

"What plan you want me to do: (chat number option)"

"1. Rush"

"2. Boom"

"3. [Let ai decide, uses ai's prefered methods]"

The player would input a number (Enter, type #, then enter again to send chat) to choose the plans and AI would act according to the player's decision.

By having this feature, AI could interact with human players and form a smarter gameplay environment.

Edit: maybe combine it with UI?

Edited by rjs23
Link to comment
Share on other sites

New idea:

Let AI be able to use team/ally chat and be able to retrieve chat inputs from player.

Yes, I think AIs should be able to receive chat messages, they can already send them. It could be useful for instructing the AI, even if it's something simple like AoK's "31 (attack an enemy now)" command, though I'm sure our AI devs could improve upon that ;)

Link to comment
Share on other sites

1. Currently, the AI bots has to loop through all entity objects to keep updating itself about its changes every turns. Once you store entity object to the variable, its properties doesn't always remain up-to-date. To update its properties, you have to keep updating the entity variable each loop. What if I want to update only one entity without looping through the objects? It would be very unefficient to go through loops just to find one or two entity to update its properties. This hurts performance, especially when it has to update itself everytime for each turns. It is fast, but wastes performance unnecessarily.

My proposed solution: add a native function that accepts entity's ID as the argument and returns it's entity object properties directly from game Engine.

Sorry for the late reply. I'm slightly confused by this. You can already grab an entity by id easily, with qBot's I just call GameState.getEntityById(id). The system was deliberately designed to be able to desync the AI from the rest of the simulation, this will allow AI's oyu run in their own threads without needing to lock the rest of the game. For this it is essential to create a copy of the required state. Keeping the copy up to date doesn't take much cpu time you can easily see in the profiler (F11).

Link to comment
Share on other sites

Sorry for the late reply. I'm slightly confused by this. You can already grab an entity by id easily, with qBot's I just call GameState.getEntityById(id). The system was deliberately designed to be able to desync the AI from the rest of the simulation, this will allow AI's oyu run in their own threads without needing to lock the rest of the game. For this it is essential to create a copy of the required state. Keeping the copy up to date doesn't take much cpu time you can easily see in the profiler (F11).

Np about late reply, as least you replied. It brings clarity ;).

I did not know about it. Clearly, I didn't study your AI script enough. Shame on me. I studied mostly on juBot's (to study its performance issues, and learn its flaws to try prevent my bot suffer same fate as juBot have.)

I already created an function called getEntityByID in my bot script that achieves the purpose of returning updated entity object from ID, will try to remake it to use GameState.getEntityById() instead. Thanks for mentioning it. Should make it better in performance.

Does SVN already let AI run in its own thread or does it still share with the UI's thread? it still seem to lock up the game little bit if I call something too many times like computing distance between entities which suggests that each AI does not lie in its own thread yet. Having Infinity loop like while(true) in AI script locks up the UI.

I just prefer having updated copies of specific entities every turn, instead of entire entities of the match. I dislike having to update every single entity like trees or fishes for every single turn because it seems ineffective to me to re-update entity when they haven't change any properties. In my bot, I try to skip some entities that isn't needed for next few turns by containing an array of important entities ID and use getEntityByID (or will be GameState.getEntityById()) to get its updated entity properties. That way, it would try to free up MHZ as much as possible for smoother gameplay.

Link to comment
Share on other sites

The AI doesn't currently run in its own thread. The main reason currently is that it would break the profiler. Plus it gives some incentive to keep the AI's nice and efficient for now.

The only updates sent are changes, so most of the trees will have no update sent unless a unit has recently been gathering from it. This is simpler because otherwise you have to keep track of what updates have been applied etc. It would probably be slower than the current system.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...