Interface Redesign - Page 15

Interface Redesign

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

Moderators: hoijui, Moderators

User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Interface Redesign

Post by Agon »

hoijui wrote:ok.. again about the options and the static properties:
i wanted to have it in one file, AF though it should be one. but i would like some more feedback. first, i don't know anything about LUA. why i wanted it to be 2 files, is becuase in hte mods, it are two files as well: ModOptions.lua and modinfo.tdf.
i though we could have AIOptions.lua and AIInfo.lua. cause then we could surely use th eexisting parsers for LUA options, and possibly had to write one for the info, as the mods use tdf, and not lua for that (or did that change already?). Though, if it is possible to put thos htings in one file, and you think we should do that, we could do it.
soo.. feedback pls! as many as possible.
I think it depends on the amount of code which will be used in common for AIs in this files.
If we put this two files together and most AI will have more than 80 lines of code it then we should split the file in two.

Btw. what will AIOptions.lua store and what AIInfo.lua?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

what they will contain:
you could open a mod archive, and look at ModOptions.lua and modinfo.tdf, which both should be in the root of the archive. for AIs, it would look quite the same, just that we could use lua for the info file as well (as i understood it, lua is the "new and fancy" stuff, and everything is getting converted to lua anyway).

in info, we have static properties of an AI, like this:

Code: Select all

shortName=RAI
version=0.600
name=Reths Skirmsih AI
description=An AI that supports most mods, also non TA ones
.
.
.
in the options file, we have dynamic options. for mods, you can select them in TASClient when Hosting a game eg. things like type of the commander (list), or metalRate (float).
for AIs, the options could be things like difficulty (int), cheat (bool).

the Option file could have the exact same syntax for AIs like for mods. the info file would most likekely contian a bit different values, while some would be the same.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

about version checking:
possibilities i see:
  • not do it at all
  • make the AIs and AI interfaces export the version(s) they support
  • have functions on the AIs and AI interfaces like this:

    Code: Select all

    LevelOfSupport GetLevelOfSupportFor(const struct VersionInfo* versionInfo)
    with:

    Code: Select all

    // for interfaces
    struct VersionInfo {
       const char* springVersionString = "0.77b1";
       int springRevision = 5555;
    }
    // for AIs
    struct VersionInfo {
       const char* springVersionString = "0.77b1";
       int springRevision = 5555;
       const char* interfaceShortName = "C";
       const char* interfaceVersion = "0.1";
    }
    
    this method could be in the AI library or in a lua file (eg. also AIInfo.lua)
and other question that came up:
when we specify an ai. eg: "RAI#0.600"
how will we determine which interface should be used, if we do not want to load all interface libraries to know which ones work?
ideas:
  • by using the GetLevelOfSupportFor() method described above
  • by specifying the interface shortName and minimal version needed by the AI in AIInfo.lua
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Interface Redesign

Post by BrainDamage »

i've been skimming over the thread, and i have to say that i don't really like the choice of ainame+separator+version in the script.txt

both TDF and lua are structured data formats, what's the point of rolling your own sub-token when you can just add a new entry in the node?

something on the line of
ainame=AAI
aiversion=0.66
it's 100% retro compatible since old spring versions will just ignore the additional tag, the additional code to generate the new tag is 0 compared to the custom separator in a parser/writer class.

so I don't see why one would wanna do something non standard as custom separator, difficult to parse (spring has already a 100% working tdf parser) for the sake of saving few chars in the code.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Interface Redesign

Post by imbaczek »

+1 for using multiple tags instead of a delimited string.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Interface Redesign

Post by Agon »

imbaczek wrote:+1 for using multiple tags instead of a delimited string.
Yeah, +1 from me, too.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

after talking to Kloot, i think the whole version support/version checking stuff will look like this:

Each interface will specify the following, in its InterfaceInfo.lua file:

Code: Select all

minEngineVersion (optional)
maxEngineVersion (optional)
and each AI will specify this in its AIInfo.lua:

Code: Select all

minEngineVersion (optional)
maxEngineVersion (optional)
interfaceShortName
minInterfaceVersion (optional)
maxInterfaceVersion (optional)
the min versions can be useful, if the AI uses aspects that are only available in new versions of the engine or interface. hte max versions could be useful if an AI is not under development anymore eg, or if we want the AI to unly be used with the current release version eg, and enforce using a newer release of the AI for later engine versions.

