Page 1 of 1

Lua AI?

Posted: 24 Aug 2007, 05:38
by smoth
So I was thinking with the AIs and lua, we are going to have issues. However, what is an AI? An advanced state machine looking for rules and conditions. So why can we not write a lua AI player? one that can be give like .addbot team# ally# color#

the lua can issue commands, check on the status of it's units and execute cheats if need be rather then having to always set a handicap! The lua ai could read possitions from the radar storing in a map even categorizing them based on tags stored on in the fbi files.

it would need no recompile! It would be crossplatform! So why is this not a good idea?

I am not doing this idea but it struck me as possible and felt I should suggest the notion.

Posted: 24 Aug 2007, 07:00
by Argh
Yup. Personally, I thought it was a "duh" thing, and I am guilty of assuming everybody else thought so, too, but weren't getting to it. After all, that's one of the reasons why I'm a bit obsessed about the whole LUA-->Gaia-->Maps thing.

However, there may be some things that we just don't know about, that may be getting in the way, especially including overall speed of execution, that may make this impractical. I dunno. It'd be interesting, though, to see a rules-based AI like NTAI as a LUA system, though, and I think LUA could do a couple of things, map-knowledge-wise, that current AIs seem to have some serious problems with, because of the things it is allowed to do, and how.

Posted: 24 Aug 2007, 07:06
by KDR_11k
AIs can get very CPU-intensive, especially good ones. You'd want at least some function to be run in native code.

Posted: 24 Aug 2007, 07:35
by Argh
Maybe that's an inherent limitation of all AIs. However, I wonder if that's more because of all of the hack-arounds they've gotta do, to get certain kinds of data out of Spring. I've often wondered what would happen if AIs shared more common elements in terms of data-collection methods, and were more specifically geared towards using that information, instead of having to interpret it.

That used to be very controversial territory, when everybody kept saying that AIs shouldn't cheat. Now, most of them do, and nobody cares, so I think it mainly depends on whether anybody even cares enough to try and build a cheating AI that uses LUA for high-level data-gathering, instructions to Units, and other tasks. We have, in various pieces, some of the things we need, such as using the Groups menus through LuaUI, etc., that could be applied...

I dunno, and I'm not really qualified to speculate at all, on relative costs or advantages, or even impossibilities that we can't see, so I'm shutting up now ;)

Posted: 24 Aug 2007, 10:16
by Dragon45
Uh, AI is intensive from pretty much any sort of theoretical computational perspective. Yes you can have engineering optimizations, but even an AI running in pure assembly is going to suck at a lot of stupid tasks and suck up ungodly amounts of resources.

Welcome to the limits of human knowledge.



But smoth actually has an interesting point from a usability perspective - even though a LUA AI, even if it would be "worse" than a pure C/whatever AI (because it would have access to the same amount of computational resources but use them more inefficiently), it would cross-platform, and stupidly easy to install.

Posted: 24 Aug 2007, 10:50
by smoth
well dragon, I am not talking about some sort of advanced thinking ai. I am saying one that cheats, does more reactive stuff. No thought ahead just builds stuff and in another thought process ocassionaly gives orders. Something like a more advanced mission ai. Less of an ai and more of a complex state machine.

build X build Y, send them at the enemy

stupid ai but it would be easy to use etc. good for missions or players to just have something to kill

Posted: 24 Aug 2007, 13:26
by Tobi
An AI in LUA perfectly fits the role of a dedicated AI for your mod only.

Since it is crossplatform you can safely include it and it will work on Windows and Linux and any future platforms, and it is easy to make modifications.

If you wanted to do the same with a compiled AI you'd need to include the .DLL (for win) and 32 and 64 bit .SO files (for linux) and if any new platform is supported by Spring you'd need to rerelease your mod with your AI compiled for that platform. (More importantly, on basically every Spring release you'd need to rerelease your mod because AI ABI may have changed...)

Additionally endusers can not be easily tricked into thinking the AI works on other mods too, since it is only available in your mod.

An AI as in a set of simple conditions that trigger certain actions or some FSE thing should well be possible this way, I think.

Posted: 24 Aug 2007, 15:24
by AF
You also forfeit the ability to draw from a huge pool of librarys and code examples and techniques available.

AIs atm can go quite far if the developers had unlimited time and motivation, but if they did it in lua they'd have to do things like implement delauney and voronoi and convex hull algorithms by themselves whereas the C++ guy just calls on something such as the CGAL library, whatsmore you're also giving up the ability to use threading and system APIs.

So for simple mod specific AIs this could go on but in the end run it just doesnt cut it, config based C++ AIs are the way forward at the moment which means we ened that Lua<->AI interface, which means we need ot change it so fancy highlighter widgets arent a higher priority than simple Lua<->AI communication.

All thats needed is a nice simple way of sending a string to lua and recieving one back. No messing around encoding strings as float values, no one way communication, no fiddling around with sending commands to units and lua catching them rather than sending them directly to lua, just bog standard SendToLua(const char* msg); callout and a LuaMessage(const char* msg); callin.