Java AI Interface for Spring
Moderators: hoijui, Moderators
Re: Java AI Interface for Spring
you have a mac??
hmm ok.. i think you are the first one testing al this under mac, no wonder you run into problems. also no wonder you do not have libjvm.so then.
well... as i dont have a mac, i ask you to fix things and make it running if you can, and send diffs or patches or instructions of some sort to me, so i can include them in the code.
hmm ok.. i think you are the first one testing al this under mac, no wonder you run into problems. also no wonder you do not have libjvm.so then.
well... as i dont have a mac, i ask you to fix things and make it running if you can, and send diffs or patches or instructions of some sort to me, so i can include them in the code.
- LoidThanead
- Posts: 58
- Joined: 27 Feb 2008, 16:16
Re: Java AI Interface for Spring
A couple of preliminary comments on the callback so far:
Maybe it would be convenient to move getResources() from the callback itself to the Economy class? That way everything regarding resources is conveniently packaged together.
Some of the method names don't follow the Java naming convention. All the units that deal with units are named EnemyUnits(), NeutralUnits() etc, instead of getEnemyUnits() and such.
UnitDef has a lot of methods like 'isCanAssist().' Looks like autogenerated getters for a lot of boolean fields. :)
I can't seem to find a method that will let me get a unit by its ID. Or any way to get a collection of the AI's own units. Or does FriendlyUnits() not include allied units?
In the C++ interface I remember a method callback->getUnit(int id). Am I overlooking something?
As a cosmetic change, you might consider using the return type List rather than ArrayList, i.e. List<UnitDef> getUnitDefs(). It's a more general interface.
I'm going to have to do some experimenting to discover the exact uses of some methods. I'll be sure to document my findings for future generations.
To onezeno: I await and will gladly answer any 'newbish questions.' :)
Maybe it would be convenient to move getResources() from the callback itself to the Economy class? That way everything regarding resources is conveniently packaged together.
Some of the method names don't follow the Java naming convention. All the units that deal with units are named EnemyUnits(), NeutralUnits() etc, instead of getEnemyUnits() and such.
UnitDef has a lot of methods like 'isCanAssist().' Looks like autogenerated getters for a lot of boolean fields. :)
I can't seem to find a method that will let me get a unit by its ID. Or any way to get a collection of the AI's own units. Or does FriendlyUnits() not include allied units?
In the C++ interface I remember a method callback->getUnit(int id). Am I overlooking something?
As a cosmetic change, you might consider using the return type List rather than ArrayList, i.e. List<UnitDef> getUnitDefs(). It's a more general interface.
I'm going to have to do some experimenting to discover the exact uses of some methods. I'll be sure to document my findings for future generations.
To onezeno: I await and will gladly answer any 'newbish questions.' :)
Last edited by LoidThanead on 30 Dec 2008, 21:59, edited 2 times in total.
Re: Java AI Interface for Spring
does spring even compile on macs?
Re: Java AI Interface for Spring
I run Ubuntu not Mac. Sorry, I should have mentioned that somewhere. I still don't compile but my problem is definitely with FindJNI.cmake and is not with caiinterface. For some reason the value JAVA_JVM_LIBRARY is always being set to JVM_LIBRARY_LIBRARY-NOT FOUND even when I point it directly at (what I assume to be) my JVM library. The original code was looking for jvm, but I could only find a file called libjvm.so (Linux shared library). I already had to update the file once to find my jni.h so maybe a patch is needed for it? I will be checking on the cmake and ubuntu forums this weekend.
Re: Java AI Interface for Spring
i use ubuntu too, and it FindJNI works fine for me.
i asumed you are using ma cause the last piece of code you showed was wrapped in if (APPLE), so it can not make any difference for you, whatever you change there, if you use ubuntu (i guess).
if you search for library jvm, the filename that is searched for is libjvm.so, under linux. in windows it would be jvm.dll eg.
it will NOT work if you search for libjvm.so.
as much as i know, you only need JAVA_HOME exported in the console where you run cmake, and then everythign should work. others got the whole java stuff running as it is now under linux aswell already, so it should be something wrong with your setup.
maybe we can meet in the lobby. in #main eg. i am there quite often, just start a private chat with me there, and wait till i answer, before writing too much
)
i asumed you are using ma cause the last piece of code you showed was wrapped in if (APPLE), so it can not make any difference for you, whatever you change there, if you use ubuntu (i guess).
if you search for library jvm, the filename that is searched for is libjvm.so, under linux. in windows it would be jvm.dll eg.
it will NOT work if you search for libjvm.so.
as much as i know, you only need JAVA_HOME exported in the console where you run cmake, and then everythign should work. others got the whole java stuff running as it is now under linux aswell already, so it should be something wrong with your setup.
maybe we can meet in the lobby. in #main eg. i am there quite often, just start a private chat with me there, and wait till i answer, before writing too much

Re: Java AI Interface for Spring
LoidThanead
thank you for those tips
will have to see how i handle the isCanAssizt() stuff.
thanks for the tips.. that is exactly what i wished for
sounds all good to me, except:
the unability to get a unit by ID is intentional. The OO interface (which the callback you are looking at is a part of) is meant to be ID free. If you com einto a situation where you have to get a unit by ID, we should change something to let you not get into that situation.
thank you for those tips