what i am not sure of yet is, if these values should be checked by the engine aswell, or if they should just be a help to the user (they would be shown ot the user when he selects the AI in the lobby eg)
short: user wants to start an AI with minEngineVersion=2 with engine version=1 -> should the engine crash and report an error, or try using the AI anyway?
User avatar
DJ
Posts: 355
Joined: 17 Jan 2007, 13:26

Re: Interface Redesign

Post by DJ »

What's the status of this at the moment? Will it be in the 0.77 release?

Is there a wiki article or other guide I can read to learn more?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

it is nearly certain that the new AI stuff wont make it into 0.77 (like 99% or more).

finally it is working in linux (compiled with gcc and cmake) and on windows (compiled with mingw and scons).

i committed my changes. i did it in several commits, as i had some SVN related problems.. sorry, but it is all up now.

works:
+ AI Interface libraries
+ Skirmish AI libraries
+ AIInfo.lua and AIInterfaceInfo.lua can be read from unitsync(untested) and are read by the engine, to know what engines are around (eg to check if script.txt specifies good values, and for the startscripts)
+ AIOptions.lua can be read through unitsync(untested)

does not work:
- group AIs (most of the interface code is still missing, the game crashes if you try to select one in game)
- actually passing option values to the AIs (though that will be very simple to add)

How to specify an AI in script.txt
LUA AI:
both are possible, the first one only for legacy support:

Code: Select all

aispecifyer=LuaAI:<luaAIName>

Code: Select all

luaai=<luaAIName>
Skirmish AI:

Code: Select all

aishortname=RAI
aiversion=0.600
the second line (specifying the version) is optional.

i guess you will have more questions. i am to lazy to think of any other things, so please just ask.

please, start testing it!

edit: it is the caiinterface branch, containing the changes
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Interface Redesign

Post by AF »

  • Remove groupAI support and re-implement it in the far future when there's an actual demand for it
  • aispecifyer aside from being misspelt is a bit confusing as it invokes the following naming conundrum:

    The ai specifyer specifier
  • aishortname seems confusing as there must be a long name and a plain ai name etc, how about:

    Code: Select all

    [AI]
    {
        id=kai;
        version=0.666;
        interface=blah etc;
    }
    
    Much cleaner and much more 'semantic' far less confusing, much less replication of the word 'ai'.
  • Existing Lua AIs should use the above suggested itnerface and the 'interface' tag, this way we do not have multiple script.txt apis and the lobby interface is more coherent and simplified.

    Also it would solve the problem of having both luaai tags and the other tags mixed together thus ending up with 2 AIs controlling the same units and both expecting total control..
  • Can you further outline the interfaces without requiring us to do a large svn checkout or sift through a 100 page svn commit log/email? Especially regarding unitsync.
  • Is it possible to implement the script.txt suggestion I made above in 0.77 so that in 0.78 we don't have to change all the lobbies for the new functionality unless we want to use options?
User avatar
DJ
Posts: 355
Joined: 17 Jan 2007, 13:26

Re: Interface Redesign

Post by DJ »

From reading further it sounds like you've done a sh*t load of work on this - much appreciated. The attraction for me was to be able to develop an AI in c# or java without having to get all the packages together to compile spring. I guess through lazyness what i'm after is a start guide similar to what you did with JAI.

From the sounds of it we maybe some way from that...
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

AF:
i am ok with removing group AI support.

damn...
i used specifYer in soo many places in the code :D
shit

well.. this place is actually the least problem, as it is only there for legacy support:
in the past, a lua ai had ot be declared like this:

Code: Select all

aidll=LuaAI:<lua-ai-name-here>
as you always want as little change as possible for lobbies, i included this legazy support.. though.. thinking about it, it is quite stupid anyway, as you still had to change the lobby for it. i will remove it totally, and only leave the other option, which is cleaner anyway.

shortname is used cause it refers to the shortname in AIInfo.lua, which additionally contains a name (can be seen as the long name). it is like this, cause AIInfo.lua uses the same keys like ModInfo.lua (shortName, name, description, ...) so it will remain shortName, not id. the interface does not have to be specifyed in script.txt at all, the engine handles that.
for me it would be ok to go from this:

Code: Select all

aishortname=RAI
aiversion=0.600
to this:

Code: Select all

[AI]
{
    shortName=KAI;
    version=0.666;
}
how would it be with options then? like this:

