Java AI Interface for Spring
Moderators: hoijui, Moderators
Re: Java AI Interface for Spring
What's the status on this - is the source available anywhere?
Re: Java AI Interface for Spring
aehm... i am back now, though i did not work on it yet, don´t even know if i will work on it again.
the status...
i have very bad memory.. if i find a little motivation i will look into my source again shortly, and figure out the status
the source is only available here.. form me.
do you want it? its nothing pretty though, but as i saw, you use netbeans too, so.. you might get around with it without too much problems.
i remember i splitted the project into 2..
one using SWIG and the other one doing the interface by hand (as i encountered problems with SWIG). with the one done by hand i ran into a problem.. as there are just too many classes and especially structures to do do classes for by hand, and i think there was also a problem with sub-structures or something. and i totally forgot the problem with the SWIG version, maybe was the same one.
but please zenzike, tell me something about you. would you be willing to overtake the project? as stated in the past, i am only good in java, and have theoretical knowledge about C and C++ and not much practical one.. i do not feel at home with this world.
are you better off there? if i find motivation again, we could also do it together maybe.. somehow, if you think it would work, if you want.
the status...
i have very bad memory.. if i find a little motivation i will look into my source again shortly, and figure out the status

the source is only available here.. form me.
do you want it? its nothing pretty though, but as i saw, you use netbeans too, so.. you might get around with it without too much problems.
i remember i splitted the project into 2..
one using SWIG and the other one doing the interface by hand (as i encountered problems with SWIG). with the one done by hand i ran into a problem.. as there are just too many classes and especially structures to do do classes for by hand, and i think there was also a problem with sub-structures or something. and i totally forgot the problem with the SWIG version, maybe was the same one.
but please zenzike, tell me something about you. would you be willing to overtake the project? as stated in the past, i am only good in java, and have theoretical knowledge about C and C++ and not much practical one.. i do not feel at home with this world.
are you better off there? if i find motivation again, we could also do it together maybe.. somehow, if you think it would work, if you want.
Re: Java AI Interface for Spring
I would be interested in looking at the code, but probably shouldn't take up the role of being the next maintainer of this yet - I have only just joined the community, and still sussing things out myself, I have no idea if I'll be staying long - for now it's just a passing interest.
As for my skills, I'm pretty good with both java and cpp, and I don't mind working in either, I have actually started bashing up an AI in cpp, though for now it's only a "Hello World!" AI, with nothing to offer.
Working together on this Java interface sounds fun. Let's have a look at the code first, and see where we go from there.
As for my skills, I'm pretty good with both java and cpp, and I don't mind working in either, I have actually started bashing up an AI in cpp, though for now it's only a "Hello World!" AI, with nothing to offer.
Working together on this Java interface sounds fun. Let's have a look at the code first, and see where we go from there.
Re: Java AI Interface for Spring
ahh i see.. good.. thanks 
am compiling the latest svn spring right now, and then may see how much is working.. if it compiles and such
will tell you here again if i can report something, and after that i'll may send you the code by private message if possible, or here.

am compiling the latest svn spring right now, and then may see how much is working.. if it compiles and such

will tell you here again if i can report something, and after that i'll may send you the code by private message if possible, or here.
little report
aehm.. well...
its kind of working, basicly.. the basic, simple things.
its possible for example, to receive and send chat messages from withing java now, and get the frame updates and find out the number of the frame...
but...
everything that is not a String or a basic data type like int, float, char*, bool (and a few others maybe) is handled with a SWIGTYPE_p_SoMeThInG thing.
this means... when requesting the start position from java through the aiCallback, i get a SWIGTYPE_p_float3 in Java, which has no more methods then an Object. i then have to write special functions in C or C++ for float3, which return basic types (the 3 values in this example)
i can then call these functions through java again. so i would call 3 functions through JNI which return 3 floats then.
there may be some way to do it with SWIG, integrate the code there so it could be integrated automaticaly, but i think it still had to be written by hand.
besides beeing unperformant, this may still work.. but when we talk about all the structs and sub structs, like Command, CommandQueue, FeautureSoMeThInG, UnitBlaBla, ...
any ideas how to get around this, how to make it easyer?
cant we get rid of all the structures pls?
its kind of working, basicly.. the basic, simple things.
its possible for example, to receive and send chat messages from withing java now, and get the frame updates and find out the number of the frame...
but...
everything that is not a String or a basic data type like int, float, char*, bool (and a few others maybe) is handled with a SWIGTYPE_p_SoMeThInG thing.
this means... when requesting the start position from java through the aiCallback, i get a SWIGTYPE_p_float3 in Java, which has no more methods then an Object. i then have to write special functions in C or C++ for float3, which return basic types (the 3 values in this example)
i can then call these functions through java again. so i would call 3 functions through JNI which return 3 floats then.
there may be some way to do it with SWIG, integrate the code there so it could be integrated automaticaly, but i think it still had to be written by hand.
besides beeing unperformant, this may still work.. but when we talk about all the structs and sub structs, like Command, CommandQueue, FeautureSoMeThInG, UnitBlaBla, ...
any ideas how to get around this, how to make it easyer?
cant we get rid of all the structures pls?

