Lua <-> AI

Lua <-> AI

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

Moderators: hoijui, Moderators

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

Lua <-> AI

Post by AF »

Despite whatever people have said this is a myth.

But Trepan added a set of 6 or 7 functions to the AI interface.
They were removed in a later commit.

Why dont you just send the AI a command?

AIs dont recieve commands.

But you can send commands to lua right?
Yes but that isnt good enough

Why?
Commands dont have string parameters, they're just lists of floating point nubmers.

Whats wrong with floating point numbers?
Nothing meaningful can eb represented using them that wouldnt require AIs recieving data from lua or a very longwinded and horrible method of encoding strings as floatingf point numbers

But commands have string parameters!!
No they dont, this is just a lua thing.

But look here at "shift": GiveOrderToUnit(unitID, CMD_ANYTHING, { "1" }, { "shift" })
Thats just something trepan used in hsi API, the spring lua API will translate that into an unsigned char value which goes into a command structure to signify a key modifier, you cant just store arbitrary string values that way:

Code: Select all

struct Command {
	CR_DECLARE_STRUCT(Command);
	Command()
	: timeOut(INT_MAX), options(0), tag(0) {};
	int id;
	vector<float> params;
	unsigned char options;
	unsigned int tag;
	int timeOut;  // remove this command after this frame
	              // can only be set locally, not sent over net
	              // (used for temporary orders)
};
So what if the communications 1 way and only allows float numbers, you dont need lua -> AI communication!

Without lua -> AI communication, AIs that play mods that use lua is virtually impossible. Theyd have to be dumbed down greatly in order to play the game and they wouldnt play well at all, it just wouldnt be worth even attempting.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Post by jK »

damn, you was right no dev is interested in it :(

and imo a lua<->AI interface wouldn't only improve single player games (which i don't play :oops:). it would make multiplayer mission with luaGaia possible or much easier, cause you wouldn't have to rewrite a complete ai in lua, instead you could interact with existing ais and give them commands ...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Even without singleplayer, AIs have a place in multiplayer too in compstomps, a vital tool for training new users.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

With lua<->Ai it would possible to "speak"/write with the AI.
Giving commands or tactic how to attack in corporation.

Its a good idea!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I could allow modders to implement their own simple task keywords specific to their mod such as a sell command or a superweapon manager.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Post by Pressure Line »

AF wrote:I could allow modders to implement their own simple task keywords specific to their mod such as a sell command or a superweapon manager.
mobile mexxes :/
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

tbh this shouldnt be hard to implement, Id do it myself if I could. I did ask about it but I was given a big lecture on being an ass making other people do work for me because Im too lazy, despite the large number of projects and efforts Im, responsible for.

