Jump to content

Dynamic AI


Recommended Posts

Hey guys, for my thesis (and in the end run to contribute to 0 A.D.) I'm developing an adaptive and dynamic AI for 0 A.D. which will not be based on scripting (since scripting is static) and will be implemented in C++. The interfacing idea, i.e. communication between the AI and the game engine, has these requirements:

The AI will need to have access during gameplay to these structures:

  • The map (along with all units/buildings on it, areas occupied by AI / player)
  • Any game status
  • Player information / status and logs of all the actions he/she performs
  • AI status (all units, buildings, what units are doing, scores, available resources / upgrades, etc

The AI will also need to send (to the game engine) these during gameplay:

  • Actions / commands what the AI decided to do (Ex: actions for certain units / changing the stance for other units / tech or age upgrades, etc

Now the problem I have is that it's been quite difficult to get an idea of which classes and methods in the engine I will need to use to perform this interfacing and communication between the AI and engine. Also, since I will not be implementing any static scripts (unlike qbot for example), the implementation will be very different from the other existing AIs. Thus, I need to implement a direct communication, via C++, between the AI and engine. Any idea on what classes and methods in the engine I will need to use? I've been on this for two weeks and barely got anywhere.

Btw this is my first post...hello to all of you :)

  • Like 1
Link to comment
Share on other sites

Hi and welcome to the forum :)

What you want to do is at least ambitious as well as problematic because it does not fit to the overall design with mods and simulations (both done in js) AFAIK. It's for sure possible though.

I have no overview of the files you'd need but CCmpAIManager.cpp seams like a good point to start as zoot.stated.

For more detailed information you might want to visit the development chat and ask there: http://webchat.quake...hannels=0ad-dev

Good luck with your project and have a nice stay.

Edited by FeXoR
Link to comment
Share on other sites

You need to look in source/simulation/components, for the AIManager (and the corresponding AI interface stuff in both c++ and js).

Basically, what you want to do would require changing the AI Manager substantially. Right now it calls a JS script, and gets info about the simulation from another JS script. You will want to change that script to give you any information you need, and you will want to change the AI manager to work in C++ (that is actually mostly trivial once you have parsed in C++ the javascript simulation state.)

Most of what you described is already possible. However, the code might need a little time to get used too.

Link to comment
Share on other sites

What you want to do is at least ambitious as well as problematic because it does not fit to the overall design with mods and simulations (both done in js) AFAIK.

Simulation components can be done in C++ (the AI manager is itself an example of this), so it shouldn't be completely impossible to extend it to support C++ AIs.

Link to comment
Share on other sites

Simulation components can be done in C++ (the AI manager is itself an example of this), so it shouldn't be completely impossible to extend it to support C++ AIs.

Thx! Good to know. I thought mods where js exclusively and since AIs are part mod/simulation it would not really fit into the design.

Edited by FeXoR
Link to comment
Share on other sites

Mods, in the usual sense, are JS only. But AIs are not necessarily part of a mod.

But you are right that it doesn't really fit the pattern of striving to keep mod-specific stuff out of the engine. agapsguy doesn't necessarily intend to follow that pattern either, though.

Link to comment
Share on other sites

Due to the priority of the solution (since it's a thesis) and the fact that keeping in patterns with the usual approaches to 0 A.D. is not one of my objectives, the most important thing is that the interfacing works according to the needs and requirements of my objectives. Whether it fits to 0 A.D.'s usual patterns is only something that the solution, could have in the future. So with respect to the AI, if it needs to have classes with direct communication to the engine, so be it :P

Link to comment
Share on other sites

Here's a guy that is devoting himself to contribute in the coding side.

I think he needs a better, more decent welcome ;)

Actually no, he's devoting himself to working on his own project using our existing engine and asking for our help ;) However, I'm sure it can be useful in some way regardless of whether it will end up being included in the game or not, and either way, it's always nice to see that the game draws interest, especially this serious interest, so I'll most definitely add my welcome and well-wishes to the already existing ones :)
  • Like 1
Link to comment
Share on other sites

I'm very interested in what you are going to do. Unfortunately I can't help much because I don't know the AI well.

Welcome and I wish you all the best! :)