ABIC
hmm...
may the ABIC interface be something for me?
http://spring.clan-sy.com/wiki/AI:ABIC
the GlobalAICallback i would get would still be of the same type, and i still would have to access all the structures and stuff the same way?
may the ABIC interface be something for me?
http://spring.clan-sy.com/wiki/AI:ABIC
the GlobalAICallback i would get would still be of the same type, and i still would have to access all the structures and stuff the same way?
Re: Java AI Interface for Spring
Yes, that's how I understand it. I'm not sure of the completion status of ABIC though.
Re: Java AI Interface for Spring
No one is maintaining it and hence it's probably outdated. Heck, I don't even know how to update it etc.
Re: Java AI Interface for Spring
k
thanks
... dont worry tobi, it seems as if i wont need it anyway.
i went on trying with the normal AI interface.. and i got further.
i have a few questions to the devs:
the size of the
in CMetalMap from Map/MetalMap.h is sizex*sizez ?
how can i determine the size of the following things in the IAICallback:
inside. is the size of those 3 or 4 or. what else?
i guess some of those things are unimportant, but some, i guess, are not. i have to know them as SWIG can not find out these values automatically, so i have to tell it how to get them.
i also had to add a no-arg constructor to the UnitDef::UnitDefWeapon struct, as without it, SWIG can not generate wrapper functions for a vector<UnitDef::UnitDefWeapon>.
would it be ok to include this no-arg constructor somewhen in the real code? (id write and submit a patch then)
ah btw zenzike:
i obviously changed some things in the code again
the linux version now works aswell, and both the swig version dont cause sync errors anymore either.
so.. tell me when/if you plan to look at it, and i'll send you the latest source right before that.
i still have a problem with 4 functions in the whole interface, the rest.. at least compiles fine.
if i get to the point where everything compiles fine.. what do you suggest?
i surely will test some functions... but i dont even know from each one how it should work...
so is someone willing to test some aswell?
when should i give the code to one of the devs?
how will we handle the dependencies? (mainly SWIG)

... dont worry tobi, it seems as if i wont need it anyway.
i went on trying with the normal AI interface.. and i got further.
i have a few questions to the devs:
the size of the
Code: Select all
unsigned char *metalMap;
how can i determine the size of the following things in the IAICallback:
- HeightMap
- JammerMap
- RadarMap
- LosMap
- SlopeMap
Code: Select all
unsigned char* color;
i guess some of those things are unimportant, but some, i guess, are not. i have to know them as SWIG can not find out these values automatically, so i have to tell it how to get them.
i also had to add a no-arg constructor to the UnitDef::UnitDefWeapon struct, as without it, SWIG can not generate wrapper functions for a vector<UnitDef::UnitDefWeapon>.
would it be ok to include this no-arg constructor somewhen in the real code? (id write and submit a patch then)
ah btw zenzike:
i obviously changed some things in the code again

