Java AI Interface for Spring - Page 6

Java AI Interface for Spring

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

Moderators: hoijui, Moderators

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

Re: Java AI Interface for Spring

Post by hoijui »

roger that! thanks kloot :-)
dunnu if it will be today though, if not, tomorow.
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Java AI Interface for Spring

Post by BrainDamage »

Tobi wrote:lobby developers add *.jar to possible AI file extensions. (Put the JAI .jar files that represent the AIs in same dir as AI dlls then.)
added to SpringLobby
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

nice! :D
aehm..
i tested it with your changes kloot, and ... it does not yet work that way. it comes quite far.. but i think when it calls the Init method of the ai, there is a problem. so far it does not use the jar name, and just call the same method as before internally. i have JAI.dll in AI/Bot-libs and in AI/Bot-libs/JAI. when i set:

Code: Select all

		aidll=AI/Bot-libs/JAI.dll;
it works, but with:

Code: Select all

		aidll=AI/Bot-libs/JAI-impl-hoijui.jar;
it doeas not. its something i have to fix i think, but it could get nasty.. as the JVM error log file hotspot.log sais:

Code: Select all

[Dynamic-linking native method info.osrts.jai.generated.JAIJNI.swig_module_init ... JNI]
Java HotSpot(TM) Client VM warning: Floating point control word changed by native JNI code.
[Dynamic-linking native method info.osrts.jai.generated.JAIJNI.new_JGlobalAI ... JNI]
Java HotSpot(TM) Client VM warning: Floating point control word changed by native JNI code.
[Dynamic-linking native method info.osrts.jai.generated.JAIJNI.JGlobalAI_director_connect ... JNI]
Java HotSpot(TM) Client VM warning: Floating point control word changed by native JNI code.
FATAL ERROR in native method: Wrong object class or methodID passed to JNI call
so somehow a jobject or jmethodID reference i pass to the swig director is not valid any more(but only when using the new way)... looks ugly, as i dont know how i could get mor info on this, as its not me calling Init(...). but i will try first.. may will ask for your help later.

one thing:
even when using the new way, it sais in infolog.txt:

Code: Select all

AI/Bot-libs/JAI-impl-hoijui.jar has C++ interface
;-) will have to be changed too somewhen.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

woops!
i loaded the JAI.dll in AI/Bot-libs/ and the engine used the one at AI/Bot-libs/JAI/ :D
it now works.
i'll send the latest version again today.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Java AI Interface for Spring

Post by AF »

I assume you've also tested for when the full path to the jar is included and not just ai.jar?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

yes :D
... well.. i just delete the path part and use only the filename, so it works whether ther is a path or not, though, if the file would be in an other location then AI/Bot-libs, it would not work. should it?

am preparing for sending the current version now.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

mail with alpha 2 sent to Tobi, zenzike and AF. if someone else wants it, pm me your email.
synogen
Posts: 6
Joined: 03 Sep 2007, 12:45

Re: Java AI Interface for Spring

Post by synogen »

will there be a wiki entry for JAI to unify the information scattered around this thread? :roll:
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 sorry,
yeah... good idea, but i think so far.. as its still not integrated into spring...
but you can also talk to me on the lobby to ask.. may be easyer for you to get into it then searching through the whole thread.
what are you interested in anyway? understanding how it works or just how you could write your own implementation? cause the later one is easy.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

to those of you who have the code:
synogaehn already tried it (the already compiled/bin version). it worked, but only after setting the following env-vars:

windows:

Code: Select all

SET JAVA_HOME=P:\Programme\Java\jdk1.6.0_03
SET PATH=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%JAVA_HOME%\jre\bin\client;%PATH%
linux:

Code: Select all

export JAVA_HOME=/usr/jdk1.6.0_03
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$JAVA_HOME/jre/bin/client:$PATH
..well, thats on my systems.

i don't know if all the three parts are needed (will have to try out later) but after this it worked.


i am currently working on the logging, organizing it better, making it more simple, and putting better log messages in the code.
after that i may make the JVM debuggable, to see if it will be possible to debugg with spring and JAI running (this is, Java debugging).

i am hoping on more tester! ;-)
synogen
Posts: 6
Joined: 03 Sep 2007, 12:45

Re: Java AI Interface for Spring

Post by synogen »

hey hoijui,

i sent you an email with a proposal for a possible wiki entry, once you checked it we could put it in the wiki to have some organized place for information collection on this :wink:

edit: i just noticed the mail failed to deliver, seems the MSN email server blocked it for whatever reason :?: , i'll try and send it to you via MSN instead asap :P
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

.. Thanks :-)
the Wiki-Page is up now:
http://spring.clan-sy.com/wiki/AI:JAI
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

i got JAI (the native part) to compiling with scons. what it needs more then the other AIs, is:
for compiling:

Code: Select all

-DSTREFLOP_X87
for linking:

Code: Select all

-jvm
and it needs the appended file in the "mingwlibs/lib/" directory (likewise for other compilers i guess).
but obviously, the JVM.dll ends up in "AI/Bot-libs/" then, instead of "AI/Bot-libs/JAI/". and the compiling of the Java part (ending up in JAI.jar) is also not done by scons. how would i do that?
anywya i think i needs special treatment, as its an interface, not an AI, and it needs to compile Java...
any hints anyone?
Attachments
libjvm.dll.a.zip
linking stub (or something like this) for the Java virtual machine, needed for JNI calls: starting the JVM, calling methods, ...
(948 Bytes) Downloaded 70 times
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