Code: Select all

[AI]
{
	shortName=KAI;
	version=0.666;
	[OPTIONS]
	{
		divLevel=4;
		otherOpt=0.1;
	}
}
?

of course it is not problem to make the AI report an error when both a LuaAI and an.. other ai is specifyed.

well, if you want to know the interface better, i suggest checking out the branch amd looking at RAI, KAIK and NullAI (NullAI does not use the CppLegacy wrapper, but interfaces only with the new C interface). if you dont want to check out... ask specific questions, or read everything i wrote here in this thread.

new in unitsync:

Code: Select all

Export(int) GetSkirmishAICount();
Export(struct SSAISpecifyer) GetSkirmishAISpecifyer(int index);
Export(int) GetSkirmishAIInfoCount(int index);
Export(const char*) GetInfoKey(int index);
Export(const char*) GetInfoValue(int index);
Export(const char*) GetInfoDescription(int index);

Export(int) GetSkirmishAIOptionCount(int index);
the changes to script.txt are bound to the new interface stuff... so why would you want ot include them before the interface?
we can not specify shortName and version if we still use the old AI interface stuff (directly naming the sharedLibrary).


@DJ:
yes, it was lots of work ;-)
mainly the debugging, with which i had lots of problems (not beeing able to debug well, not understanding whats wrong, and so on)

you could now start with writing a C# interface library, if you want. if you do that, use the C interface as reference (described below), and forget about JAI. it is outdated/not using the new interface. i first have to port it.
though, you would still have to compile spring yourself as well. or is the build bot able to compile branches? i dont know, but it is not such a big deal to do it yourself. if you follow the guide here http://spring.clan-sy.com/wiki/Engine_D ... nvironment, you could be ready in less then an hour (if you have not yet installed anything you need).
if you want to do that, have a look at the following files:
rts/ExternalAI/Interface/SAIInterfaceLibrary.h
AI/Interfaces/C/Interface.h
AI/Interfaces/C/Interface.cpp
AI/Interfaces/C/InterfaceExport.h
AI/Interfaces/C/InterfaceExport.cpp
for a start, you would have to copy AI/Interfaces/C/InterfaceExport.h to AI/Interfaces/CSharp/InterfaceExport.h eg, and then start writing your C -> C# interface code in AI/Interfaces/CSharp/InterfaceExport.cpp


am tired now, sorry if i forgot something, please ask again
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

... is anyone planing on helping to test it?

i tryed using an intel compiled RAI with a gcc compiled spring, which crashed. will try to debugg it somehow (uhh huh, am so excited!!)

anyone?
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Interface Redesign

Post by Agon »

Hm, I will start researching how to do an C# interface.
Maybe I can find someone who has the knowledge to do this.

Edit:
How many classes/methods/variables do I need to wrap?
I ask because I don't know if it is less work to learn how to use Swig and generate the wrapper with it or do it by hand.
Hoi: How did you do it with the Java bindings?
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: Interface Redesign

Post by Hoi »

Agon wrote: Hoi: How did you do it with the Java bindings?
Lol I thought you was talking to me :mrgreen:
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

Agon
hoijui wrote: you could now start with writing a C# interface library, if you want. if you do that, use the C interface as reference (described below), and forget about JAI. it is outdated/not using the new interface. i first have to port it.
though, you would still have to compile spring yourself as well. or is the build bot able to compile branches? i dont know, but it is not such a big deal to do it yourself. if you follow the guide here http://spring.clan-sy.com/wiki/Engine_D ... nvironment, you could be ready in less then an hour (if you have not yet installed anything you need).
if you want to do that, have a look at the following files:
rts/ExternalAI/Interface/SAIInterfaceLibrary.h
AI/Interfaces/C/Interface.h
AI/Interfaces/C/Interface.cpp
AI/Interfaces/C/InterfaceExport.h
AI/Interfaces/C/InterfaceExport.cpp
for a start, you would have to copy AI/Interfaces/C/InterfaceExport.h to AI/Interfaces/CSharp/InterfaceExport.h eg, and then start writing your C -> C# interface code in AI/Interfaces/CSharp/InterfaceExport.cpp
with the C interface, it should now be considerable less you have to wrapp. all you need is under rts/ExternalAI/Interface, exluding rts/ExternalAI/Interface/LegacyCppWrapper. it are mostly very small structs, with these exceptions, which are medium till large (largest one first):
SAICallback
AISCommands
AISEvents

