AI development

Discuss the future of Warzone 2100 with us.
fezvez
New user
Posts: 4
Joined: 30 Apr 2011, 15:24

AI development

Post by fezvez »

Hello there!

I've been lurking around these days, may it be inside the code, on the irc chan, or in this very forum. Well, I've learnt much, notably that there seems to be hacks simply... everywhere :P

However, I wanted to talk a little bit about what interests me, and how I might contribute to this fantastic project! I am studying Machine Learning/Artificial Intelligence right now. Among the things I've done, well, I've made an AI for Connect 4 (exploration of trees), I've made a Go program (Reinforcement Learning, like the MoGo program) and I've taught "kiting" to a Warcraft II archer (first with an online version of Boosting, and, with a completely different approach, with an online version of the Perceptron)

And I'm trying to do some interesting stuff with the Warzone 2100 engine! The basic thing I'm thinking of is instantiating a very simple map, two armies, one with a "standard" AI, the other one with a "custom" one. Then give the "custom" AI a smaller army, but much more computation time. And try to defeat the "standard" AI.

So, if I may, I'd like to ask you a few things :
  • It seems to me that in the main game loop (in loop.cpp), there is an droidUpdate() which calls aiUpdateDroid(). Just to be sure, it seems to me that this is only about the standard behavior of the robot (look for a target in range, then shoot it) Is it the case?
  • It seems to me that the droids I, as a player control, are given orders (DROID_ORDER, OrderList...). However, as I try to understand how things work, I know that the Qt QMainWindow captures the mouse event, then updates aMouseState... then nobody ever reads it again? I'm clearly missing something here!
  • I have literally NO clue where the AI scripts http://developer.wz2100.net/wiki/AiTutorial get inside the C++ code. Where do these scripts interact? Where is the holy function I'm searching for : giveOrderToDroid(DROID * targetDroid, ORDER * targetOrder) ?
  • And, to conclude, there's a general question concerning the 3 AIs that are currently implemented : do you have any idea at all in what they consist? Are they huge (hirarchical) finite state machine? Or something else?
I'm still exploring the whole thing (which is really huge) but I guess that in the end, I won't be able to code things using the AI scripts only. I need mathematical libraries (SVM, matrix handling, etc...), and I guess I'll need to toy with the C++ code.

So, if anyone can shed light on my problems, you'll have many thanks!
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: AI development

Post by Per »

Hi. You got it right, so far. We are in the process of moving from the old wzscript system to javascript at the moment, which will offer much better facilities for AI coding (math etc). See src/qtscript* for the work-in-progress code. Currently only the scavenger AI is controlled by this code, but all the hooks are there to use javascript now. We are missing lots of functions, though, but they should be easy to port over from the old script system. If I were to start writing a new AI, I would definitely start using this framework rather than the horrible (and horribly buggy) wzscript stuff. Look for the *.ai files that control the AIs, and just add a "js = myfile.js" line to add a javascript script to it.

If you want to look at wzscript, it is holed up in src/scriptfuncs.cpp, src/scriptvals.cpp, src/scriptobj.cpp and friends. Usually a script function "scriptFunc" is implemented somewhere in the C++ code as "scrScriptFunc".

Both old and new frameworks are entirely event driven. There is some information about how this works in the scripting forum.

I will try to make time for some introduction posts to the new javascript system soon.