agapsguy Posted March 5, 2013 Report Share Posted March 5, 2013 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 statusPlayer information / status and logs of all the actions he/she performsAI status (all units, buildings, what units are doing, scores, available resources / upgrades, etcThe 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, etcNow 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 1 Quote Link to comment Share on other sites More sharing options...
zoot Posted March 5, 2013 Report Share Posted March 5, 2013 Others are much more informed on this than me, but have you inspected the AI manager?https://github.com/0ad/0ad/blob/master/source/simulation2/components/CCmpAIManager.cpp Quote Link to comment Share on other sites More sharing options...
FeXoR Posted March 5, 2013 Report Share Posted March 5, 2013 (edited) 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-devGood luck with your project and have a nice stay. Edited March 5, 2013 by FeXoR Quote Link to comment Share on other sites More sharing options...
Echelon9 Posted March 5, 2013 Report Share Posted March 5, 2013 I'll choose to agree to disagree with the statement that 'scripting is static and thus not appropriate for a dynamic and adaptive AI, so instead code it in C++', and welcome you to the working coders on the engine! Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 5, 2013 Author Report Share Posted March 5, 2013 Thanks guys I'll focus on that class and also ask on the chat. Quote Link to comment Share on other sites More sharing options...
wraitii Posted March 5, 2013 Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
zoot Posted March 5, 2013 Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
FeXoR Posted March 5, 2013 Report Share Posted March 5, 2013 (edited) 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 March 5, 2013 by FeXoR Quote Link to comment Share on other sites More sharing options...
zoot Posted March 5, 2013 Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 5, 2013 Author Report Share Posted March 5, 2013 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 Quote Link to comment Share on other sites More sharing options...
Burzum Posted March 5, 2013 Report Share Posted March 5, 2013 (edited) Here's a guy that is devoting himself to contribute in the coding side.I think he needs a better, more decent welcome Edited March 5, 2013 by Burzum 1 Quote Link to comment Share on other sites More sharing options...
feneur Posted March 5, 2013 Report Share Posted March 5, 2013 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 1 Quote Link to comment Share on other sites More sharing options...
Yves Posted March 5, 2013 Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
wraitii Posted March 5, 2013 Report Share Posted March 5, 2013 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 . Quote Link to comment Share on other sites More sharing options...
MoLAoS Posted March 5, 2013 Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
FeXoR Posted March 5, 2013 Report Share Posted March 5, 2013 (edited) 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 March 5, 2013 by FeXoR Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 5, 2013 Author Report Share Posted March 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 5, 2013 Author Report Share Posted March 5, 2013 (edited) 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 March 5, 2013 by agapsguy Quote Link to comment Share on other sites More sharing options...
alpha123 Posted March 5, 2013 Report Share Posted March 5, 2013 I must say this sounds very cool. Best of luck to you agapsguy!Definitely feel free to ask on IRC. The AI code really isn't well documented at the moment. :/ Quote Link to comment Share on other sites More sharing options...
zoot Posted March 6, 2013 Report Share Posted March 6, 2013 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. Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 6, 2013 Author Report Share Posted March 6, 2013 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 Quote Link to comment Share on other sites More sharing options...
FeXoR Posted March 6, 2013 Report Share Posted March 6, 2013 (edited) 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 March 6, 2013 by FeXoR Quote Link to comment Share on other sites More sharing options...
agapsguy Posted March 6, 2013 Author Report Share Posted March 6, 2013 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). Quote Link to comment Share on other sites More sharing options...
idanwin Posted March 8, 2013 Report Share Posted March 8, 2013 Wow, nice project! I intend to study Machine Learning in a few years, so this is certainly something I'm going to follow with great interest ;-) Quote Link to comment Share on other sites More sharing options...
rayman Posted September 14, 2013 Report Share Posted September 14, 2013 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++ codeWith 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.