Lua <-> AI Solution n#1

Lua <-> AI Solution n#1

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Lua <-> AI Solution n#1

Post by AF »

http://www.darkstars.co.uk/2008/lua-ais ... n-modules/

I have a second solution Ill post in a few days which is geared towards a totally different set up and paradigm, but here's solutionnumber 1.

I'd also like to see work on figuring out how the lua<->AI interface actually works.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Lua <-> AI Solution n#1

Post by Tobi »

TBH the solution you present is a bit of an utopy.

LUA is a dynamic language, C/C++ is a static typed language. Even microsoft hasn't figured out entirely how to best make dynamic objects available to statically typed languages. (IronPython can use C# classes perfectly, but IronPython classes are some Dynamic Language Runtime proxy class in C#, and AFAIK even with those not everything works yet.)

I think with most proxy-class based approaches from static to dynamically typed language you either end up creating new proxy mostly from scratch for each dynamic language object you want to access from C/C++, or you end up with an ultra-generic proxy that only takes strings as function names etc. (mostly defeating point of proxy then, apart from some OO around the single LUA object)

IMHO best approach if you insist on making AI suitable for all mods ever made would be to implement rich high level LUA bindings in the AI. These wouldn't even necessarily need to be able to commicate with mod LUA, though it could ease development (in particular for cheating AIs, if it can access LuaRules :-))

Current interface just executes a line of LUA and returns the string result IIRC.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Lua <-> AI Solution n#1

Post by trepan »

Current interface allows you to call the AICallIn() LuaRules/unsynced
function (if it exists), and pass it in a raw chunk of data (ex: it does
not have to be 0 terminated). That call-in can then parse the data
however it wants, and return another raw chunk of data.
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Re: Lua <-> AI Solution n#1

Post by Triaxx2 »

As far as I've found, the best solution seems to be to write the AI in LUA.

That solution seems to be a direct conversion from C++/C# to LUA. It looks to me like it's more effort than would be required to straight convert to LUA.
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Re: Lua <-> AI Solution n#1

Post by tombom »

Oh cool guys we have Triaxx2's opinion on this

he's the expert we can all just go home now
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lua <-> AI Solution n#1

Post by AF »

Can we please keep sarcasm to a minimum. This is the AI forum and it would be best if it remained intellectual where possible. The last thing we need is to put off newcomers and derail discussions by targeting members of the community. Show a little respect.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Lua <-> AI Solution n#1

Post by Agon »

Get back to topic ;)

The main problem as I understand is that there are different mods which uses Lua in different ways.
Eg.:
CA: Different way of generating metal than BA.
Chicken mode: Has chicken spawn events.
THIS: Has no "normal" resources. Uses a for the ai unknown way of creating units.
Fibre: No "normal" resources. Getting resources is different from normal TA mods.

Some solutions:
1. Mod calls events and passes strings with it. AI has for each mod an adaption.
2. Mod can use a LuaAI interface there things like new resources, events are predefined and the AI can use them.
Like:
CheckInNewResource(string name, int[] unitsGeneratRes):
UnitNeedsResource(string name, int amount);

Both solutions are not the best and I'm as a player can't think of better solution currently. The main problem is that there are many different informations/events which are generated by Lua (in the mod) which the AI needs to play the mod. Besides that it is different from mod to mod.

I think best would be to write a LuaAI interface to standardizes Lua<->AI handling.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Lua <-> AI Solution n#1

Post by trepan »

LuaAI is probably not the interface that you mean, that would
be LuaRules + AICallIn(). LuaAI is intended to be used to write
synced AIs in lua (and run in the LuaRules synced environment).

LuaAI vs GlobalAI
  • Some PROS
    • lower network transfer requirements
      no need to compile for different OSes
      mod specific AI embedded within the mod
      (it came with the mod, so it should behave well with it...)
    Some CONS
    • lua speed vs native dll speed
      all clients must calculate AI behaviour (synced)
      call-out availability (ex: better metal map access)
      must be synced (ex: GPGPU isn't possible)
You could also write an unsynced AI in lua (iirc). That could also
be included in a mod archive, and would allow you to try GPGPU
techniques, etc...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lua <-> AI Solution n#1

Post by AF »

Lua AIs also lack multi-threading and the ability to make use of external libraries. Using a custom geometry or terrain analysis library in a luaAI is not an option unless its written in lua which is highly improbable.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Lua <-> AI Solution n#1

Post by trepan »

That would be part of the "call-out availability".
More AI-centric call-outs could be added to Spring for
computationally expensive tasks (there probably aren't
that many before using LuaAI as a high level control
becomes a viable alternative). As for your comment
about not being able to use external libraries ... it
depends in what language they are written ;-)

If there are libraries that people think would be great
additions for AI, I'm fairly sure that they could be added
to the Spring Lua interface without that much trouble.
An example of that line of thought (provided by jc):
viewtopic.php?f=15&t=15004
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Lua <-> AI Solution n#1

Post by Agon »

I did not mean the LuaAI which provides a way to develop Lua AIs.
I meant an interface written in Lua which provides methods/events to communicate between a mod and a AI.
Mod<->"Lua AI Interface"<->Spring AI Interface<->AI
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lua <-> AI Solution n#1

Post by AF »

Basically 2 objects sitting on either side of the lua AI divide acting as messengers in order to provide a standardized interface where the existing interface does not? Isn't that sort of what I proposed in my recent blog post as solution n#1?
http://www.darkstars.co.uk/2008/lua-ais ... n-modules/
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Lua <-> AI Solution n#1

Post by Agon »

AF wrote:Basically 2 objects sitting on either side of the lua AI divide acting as messengers in order to provide a standardized interface where the existing interface does not? Isn't that sort of what I proposed in my recent blog post as solution n#1?
http://www.darkstars.co.uk/2008/lua-ais ... n-modules/
Sort of ;)
Do you want to use the "messaging" like this:
Mod(Lua)->MessageToAI(string "CaChickensSpawned");
Mod(Lua)->MessageToAI(string "Ressource|Name:Iron");
Mod(Lua)->MessageToAI(string "UnitRequires:Ressource|Name:Iron|Amount:100");
or like this:
Mod(Lua)->SpawnEvent(typeOfSpawn units);
Mod(Lua)->RegisterRessource(string "name", unitId[] unitsGenerateRes);
Mod(Lua)->UnitRequires(typeOfRequire ressource, string "name", int 100);
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lua <-> AI Solution n#1

Post by AF »

tbh I haven't the brainpower to think up a reply so dont think Im ignoring you if it takes me a while to answer, but Ill get back to you when I've caught up on 20 hours or so of sleep.
tberthel
Posts: 59
Joined: 12 Jan 2008, 06:17

Re: Lua <-> AI Solution n#1

Post by tberthel »

I can't wait to use this along with JAI.

Cool stuff.
Post Reply

Return to “AI”