you have to decide yourself if you will use SWIG or not. i did use SWIG before, as there were lots of classes and structs in many files, in hirarchical relation to each other. all this is not the case anymore now. i think, i will only use regexes to generate the wrapper code, not SWIG, when porting JAI to use the C Interface.

if you want, you can also come to the #sy channel on the lobby server, if you have more questions. i may not answer instantly, but i am usually around there.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Interface Redesign

Post by Agon »

Hoi wrote:
Agon wrote: Hoi: How did you do it with the Java bindings?
Lol I thought you was talking to me :mrgreen:
Ups, no.
I meant hoijui.

hoijui:
Thanks. I think I will do the job with Swig.

Edit:
"GroupAiCallback.h/cpp"
Why is here AI named Ai, the other files are "*AI*".

Edit02:
Same goes for "IGroupAiCallback.h/cpp"

Do I need to wrap the interface ('I*') and the normal files or only one of them?
The Mono AIInterface would load the Mono runtime and the AIs, I'm right?

Edit03:
While trying to compile the branch I recive this:

Code: Select all

/store/workspace/spring-caiinterface/rts/Game/Game.cpp: In member function ├óÔé¼╦£void CGame::ActionReceived(const Action&, int)├óÔé¼Ôäó:
/store/workspace/spring-caiinterface/rts/Game/Game.cpp:2032: error: invalid use of incomplete type ├óÔé¼╦£struct CGroup├óÔé¼Ôäó
/store/workspace/spring-caiinterface/rts/Sim/Units/Unit.h:18: error: forward declaration of ├óÔé¼╦£struct CGroup├óÔé¼Ôäó
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

hey Agon :-)
for the future: if you have something else to say, do an other post, do not edit your last one, even if you already did the previous post. i saw your post just now, cause i did not check the topic, as it did not have any new posts.

your questions:
GroupAiCallback.h/.cpp is directly under rts/ExternalAI. you should not care about this folder directly, but only about the subfolder rts/ExternalAI/Interface.
uninteresting for you:
- rts/ExternalAI (Legacy C++ Interface and connection to of the C Interface to the engine)
- rts/ExternalAI/Interface/LegacyCppWrapper (AI part of the Legacy C++ AI Interface)
interesting for you:
+ rts/ExternalAI/Interface (C AI Interface)

you should wrapp pnly the C interface, and not care about the rest. IGroupAiCallback.h/cpp eg is also part of the legacy C++ interface -> dont wrapp it.

i am having a look at the errors you get when compiling. could you maybe tell me how exactly you are compiling? (OS, build system, compiler)
(from the compile erroroutput, i guess you use linux. trying to find what could be wrong ...)

something else:
as it works at the moment, the AI interface has to read the AI LUA info and option files. i figured that this is quite stupid, and that the engine should do it. i will change that, and this will make your work easier (the AI Interace library, eg the one you will make for C#, will have to export less functions and will not have to deal with anything LUA at all). i hope to do it soon, but till then, you could simply forget about the following functions in SAIInterfaceLibrary, as they will be removed:

Code: Select all

getSkirmishAISpecifyers
getGroupAISpecifyers
i also recommend you not to implement the following two functions, as they are optional, and currently not used at all by the engine:

Code: Select all

getInfos
getLevelOfSuportFor
so you only have to implement the following six functions from SAIInterfaceLibrary:

Code: Select all

loadSkirmishAILibrary
unloadSkirmishAILibrary
unloadAllSkirmishAILibraries

loadGroupAILibrary
unloadGroupAILibrary
unloadAllGroupAILibraries
while the later three have to be there for your library to sucessfully load, you can have them doing nothing, as the C AI Interface fro Group AIs is not yet done.

am having a visitors today, but tomorow i should have time to do the change. and as siad, i will have a look at your compile errors.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Interface Redesign

Post by hoijui »

the erro you get is strange. CGroup is a class, and in every forward declaration in the code, it is declared as class. so i dont know why your compiler thinks it is a struct. did you try to compile without any code added or changed at all?
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Interface Redesign

Post by Agon »

Thanks for informations.
I'm using Linux (openSuse x64) and gcc (SUSE Linux) 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]

Complete log is here: http://paste.uni.cc/19356
Post Reply

Return to “AI”