Sadly fancy highlighter shaders and GUI sfx are considered a higher priority than working singleplayer in the current effort to "make everything work" =(
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Re: Lua <-> AI

Post by Neddie »

AF wrote: But Trepan added a set of 6 or 7 functions to the AI interface.
They were removed in a later commit.
Which functions, and why were they removed?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Post by Kloot »

Trepan's additions weren't removed, they just haven't been implemented yet (and the commit log said as much). From AICallback.h:

Code: Select all

// LuaRules state
bool IsLuaRulesEnabled();

// LuaRules info (return false if the information is not available)
bool GetGameRulesParam(int param, float& value);
bool GetGameRulesParam(const char* param, float& value);
bool GetTeamRulesParam(int teamID, int param, float& value);
bool GetTeamRulesParam(int teamID, const char* param, float& value);
bool GetUnitRulesParam(int unitID, int param, float& value);
bool GetUnitRulesParam(int unitID, const char* param, float& value);

// Lua Script unsynced call
enum LuaCallState {
	LUACALL_SUCCESS     = 0,
	LUACALL_NOT_RUNNING = 1,
	LUACALL_UNDEFINED   = 2,
	LUACALL_ERROR       = 3
};

//
// The 'args' array size must be at least: max(inArgs, outArgs) 
//
LuaCallState CallLuaRules(const char* name, float* args, int argSize, int inArgs, int& outArgs);
LuaCallState CallLuaRules(const char* name, char* data, int dataSize, int inSize, int& outSize);
The only things that did disappear (in r3689) were these six prototypes:

Code: Select all

bool IsLuaUIEnabled();
bool IsLuaCobEnabled();
bool IsLuaGaiaEnabled();

LuaCallState CallLuaUI(const char* name, int inArgs, int& outArgs, float* args); 
LuaCallState CallLuaCob(const char* name, int inArgs, int& outArgs, float* args); 
LuaCallState CallLuaGaia(const char* name, int inArgs, int& outArgs, float* args); 
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

eeek, overcomplication found!

AI Callout:

const char* SendToLua(const char* message);

AI CallIn:

const char* LuaMsg(const char* message);

From this any AI related data can be sent easily. A very very simple 2 way communication, extremely obvious as to its usage, very very flexible and generic.

As to the state of lua represented by the enum, a simple returning null/0 would suffice, and would fit in with the behaviour of the rest of the AI interface.

Other than that, perhaps a parameter signifying where to send the message to. Of course there are numerous improvements ontop of that that're possible, however lets just have a working form of communication using strings even if it is very simplistic
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Lua <-> AI

Post by hughperkins »

AF, you're pretty good at this C++ stuff, I bet you could get something working for this Lua stuff pretty quickly?
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Lua <-> AI

Post by trepan »

AICallback.h:

Code: Select all

  // NOTES:
  // 1. 'data' can be NULL to skip passing in a string
  // 2. if inSize is less than 0, the data size is calculated using strlen()
  // 3. the return data is subject to lua garbage collection,
  //    copy it if you wish to continue using it
  const char* CallLuaRules(const char* data, int inSize = -1, int* outSize = NULL);
That was added quite some time ago, and
we ain't seen nothing from nobody yet. Lots
of talk about how it would be the cure all...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Lua <-> AI

Post by Argh »

Meh. I've been telling them that this was coming for months, in the context of P.U.R.E. and World Builder. Now that I see that it is possible to support Lua contexts, i.e., you already set it up, and nobody's bothered looking into it... meh, that's grim :P

We have a major disconnect here, between what AIs can do, and what we (game designers) would like them to do, and it's going to get steadily worse, until no major game can be played by an AI... unless they're very closely related to BA :P

I kept P.U.R.E. playable by KAIK pretty much by the skin of my (and Kloot's) teeth, and that took quite a lot of work- on my part, by avoiding stuff in basic Spring that will hose classical AIs, and on his, by supporting Gaia and Neutral stuff, and fixing various areas of KAIK that weren't working happily with the game. The final result's not too bad, but meh- at this point, after adding the new per-Unit features to the Resistance side, it's a nasty moment- Overmind has to remain very simplistic and feature-poor because of these issues, basically.

The next issue, insofar as I can see, is whether or not there's any real future to AI development, in the classic sense, or whether a Lua implementation offers a real path forwards here.

Not that I am asking any of you to write an AI with Lua, or anything. I think that mainly what needs to happen right now is some discussion about what's missing from Lua that is necessary for AIs to be built- not just simplistic time-driven stuff, but complete, state-driven AI.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Lua <-> AI

Post by hughperkins »

Somewhere in the back of my mind, I have this vague recollection that Supreme Commander is using Lua for its AIs? (Or maybe just for some sort of configuration / AI selection, I'm not really .. .don't really remember).
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Re: Lua <-> AI

Post by Peet »

Supcom uses lua for everything.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Re: Lua <-> AI

Post by jcnossen »

Even projectiles ugh... And people wonder why it is so slow :|
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lua <-> AI

Post by AF »

trepan wrote:AICallback.h:

Code: Select all

  // NOTES:
  // 1. 'data' can be NULL to skip passing in a string
  // 2. if inSize is less than 0, the data size is calculated using strlen()
  // 3. the return data is subject to lua garbage collection,
  //    copy it if you wish to continue using it
  const char* CallLuaRules(const char* data, int inSize = -1, int* outSize = NULL);
That was added quite some time ago, and
we ain't seen nothing from nobody yet. Lots
of talk about how it would be the cure all...
Too little too late.

Even if I attempted to use these right now I would be faced with having to figure out the code on the lua end of the divide with which to finish my design and provide for content devs to work with what I've developed, but there's is no documentation whatsoever beyond what is in your post.

On top of that, people are forgetting that for all intents and purposes, the AI development here has been killed off by neglect. The switch from Visual Studio to Mingw32 and gcc in itself raised the entry bar so high that the vast majority of potential newcomers to the spring AI scene were left out in the cold. Did nobody wonder why there have been no new AIs in the last 6 months? Whatever happened to the trend of 2 new AIs every 3-4 months back when we started?

Argh has had the incredible luck of pestering and driving kloot insane in order to fix issues with P.U.R.E. I for one am unwilling to release any more NTai releases because it is a huge hassle just to get a working compiler that will build a compatible spring AI binary. People have a horrid tendency to resort to a 'just use scons' answer, and this just isnt good enough. I know plenty of people who have just plain given up on scons, it seems like something that's only really well tested under linux, and I don't want to have to explain howto setup the whole thing to get the scons command to work properly to begin with.

Have you noticed that the existing AI developers have either moved from AI to engine development or dissapeared fromt he community all together? Perhaps making the odd update here every few months? I know for one that most of my NTai work in the last few months has been motivated by it being used for academic purposes as well as some attempts to clean up code to make it more presentable should any potential employers decided to poke there nose in.

Ontop of all this, lets say the AI community was as active as it used to be, and we AI developers had the tools to build our lua go betweens, there's no evidence that they would actually get used. The modding community in general seems to be ignoring AIs completely more and more. The only people who come to mind who buck this trend in any way are Ivory King who pops up every few months asking for a working NTai binary, and Argh who seems to complain about the state of affairs every week or two in the odd post.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Lua <-> AI

Post by Agon »

@AF:
Yeah, not much happens around and inside the ai area of spring.
One reason could be that more and more mods are using Lua for extra features like CA, Fibre, Pure, THIS and so on.
I would like to have a interface there Lua developer can provide informations which an ai can get.
Plus a function where lua code triggers an event where an ai can registered and use it.
So the modders can provide informations for the ai easily and in the right form and the ai developer can use the provided information to adjust there ai to the mod gameplay.
Maybe this is a bad idea for both, I don´t know. I was never a modder for spring or an ai developer.
But (good news for AF :D ) I would like to became one. Hope hughperkins is so nice to create a mono interface for me and the rest of the community.
The other reason is not every one likes C++. This point could be eliminated by hughperkins (Mono, supports >20 languages) and hoijui (Java).
Maybe hard to understand the ai interface?
Bad documentation for the ai interface?
Not much interest in this area from the player community?

Maybe a contest for AI developer could increase the popularity.
Trying to get a place on google summer of code next year.
Increasing the community through radio, blogs, forum posts and TV.
We could need a pr-manager :D .
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Lua <-> AI

Post by hoijui »

i don't know how realistic it is, but a google summer of code project for an AI soudn good to me! :-)
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Lua <-> AI

Post by Agon »

hoijui wrote:i don't know how realistic it is, but a google summer of code project for an AI soudn good to me! :-)
Not only for AI, for the complete Spring project.
The only problem is you need mentors, as I know.

For Lua<-AI the same solution could work as I mentioned in my post before. But as I wrote, don´t know if it is easy to implement, maintain and for both sides to use.

I see a big need for Lua<->AI in the feature of Spring. Nearly all new mods and releases of mods are using Lua and some really depend on Lua like Fibre and THIS.

If no interface will be available the developing of AIs for Spring could go to zero.
Post Reply

Return to “AI”