... which will not be based on scripting (since scripting is static) and will be implemented in C++.

Could you elaborate on that? What do you mean by "static" and "dynamic" in this context?

I can't think of anything that makes c++ a lot more "dynamic" than Javascript. I'm no Javascript expert but as far as I know all the important OOP concepts are available and even if you have to write some additional C++ code to get additional information for the AI, it should be possible to process that information using Javascript.

Link to comment
Share on other sites

I am pretty sure "scripting" doesn't refer to javascript per say. Scripted AI for instance would be AI designed for such and such faction and such and such map, as opposed to generalized AI which would evaluate the stats of units and use them based on that.

He may also not be aware that 0AD runs main engine functions in JS, but I can't say for sure.

Link to comment
Share on other sites

I think he means some sort of adaptative AI that would learn from the player/games and slowly improve. They're quite in fashion right now, I'm not sure how efficient they could get though, but it'll be very interesting to see anyway :) .

IMO that aproach would still be static in code. Just the data the code uses change. To get dynamic code with C++ would mean you'd have to compile during runtime. In that sense uncompiled/JIT-compiled languages seam the right decision to me if "dynamic code" is indeed the aim.

So Yves question seams quite relevant.

Could you tell us a little more detailed what you intent to do, agapsguy?

Edited by FeXoR
Link to comment
Share on other sites

Dynamic AI, in the contest of what I want to do, is based on skill learning and dynamic scripting and has nothing to do with runtime compilation. As an idea consider a C++ coded AI, with rules stored in a file on HDD and AI decides which rules to execute. To be dynamic, any action can be executed via different rules, and the AI selects one of these relative rules based on a calculation at runtime. Moreover, the AI becomes adaptive by learning from the player.

Link to comment
Share on other sites

Just to clarify, an AI is not necessarily static if it has static code. In my approach, for example, the rules are not static and everything is player-oriented. A static AI is a hard-coded AI that for every action has 1 or more rules it can execute which are relative to that action, in such a way that those rules never change (excluding changes made by the developer himself) and the number of rules relative to each action therefore does not change as well.

Edited by agapsguy
Link to comment
Share on other sites

Dynamic AI, in the contest of what I want to do, is based on skill learning and dynamic scripting and has nothing to do with runtime compilation. As an idea consider a C++ coded AI, with rules stored in a file on HDD and AI decides which rules to execute. To be dynamic, any action can be executed via different rules, and the AI selects one of these relative rules based on a calculation at runtime. Moreover, the AI becomes adaptive by learning from the player.

Seems that the only thing that really needs to be C++ is the interface to the HDD. All the actual AI logic could still be JS.

If you chose to do it this way, I believe we would be more likely to be able to use your results too, since we need to keep as much code in JS as possible, for moddability etc.

Link to comment
Share on other sites

I'll keep that in mind during the implementation stage, however performance-wise developing in JS could result in slower gameplay than C++. On the other hand, if after I finish the project the developers here would be interested to see how it could work in the game, I'll definitely hand-in a lot of documentation ;)

Link to comment
Share on other sites

It just came to my mind that an AI saving it's data to evolve over more than one game will break sync in multiplayer games if the data (in this specific case the rules if I get that right) are not shared before the game starts.

Edited by FeXoR
Link to comment
Share on other sites

I know FeXoR, which is one of the reasons why any multiplayer aspect is out of the scope of my thesis. If, after finishing the thesis, it is decided that work on the AI is continued for 0 A.D., then I'm sure we can find a way to sync the rules. But, for my thesis, I will only consider a 1-1 game (1 player and the AI).

Link to comment
Share on other sites

  • 6 months later...

Sorry to bump an old topic but I wondered if there were any updates on this project? I'm working on something for my masters project (real-time/interactive video game music) which I believe requires similar access to the JS data through the C++ code

With the other games I've worked on, I've passed data into a shared memory buffer, but I'm struggling to get my head around how to actually access the game logic from C++ (and from what I gather I can't simply pass the data into a buffer from the JS code).

I'm trying to call ScriptInterface but I must be missing something, I studied the CmpAIManager at length but don't seem to be able to successfully call it myself without running into trouble.

Thanks!

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...