Java AI Interface for Spring - Page 12

Java AI Interface for Spring

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

Moderators: hoijui, Moderators

User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

ARGGGG
i hate it!
its pretty sure me doing something wrong. its running worse and worse.
if you have a change, go back to the old version, as a fix for this one may not arrive soon.
3Px
Posts: 7
Joined: 15 Mar 2009, 20:11

Re: Java AI Interface for Spring

Post by 3Px »

Hi,
What is the current status of Java interface? It looks very promising and I was considering developing a small project with it but if there are serious bugs that crash it in any non-trivial case it wouldn't be possible to use.
I don't have any experience with C/C++ <-> Java bindings - do you have any recent documentation of this part of code? Maybe it would clear up a few things allowing me to contribute :)
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Java AI Interface for Spring

Post by imbaczek »

it works but there is some threading issue that causes crashes AFAIK.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

hehe :D
you know, in this project we consider something running, when it crashes just sometimes
no, just joking ;-)

yeah, documentation....
there is some, but it is scattered all around, i am afraid :/
there are some diagrams even. i will integrate them into the Wiki pages, maybe tomorrow, now too tired.
some info here
http://spring.clan-sy.com/wiki/AI
http://spring.clan-sy.com/wiki/AIs
more interesting is the second link, though very unpolished.
for more insight, have a look at the code from:
git://github.com/spring/spring.git
especially the following dirs:
rts/ExternalAI
rts/ExternalAI/Interface
AI/Interfaces/Java
AI/Skirmish/NullOOJavaAI

and come back here if you have questions.
the current problem with the Java interface is something related to JNI and threading, though i still have only relatively vague idea. if that is one of your strengths, then . please, contribute! :O
otherwise.. can not hurt either
3Px
Posts: 7
Joined: 15 Mar 2009, 20:11

Re: Java AI Interface for Spring

Post by 3Px »

Thanks for the reply. Right now I'm trying to run sample NullOOJavaAI but I have some problems - probably with my startup script. I tried to modify my previous script but I got errors like this:

Code: Select all

Player 3P connected with number 0 (client version 0.78+.2.1)
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid

Program received signal SIGABRT, Aborted.
Relevant part of the backtrace points to the setup code:

Code: Select all

(...)
#9  0xb7627766 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string () from /usr/lib/libstdc++.so.6
#10 0x0835c2f1 in CTeamHandler::LoadFromSetup ()
#11 0x08348605 in CGlobalSyncedStuff::LoadFromSetup ()
#12 0x080e77ed in CPreGame::GameDataReceived ()
#13 0x080e7f72 in CPreGame::UpdateClientNet ()
#14 0x080e839c in CPreGame::Update ()
#15 0x084c5f1d in SpringApp::Update ()
#16 0x084cb759 in SpringApp::Run ()
#17 0x084cd34c in Run ()
#18 0x084cd400 in main ()

It would be much easier to begin working with something that is known to be OK, so could someone provide a start script that uses new interface? I know that I could just read relevant initialization code but it's easier just to focus on the AI part for the moment :)
3Px
Posts: 7
Joined: 15 Mar 2009, 20:11

Re: Java AI Interface for Spring

Post by 3Px »

Finally I managed to get some working start script (is there any lobby client or similar tool available for linux that doesn't segfault all the time?). But now spring crashes when it tries to load the skirmish AI (it's already in-game).

Code: Select all

Player unnamed connected with number 0 (client version 0.78+.2.1)
Player unnamed finished loading and is now ingame
/home/phonso/spring-install/bin/spring: symbol lookup error: /home/phonso/spring-install/lib/spring/AI/Interfaces/Java/0.1/libAIInterface.so: undefined symbol: JNI_CreateJavaVM

Program exited with code 0177.
The crash is related to lazy symbol resolving - which is a feature/bug - library is loaded without problems even if symbols are missing. dlopen with RTLD_NOW fails and spring has an opportunity to handle this error nicely and in fact, it displays an error message:
Error while loading AI Interface Library from file "/home/phonso/spring-install/lib/spring/AI/Interfaces/Java/0.1/libAIInterface.so"
After clicking OK it crashes with

Code: Select all