the linux version now works aswell, and both the swig version dont cause sync errors anymore either.
so.. tell me when/if you plan to look at it, and i'll send you the latest source right before that.
i still have a problem with 4 functions in the whole interface, the rest.. at least compiles fine.
if i get to the point where everything compiles fine.. what do you suggest?
i surely will test some functions... but i dont even know from each one how it should work...
so is someone willing to test some aswell?
when should i give the code to one of the devs?
how will we handle the dependencies? (mainly SWIG)
Re: Java AI Interface for Spring
Checked the comments?hoijui wrote:kthanks
... dont worry tobi, it seems as if i wont need it anyway.
i went on trying with the normal AI interface.. and i got further.
i have a few questions to the devs:
the size of thein CMetalMap from Map/MetalMap.h is sizex*sizez ?Code: Select all
unsigned char *metalMap;
how can i determine the size of the following things in the IAICallback:
- HeightMap
- JammerMap
- RadarMap
- LosMap
- SlopeMap
Code: Select all
// the following functions are used to get information about the map
// * do NOT modify or delete any of the pointers returned
// * the maps are stored from top left and each data position is 8*8 in size
// * to get info about a position (x, y) look at location (int(y / 8)) * GetMapWidth() + (int(x / 8))
// * note that some of the type-maps are stored in a lower resolution than this
virtual int GetMapWidth() = 0;
virtual int GetMapHeight() = 0;
virtual const float* GetHeightMap() = 0; // this is the height for the center of the squares, this differs slightly from the drawn map since it uses the height at the corners
virtual float GetMinHeight() = 0; // readmap->minHeight
virtual float GetMaxHeight() = 0; // readmap->maxHeight
virtual const float* GetSlopeMap() = 0; // slopemap, half the resolution of the standard map (values are 1
// minus the y-component of the (average) facenormal of the square)
virtual const unsigned short* GetLosMap() = 0; // a square with value zero means you don't have LOS coverage on it, half the resolution of the standard map
virtual const unsigned short* GetRadarMap() = 0; // a square with value zero means you don't have radar coverage on it, 1/8 the resolution of the standard map
virtual const unsigned short* GetJammerMap() = 0; // a square with value zero means you don't have radar jamming coverage on it, 1/8 the resolution of the standard map
virtual const unsigned char* GetMetalMap() = 0; // this map shows the metal density on the map, half the resolution of the standard map
Yes, size 3 bytes (or maybe 4 but the alpha isn't used anyway AFAICS): red, green, blue.in IAICallback there are two structs structs: PointMarker and LineMarker. Each one of them has ainside. is the size of those 3 or 4 or. what else?Code: Select all
unsigned char* color;
i guess some of those things are unimportant, but some, i guess, are not. i have to know them as SWIG can not find out these values automatically, so i have to tell it how to get them.
I did this alreadyi also had to add a no-arg constructor to the UnitDef::UnitDefWeapon struct, as without it, SWIG can not generate wrapper functions for a vector<UnitDef::UnitDefWeapon>.
would it be ok to include this no-arg constructor somewhen in the real code? (id write and submit a patch then)

Compile time only right? Does it require linking to a (SWIG) library? If not it's really no problem, AFAIK SWIG is available on all platforms Spring is available.how will we handle the dependencies? (mainly SWIG)
Re: Java AI Interface for Spring
..hmmm :D sorry
no did not check the comments.
really nice that they are there!
thanks again for your help today!
yes, SWIG is needed during compile time only. i just though... everyone that wanted to compile spring as a whole would have to install SWIG then, just because of JAI.
no did not check the comments.
really nice that they are there!
thanks again for your help today!
yes, SWIG is needed during compile time only. i just though... everyone that wanted to compile spring as a whole would have to install SWIG then, just because of JAI.
- BrainDamage
- Lobby Developer
- Posts: 1164
- Joined: 25 Sep 2006, 13:56
Re: Java AI Interface for Spring
the real problem is not the swig lib which is quite small (3-5 MB), but the java sdk which is 200+ MB (more than all other deps togheter) and only needed if you plan to use a java based lobby, since the buildsystem doesn't support it as optional dep you have to comment the code that uses it, i dunno how to patch the buildsystem to add a flag to make it optional or i'd have done long ago
Last edited by BrainDamage on 01 May 2008, 00:50, edited 1 time in total.
Re: Java AI Interface for Spring
Maybe I'll just copy the 2 headers spring needs into the repo sometime 

help with AWK
I need to fix some things in the SWIG generated code, most i did already, but there is one missing. I think it has to be done with awk, as its a multi line thing, for which sed seems to be bad. I have to replace some values in functions, according to the function name. so basically i have the SWIG generated code file (simplifyed):
and a substitution map somehow like this (doesnt have ot be in this form, as i have to write it manually anyway):
The first appearance of Value that comes after Name_1 has to be changed to read Value_x and so forth. It could be done with one awk invocation for each substitution, that would not be a problem, as it are only about 8 of them. The thing is, i have newer used awk (except copy and paste). Is there anyone of you good with it? I do not want to learn awk just for that :/
It would not have to be perfect nor tested, i can do the refinement myself, just would be grateful if one of you could do it quick, if not, i will post it in a unix forum.
thanks
Code: Select all
blabla Name_2 blabla {
aaaa
bbbb
cccc
blabla Value blabla
dddd
}
blabla Name_1 blabla {
tttt
wwww
ssss
cccc
blabla Value blabla
ssss
blabla Name_3 blabla {
xxxx
qqqq
blabla Value blabla
llll
}
Code: Select all
Name_1 Value_x
Name_2 Value_z
Name_3 Value_y
It would not have to be perfect nor tested, i can do the refinement myself, just would be grateful if one of you could do it quick, if not, i will post it in a unix forum.
thanks

Re: Java AI Interface for Spring
My awk isn't good enough for that 

Re: Java AI Interface for Spring

i posted it on google groups, and got an answer really fast, if you´re interested, its here:
http://groups.google.ch/group/comp.lang ... 7a2504a606
will use it tomorow to fill in the fixed array sizes i asked for (which i missed were available in the comments)
Edit: changed url to url
Re: Java AI Interface for Spring
Hello...
i want to build in Krogothe´s MexSpot finder now. AF told me to get the one from KAIK or NTai. i looked in KAIK:
would i have to use SpotFinder, MetalMap? if so.. i saw that ThreatMap is used in those, and ThreatMap uses UnitTable, so i have to copy those two classes aswell? is it meant like that? am i allowed to do so Kloot?
wouldn´t that already contain lots of KAIK logic (which should not be, as this should be a neutral interface, and the logic should come from the implementations).
i want to build in Krogothe´s MexSpot finder now. AF told me to get the one from KAIK or NTai. i looked in KAIK:
would i have to use SpotFinder, MetalMap? if so.. i saw that ThreatMap is used in those, and ThreatMap uses UnitTable, so i have to copy those two classes aswell? is it meant like that? am i allowed to do so Kloot?
wouldn´t that already contain lots of KAIK logic (which should not be, as this should be a neutral interface, and the logic should come from the implementations).
Re: Java AI Interface for Spring
The metal algorithm class in NTai is self contained however it does not come with any logic for deciding which spots should be built on first ro for ugprading mexes unless you add in the wrapper class that sits around it. The wrapper class relies on NTai logic but it should be easy to remove dependency as most calls are of the form G->cb->stuff() where cb is a pointer to an IAICallback interface.
Re: Java AI Interface for Spring
hoijui: only CMetalMap::GetNearestMetalSpot() uses information
from the threatmap, but that function is not technically a part of
the algorithm so you can just leave it out.
from the threatmap, but that function is not technically a part of
the algorithm so you can just leave it out.
Re: Java AI Interface for Spring
Thanks you 2! 
i took it from KAIK. CMetalMap (as CAIMetalMap) and CSpotFinder are now available from Java; though not yet tested.
well...
i have now all the functionality built in, it seems to work, and passed some small tests already:
- functions in IGlobalAI get called
- in general the functions in the callback and cheat interfaces work
- i can give move commands
so what now?
who wants the code?
i have 2 makefiles, one for linux and one for windows, which both compile with mingw for windows.
(i could clean up a bit i guess)
how should we do it:
so there will be one JAI.dll only, and one or two jars for the Java part of the interface. then there will be one jar for each implementation as i think of it now...
so lets say we have two implementations:
JAI_impl_1.jar
JAI_impl_2.jar
and i want to set up a game with 4 AIs, one of impl_1 and two of impl_2 and an AAI.
how can i, as user, define which ones i want?
in the lobby i would add one AAI.dll and three JAI.dll´s
but which impls to use?
at the moment ther is a factory class in Java, which returns the Java equivalent of IGlobalAIs. its technically easy to load different impls, but how does the user specify them?
should we have a config file? the user could then specify an order in that file, eg:
JAI_impl_1
JAI_impl_2
JAI_impl_2
JAI_impl_1
JAI_impl_3
...
meaning the first JAI used by JAI.dll will be of impl_1 and the second and third of impl_2 and so on.
or we could change the code and the lobbies to accept options for the AIs, as there are Mod Options aswell.

i took it from KAIK. CMetalMap (as CAIMetalMap) and CSpotFinder are now available from Java; though not yet tested.
well...
i have now all the functionality built in, it seems to work, and passed some small tests already:
- functions in IGlobalAI get called
- in general the functions in the callback and cheat interfaces work
- i can give move commands
so what now?
who wants the code?
i have 2 makefiles, one for linux and one for windows, which both compile with mingw for windows.
(i could clean up a bit i guess)
how should we do it:
so there will be one JAI.dll only, and one or two jars for the Java part of the interface. then there will be one jar for each implementation as i think of it now...
so lets say we have two implementations:
JAI_impl_1.jar
JAI_impl_2.jar
and i want to set up a game with 4 AIs, one of impl_1 and two of impl_2 and an AAI.
how can i, as user, define which ones i want?
in the lobby i would add one AAI.dll and three JAI.dll´s
but which impls to use?
at the moment ther is a factory class in Java, which returns the Java equivalent of IGlobalAIs. its technically easy to load different impls, but how does the user specify them?
should we have a config file? the user could then specify an order in that file, eg:
JAI_impl_1
JAI_impl_2
JAI_impl_2
JAI_impl_1
JAI_impl_3
...
meaning the first JAI used by JAI.dll will be of impl_1 and the second and third of impl_2 and so on.
or we could change the code and the lobbies to accept options for the AIs, as there are Mod Options aswell.