will have to see how i handle the isCanAssizt() stuff.
thanks for the tips.. that is exactly what i wished for

sounds all good to me, except:
the unability to get a unit by ID is intentional. The OO interface (which the callback you are looking at is a part of) is meant to be ID free. If you com einto a situation where you have to get a unit by ID, we should change something to let you not get into that situation.
- LoidThanead
- Posts: 58
- Joined: 27 Feb 2008, 16:16
Re: Java AI Interface for Spring
I see... So the idea is that the AI keeps track of its own units through the unitFinished() and unitDestroyed() methods?
Re: Java AI Interface for Spring
ah yeah sorry, i forgot to answer this.
yes i think thtas the way it was done so far, but.. i agree it could be handy to have a callback for units of ones own team only.
and yes, getFriendlyUnits returns all ally team units aswell.
one more thing on the todo list.
yes i think thtas the way it was done so far, but.. i agree it could be handy to have a callback for units of ones own team only.
and yes, getFriendlyUnits returns all ally team units aswell.
one more thing on the todo list.
Re: Java AI Interface for Spring
two other things i forgot (sorry, had a bad wake-sleep-eat rythm these days -> even worse concentration then usually)
1. getResources is not under Economy because:
Resources are (logically) something natural. they are on the map, used and created by units, in features, and are summarized in the Economy.
The Economy is kind of a thing a team has, which deals with quantities of resources, but resources are not a part of the economy. of course, an economist would say that everything is part of the economy.. but i am not one
well.. i dont want to say it is perfect like this, but i think it is better this way then resources as a subpart of the economy.
2. if you find more things, just do a new post, and do not edit a previous one.. cuase i most likely will not see it then (this time, i just noticed by good luck)
1. getResources is not under Economy because:
Resources are (logically) something natural. they are on the map, used and created by units, in features, and are summarized in the Economy.
The Economy is kind of a thing a team has, which deals with quantities of resources, but resources are not a part of the economy. of course, an economist would say that everything is part of the economy.. but i am not one