spring: /usr/include/boost/thread/pthread/mutex.hpp:50: void boost::mutex::lock(): Assertion `!pthread_mutex_lock(&m)' failed.

Program received signal SIGABRT, Aborted.
But it seems to be completely unrelated matter ;)

I think that the reason for this is bad linkage of Java/0.1/libAIInterface.so - it misses one of required libraries but I don't know which one - yet :)
3Px
Posts: 7
Joined: 15 Mar 2009, 20:11

Re: Java AI Interface for Spring

Post by 3Px »

Another reply to myself :) Indeed, library was missing, after adding

Code: Select all

-ljvm
in gcc command line, no more problems with this shared library (it would be easier if I knew anything about JNI).

Unfortunately now I get yet another crash

Code: Select all

Server started on port 8452
Player unnamed connected with number 0 (client version 0.78+.2.1)
Player unnamed finished loading and is now ingame
Checked JNI functions are being used to validate JNI usage
[Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
[Registering JNI native method java.lang.Object.hashCode]
[Registering JNI native method java.lang.Object.wait]
[Registering JNI native method java.lang.Object.notify]
(...)
[Dynamic-linking native method com.sun.jna.Pointer._getPointer ... JNI]
[Dynamic-linking native method java.lang.reflect.Proxy.defineClass0 ... JNI]
[Dynamic-linking native method com.sun.jna.Memory.free ... JNI]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb63526c0 (LWP 21848)]
0xa5a791e4 in ?? ()
(gdb) bt
#0  0xa5a791e4 in ?? ()
#1  0x9daac520 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
This output isn't very helpful :) I don't even know if it's AI's or mod's fault. Other logs - maybe you can get more information from them then me:
interface-log.txt
jvm-log.xml
infolog.txt

I'll appreciate any hints where should I start looking now :)

btw.
One final thing - information in Documentation/SpringStartScript.txt is incorrect:

Code: Select all

Version=0.1;   // [optional] version of this Skirmish AI
It is not optional - omitting it was the cause of my previous problem:

Code: Select all

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Java AI Interface for Spring

Post by BrainDamage »

3Px wrote:Finally I managed to get some working start script (is there any lobby client or similar tool available for linux that doesn't segfault all the time?)
springlobby doesn't work for you?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

3Px wrote: btw.
One final thing - information in Documentation/SpringStartScript.txt is incorrect:

Code: Select all

Version=0.1;   // [optional] version of this Skirmish AI
It is not optional - omitting it was the cause of my previous problem:

Code: Select all

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid
Thank you!
it is on my todo list now, but it will have to wait until the Java Interface is running again.

about your current problem, see the PM i sent you, and look for me in the lobby.
3Px
Posts: 7
Joined: 15 Mar 2009, 20:11

Re: Java AI Interface for Spring

Post by 3Px »

Brain Damage wrote:springlobby doesn't work for you?
I tried it today and it "works" but I get segfaults while performing basic operation (trying to start a single player game) - I had to create some magic cache files by hand to generate a startup script without crashing.

And I prefer starting spring from console using a pre-made static start script - it's much faster (just 1 short command and it starts in debugger).
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

main package name changed

Post by hoijui »

the main namespace/package name of the Java part of the interface changed form

Code: Select all

com.clan_sy.spring.ai
to

Code: Select all

com.springrts.ai
as springrts.com this is now the new main URL of Spring.
User avatar
LoidThanead
Posts: 58
Joined: 27 Feb 2008, 16:16

Re: Java AI Interface for Spring

Post by LoidThanead »

(Pst! You might want to update the appropriate wiki pages that still use the old package name. I fixed the tutorial on creating a Java AI, but I don't know if there are any other places where the old name still remains.)
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

thanks :-)
i changed it in one place (Java AI Interface) in hte wiki now, but if you see it in other places, please fix it.
cranphin
Posts: 136
Joined: 13 Jun 2005, 16:37

Re: Java AI Interface for Spring

Post by cranphin »

Hi!

Is the 'Null Object Oriented Java AI ' still being worked on ? :)

I found a bug XD

In UnitDef.java:

Code: Select all

	float _buffer_getWindResourceGenerator;
	boolean _buffer_isInitialized_getWindResourceGenerator = false;
	public float getWindResourceGenerator(Resource c_resourceId) {
		float _ret = _buffer_getWindResourceGenerator;
		if (!_buffer_isInitialized_getWindResourceGenerator) {
			_ret = ooClb.getInnerCallback().Clb_UnitDef_0REF1Resource2resourceId0getWindResourceGenerator(ooClb.getTeamId(), unitDefId, c_resourceId.getResourceId());
			_buffer_getWindResourceGenerator = _ret;
			_buffer_isInitialized_getWindResourceGenerator = true;
		}
		return _ret;
	}
The

Code: Select all

_buffer_getWindResourceGenerator
seems to be some kind of cache thing, am I right ?

Almost all getters in UnitDef take no argument, so they can be trivially cached.
But resource related getters may return a different result depending on the resource passed as argument, so the 'caching' is faulty, it may return the wrong value :)
I noticed when I wanted to print all the resource generating buildings, and they all cost/produced/etc. the same amount of metal as energy XD

Hope this can be fixed :)
Cheers!
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

a fast fix would be to disable caching compleetly (-> removing 3 lines from an AWK script).
but maybe i can add something like:

Code: Select all

if (numAdditionalIndexVars > 0) {
   caching = false;
}
anyway.. it is a bug, and thank you for reporting! :-)
will fix it.
cranphin
Posts: 136
Joined: 13 Jun 2005, 16:37

Re: Java AI Interface for Spring

Post by cranphin »

hoijui wrote:a fast fix would be to disable caching compleetly (-> removing 3 lines from an AWK script).
but maybe i can add something like:

Code: Select all

if (numAdditionalIndexVars > 0) {
   caching = false;
}
anyway.. it is a bug, and thank you for reporting! :-)
will fix it.

I did a quick fix myself just by not setting the cached value to true XD
I think it's good to stick with the caching system, but for these values you want to cache against the resource ID I think :)

MAyby ^_^

Keep up the good work! :)
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

a note for Java AI devs:
for your CMake build scripts (CMakeLists.txt), make sure to take this into account:
CLASSPATH_AIINTERFACE was renamed to CLASSPATH_Java_AIINTERFACE
cranphin
Posts: 136
Joined: 13 Jun 2005, 16:37

Re: Java AI Interface for Spring

Post by cranphin »

Hmm, it's tricky ^_^
How do you send commands ? :)

A simple example, just how to send a move and a stop command to the commander if you have a Unit object? :)


Btw. people have claimed there's some actualy working AI's (or AI's being built) based on this interface, but I can't find them, would love some example code ^_^
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

Go through the world with an open soul, and you will see.

http://springrts.com/wiki/AI:Development:Lang:Java
User avatar
LoidThanead
Posts: 58
Joined: 27 Feb 2008, 16:16

Re: Java AI Interface for Spring

Post by LoidThanead »

Shameless plug: you may want to have a look at http://springrts.com/wiki/AIWrapper:ModularAI, which makes it even easier to handle units...
Post Reply

Return to “AI”