AI in War Worlds

Posted by

It's been a while since I blogged about War Worlds, and there's a good reason for that... but I can't say too much about it for now :) Anyway, I've done a little bit more work on it recently, and so I thought I'd just blog a little about what I've been doing.

I've been working a little on the AI which, as I blogged about before, is being done in Lua.

Now, there's two main functions in the War Worlds AI which make up the bulk of the API. The first is the one I blogged about before, self:find_units. The other one is self:issue_order (note: "self" in these function calls refers to the AI's "player" object, kind of like "this" in C++). With these two APIs combined, you should be able to do pretty much any AI.

Obviously, there was quite a bit of plumbing in the back-end that needed to go into it all before these could work, and they're still not the only thing you'll ever call, but it's a nice start.

Here's an example of some Lua from one of the test scripts I've written:


function check_attack()
    local units = self:find_units({ unit_type="factory", build_state="idle" })
    self:issue_order(units, { order="build", build_unit="simple-tank" })

    self:timer(10, check_attack)
end

So, line 2 of that snippet looks for all "factory" units whose "build_state" is "idle" (that is, all factories that are not currently building anything). The self:find_units function returns a collection of units - you can iterate them and do stuff like that if you like, but we just want to issue them a "build" order to build the "simple-tank" unit type, which is what we do in line 3.

On line 5, we call the self:timer function to schedule ourselves to run again in 10 seconds.

This is the basic way that the AI will be implemented for the initial release. I'm hoping to make the AI interface generic enough that people will feel compelled to write their own AI for the game. Who knows? Maybe we could set up tournaments specifically for the AIs that people have developed!

blog comments powered by Disqus