well.. i dont want to say it is perfect like this, but i think it is better this way then resources as a subpart of the economy.
2. if you find more things, just do a new post, and do not edit a previous one.. cuase i most likely will not see it then (this time, i just noticed by good luck)
- LoidThanead
- Posts: 58
- Joined: 27 Feb 2008, 16:16
Re: Java AI Interface for Spring
I can see where you're coming from with the Economy class. I hadn't looked at it that way. It still feels a little off to me, but I think I'll come around to your way of thinking when I get to actually building units. (And having to think about their costs.)
As for editing, I thought I'd edited soon enough after the initial post for you not to have seen it yet. Guess I was wrong. I don't like double posting, but it seems to be the better option here.
One more thing I noticed was that UnitDef.getBuildOptions() returns ID's of unitDefs, as far as I can see. If you say the OO interface should be completely ID free, maybe it would be more convenient to have it return the appropriate UnitDefs instead?
As for editing, I thought I'd edited soon enough after the initial post for you not to have seen it yet. Guess I was wrong. I don't like double posting, but it seems to be the better option here.
One more thing I noticed was that UnitDef.getBuildOptions() returns ID's of unitDefs, as far as I can see. If you say the OO interface should be completely ID free, maybe it would be more convenient to have it return the appropriate UnitDefs instead?
Re: Java AI Interface for Spring
absolutely, thanks for this oneLoidThanead wrote:One more thing I noticed was that UnitDef.getBuildOptions() returns ID's of unitDefs, as far as I can see. If you say the OO interface should be completely ID free, maybe it would be more convenient to have it return the appropriate UnitDefs instead?
- LoidThanead
- Posts: 58
- Joined: 27 Feb 2008, 16:16
Re: Java AI Interface for Spring
Also the AICommands take ID's as constructor arguments. For example, the different attack commands.
And depending on whether you want the interface to be completely ID free, it could be an idea to add a UnitGroup to use instead of a groupID?
And depending on whether you want the interface to be completely ID free, it could be an idea to add a UnitGroup to use instead of a groupID?
Re: Java AI Interface for Spring
the problem with your last two suggestions is:
the commands are logically part of the non-OO part of the Java interface, thtas why they have the ids. so they are used by the NullJavaAI aswell for example, and this AI shall not know about anything under .oo
but then again, nobody will use the non-OO part anyway, and i may just add an additional constructtor, so we have one with and one with .
i think i will do this. About the UnitGroup class... yeah... is a good question if it makes sense... i think i will wait with it. It would need no change in the C interface, and it does not affect big parts of the interface, so changing this later is no big thing.
the other suggestions you made, and i did not give an explanation why i won't do them, are done (see SVN changelog; yeah, the interface branch is not yet on GIT).
the commands are logically part of the non-OO part of the Java interface, thtas why they have the ids. so they are used by the NullJavaAI aswell for example, and this AI shall not know about anything under .oo
but then again, nobody will use the non-OO part anyway, and i may just add an additional constructtor, so we have one with
Code: Select all
(Unit unit, ...
Code: Select all
(int unitId, ...
i think i will do this. About the UnitGroup class... yeah... is a good question if it makes sense... i think i will wait with it. It would need no change in the C interface, and it does not affect big parts of the interface, so changing this later is no big thing.
the other suggestions you made, and i did not give an explanation why i won't do them, are done (see SVN changelog; yeah, the interface branch is not yet on GIT).
Re: Java AI Interface for Spring
i did an other commit. now commands have more OO like constructors additionally. i also added an enum AICommand.Option, which is now used in the above mentioned constructors aswell. i do not know if the way i use it is optimal, if you know a better way (more simple prefferably), communicate it please.
Re: Java AI Interface for Spring
two new things in latest SVN:
1. hirarchical classpath:
The Java AI Interface related classes and libraries are loaded with the system class-loader (default). Every skirmish AI has its private ClassLoader, which has the system class-loader as parent, and which is responsible for loading the AI code in ai.jar and its libraries under jlib/. This makes it possible to use different versions of the same AI in a single game, even if they use identical fully qualified class names, and it allows AIs using different versions of a common library to coexist in a game.
2. copying documentation
doc comments like this one:
are now copied from the C AI interface to the Java interface.
they are taken from the following files under rts/ExternalAI/Interface:
- SAICallback.h (little documentation so far)
- AISEvents.h (fully documented)
- AISCommands.h (little documentation so far)
other interfaces may do the same.
1. hirarchical classpath:
The Java AI Interface related classes and libraries are loaded with the system class-loader (default). Every skirmish AI has its private ClassLoader, which has the system class-loader as parent, and which is responsible for loading the AI code in ai.jar and its libraries under jlib/. This makes it possible to use different versions of the same AI in a single game, even if they use identical fully qualified class names, and it allows AIs using different versions of a common library to coexist in a game.
2. copying documentation
doc comments like this one:
Code: Select all
/**
* This class does X.
*/
class X {
...
they are taken from the following files under rts/ExternalAI/Interface:
- SAICallback.h (little documentation so far)
- AISEvents.h (fully documented)
- AISCommands.h (little documentation so far)
other interfaces may do the same.
Re: Java AI Interface for Spring
Got error (see attached).
What am I doing wrong?
P.S. Could you tell me if it's possible to use SWIG to generate c# interface as I prefer dotNet over Java? Or may be it's already done somehow?
Thanks!
What am I doing wrong?
P.S. Could you tell me if it's possible to use SWIG to generate c# interface as I prefer dotNet over Java? Or may be it's already done somehow?
Thanks!
- Attachments
-
- error_spring.JPG
- (103.67 KiB) Downloaded 24 times
Re: Java AI Interface for Spring
A Mono interface is in the workings. If you are not god ad C and C++, i recommend you not to try to write an interface yourself. SWIG is only of little help, as you had to adjust a LOT by hand (i tried it with SWIG first -> not nice).
about the error:
does not help anything, this message.
you could try to look at the log files:
infolog.txt
AI/Interfaces/Java/0.1/log.txt
about the error:
does not help anything, this message.
you could try to look at the log files:
infolog.txt
AI/Interfaces/Java/0.1/log.txt
Re: Java AI Interface for Spring
Here they are. Nothing suspicious, AFAIK.hoijui wrote: ....
you could try to look at the log files:
infolog.txt
AI/Interfaces/Java/0.1/log.txt
- Attachments
-
- log.txt
- (1.63 KiB) Downloaded 127 times
-
- infolog.txt
- (3.9 KiB) Downloaded 123 times
Re: Java AI Interface for Spring
hmm true... does not help either :/
maybe give some details of your system:
- JDK/JRE version you use
- Win32/Win64?
- WinXP/Vista?
other things that could be usefull.. (nothing flying through my mind right now)
maybe give some details of your system:
- JDK/JRE version you use
- Win32/Win64?
- WinXP/Vista?
other things that could be usefull.. (nothing flying through my mind right now)
Re: Java AI Interface for Spring
Firstly it wasn't work because I had no jvm.dll in %PATH% var. After I added C:\Program Files\Java\jdk1.6.0_11\jre\bin and C:\Program Files\Java\jdk1.6.0_11\jre\bin\client to PATH, it started to load with the error I've posted before.hoijui wrote:hmm true... does not help either :/
maybe give some details of your system:
- JDK/JRE version you use
- Win32/Win64?
- WinXP/Vista?
other things that could be usefull.. (nothing flying through my mind right now)
To answer your question:
- JDK\JRE 1.6.11. Win32,XP.
And another point. In log.txt there are several records like this "AI/Skirmish\NullOOJavaAI\0.1\ai.jar". I see slashes and backslashes mixed. Can it be the source of error (since It states something about IO)?
Could you give me some hints on how to debug ai.class. Maybe I can see some errors there. Another side there debug might be enabled is the spring itself, but I'm too lazy to compile whole spring (as I remember it is painful to compile spring in MSDev2008).