well.. what do you think?
should JAI ever be integrated into spring?
if yes, how?
its relatively complicated, as it consists of:
- generating with SWIG (i saw that Upspring uses SWIG too how do they do it?)
- executing a shell/batch script to fix things SWIG can not generate correctly (should be working on mac also, with possibly small adjustments)
- compile native (least problem)
- compile java (needs JDK installed)
or should i generate native and Java code with swig, upload it to SVN, compile the jar and then scons only compiles the native part and copies JAI.dll and JAI.jar to the right place?
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Java AI Interface for Spring

Post by hughperkins »

Java AI? That sounds sweet! How far along is it? The interface I mean, so that I could write an AI in Java? Dont' suppose... any chance of like a two-minute tutorial guide somewhere saying how to get started, build a first solar panel, something like that?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java AI Interface for Spring

Post by hoijui »

hello hughperkins,
best bet for what you want is probably:
http://spring.clan-sy.com/wiki/AI:JAI
it's still alpha, so there are still big changes going on (mianly: classes getting added or removed and parameter types changing). The next alpha release (coming in one or 2 days i think) is aimed at making the whole interface Java like/friendly, so that none or quasi none native like stuff is used. this means using List<Float> where a std::vector<float> is used in native, using lower-case method names, wrapping integer constants into java enums, and changes like this:

Code: Select all

int GetUnitDefList(UnitDef** list);
UnitDef[] getUnitDefList();
also float3 is wrapped into a Java class, extending javax.vecmath.Vector3f, and things like this.

maybe after this release, it would be worth wile starting to write an AI in Java, as not too much should change anymore in the interface.

A Tutorial as you want it is not yet available, but there are 2 very basic test implementations coming with JAI, so you can look there.
one of them (tested with XTA) can build energy, metal extractors, factories and mobile units, and it attacks. so this may give you some good hints for a start.

btw...
i was able to debug my Java AI, but Synogen had problems with it, and as much as i know, did not yet get that working.
synogen
Posts: 6
Joined: 03 Sep 2007, 12:45

Re: Java AI Interface for Spring

Post by synogen »

hoijui wrote: btw...
i was able to debug my Java AI, but Synogen had problems with it, and as much as i know, did not yet get that working.
well, the only progress i have made is that by using the -Xnoagent option for the JVM spring doesn't crash anymore with JDWP enabled, and i can connect to it using my eclipse IDE. i still can't really debug though, since spring just stalls where it crashed before, and doesn't respond anymore.
the debugger says that the java thread containing JAI is running though, so there must be something else that blocks springs execution...
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Java AI Interface for Spring

Post by hughperkins »

This is looking great! You've been putting a lot of work into this.

Ummm, had a go at compiling but got a few errors:

Code: Select all

Fixing SWIG generated wrapper
-----------------------------
Removing long redeclaration...
'sed' is not recognized as an internal or external command,
operable program or batch file.
'mv' is not recognized as an internal or external command,
operable program or batch file.
Adding streflop call (before and) after every JNI call, to reset FPU state..
'gawk' is not recognized as an internal or external command,
operable program or batch file.
'mv' is not recognized as an internal or external command,
operable program or batch file.

Code: Select all

In file included from ./src/cpp/JAI.cpp:2:
./src/cpp/generated/JAI_wrap.cxx:139: error: redeclaration of C++ built-in type
`long'
In file included from ./src/cpp/JAI.cpp:2:
./src/cpp/generated/JAI_wrap.cxx:149:17: jni.h: No such file or directory
./src/cpp/generated/JAI_wrap.cxx:173: error: variable or field `SWIG_JavaThrowEx
ception' declared void
./src/cpp/generated/JAI_wrap.cxx:173: error: `JNIEnv' was not declared in this s
cope
./src/cpp/generated/JAI_wrap.cxx:173: error: `jenv' was not declared in this sco
pe
./src/cpp/generated/JAI_wrap.cxx:173: error: expected primary-expression before
"code"
./src/cpp/generated/JAI_wrap.cxx:173: error: expected primary-expression before
"const"
Tell me I dont have to install cygwin right? But maybe I need to download those gnu tools that have sed and so on?
Last edited by hughperkins on 26 May 2008, 02:44, edited 1 time in total.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Java AI Interface for Spring

Post by hughperkins »

Did the following:
* Downloaded gawk and sed from gnuwin32 http://gnuwin32.sourceforge.net/packages.html
* Edited fixSwigWrapper.bat as follows:
** changed "mv" to "move"
** changed the quotes in the sed commands from ' to "
* Edited makefile_win32:
** point JAVA_HOME to my jdk directory
** add "-I. \" to IFLAGS line in C++ vars section

Reran makefile, it gets a little further ;-) but now I get:

Code: Select all

g++: ../../../game/spring.a: No such file or directory
You're testing this on linux arent you? ;-)
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Java AI Interface for Spring

Post by hughperkins »

Played a little more:

* replacing "spring.a" with "spring.exe" gives lots of errors about symbols being redefined
* removing spring.a completely gives errors about undefined references to CIcon

Cant help thinking, might be easier just to include CIcon or something than figure out the linking with spring.exe, but anyway, it's starting to get closer to the hard bit I think? so I might just leave you to get back to me about how you're managing to get this building on Windows :-)
Post Reply

Return to “AI”