Page 1 of 2

Need help - java AI

Posted: 15 Feb 2010, 16:37
by zeross
Hi guys.

I'm new here so i'll ask some noobs questions ^^

i'm starting to create a java AI and following this tuto : http://springrts.com/wiki/AI:Development:Lang:Java

i've done what they said up to "Test your AI " but when i add a bot with springlobby my AI dosen't appear. Instead i got a "NullOOJavaAI 0.1 (2)" and the className is the same as NullOOJavaAi.

I checked my info file and rechecked everything but can't find why it dosen't work.


Here is my AIInfo.lua

Code: Select all

--
--  Info Definition Table format
--
--
--  These keywords must be lowercase for LuaParser to read them.
--
--  key:      user defined or one of the SKIRMISH_AI_PROPERTY_* defines in
--            SSkirmishAILibrary.h
--  value:    the value of the property
--  desc:     the description (could be used as a tooltip)
--
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local infos = {
	{
		key    = 'shortName',
		value  = 'diplomatie',
		desc   = 'machine name',
	},
	{
		key    = 'version',
		value  = '0.1', -- AI version - !This comment is used for parsing!
	},
	{
		key    = 'name',
		value  = 'Civilisation diplomatique.',
		desc   = 'display name',
	},
	{
		key    = 'loadSupported',
		value  = 'no',
		desc   = 'whether this AI supports loading or not.',
	},
	{
		key    = 'interfaceShortName',
		value  = 'Java', -- AI Interface name - !This comment is used for parsing!
		desc   = 'java interface',
	},
	{
		key    = 'interfaceVersion',
		value  = '0.1', -- AI Interface version - !This comment is used for parsing!
		desc   = 'required interface version',
	},
}

return infos

Then i tried to change the name of the other AI i have in my folder (AAI,KAIK,E323AI etc..) but even if i edit their info files to change their names or wathever i just don't update on my springlobby.

so i thought my springlobby have saved the AI info elsewhere and i just keep editing for nothing ? where can i actualise the AI and make springlobby acknowledge my AI ?

(my springlobby version is 0.63 msw and i'm running on windows 7)

Thanks for your help.

Re: Need help - java AI

Posted: 15 Feb 2010, 16:41
by hoijui
welcome! :-)

this info is not getting cached.
could it be that you changed only the AIInfo.lua file in your source, and the one in your spring installation still has the old info file?

Re: Need help - java AI

Posted: 15 Feb 2010, 17:02
by zeross
Thanks for your fast answer =)

Hum... solved -_-

i was editing the right files but...
I was going to upload my "Diplomatie" folder to show you exactly what i was doing. So i put my files in a .rar and moved it to desktop to upload it. then i wanted to check if everything was ok so i extracted it.
Then i've seen that all my files was ok but the content of my "AIInfo.lua" was the same as NullOOJavaAI. i thought "this is weird because i just ziped and unziped my files and i got another one..."
i've done it again to check and the same thing happen.


then i took the unziped file, re-edited it to fit my AI, put it back on my AI folder, and now it work and i can see my AI in springlobby.


so i supose that was windows who have cached my files and the "zip/unzip" operation have show it.


so, i can see my AI and start it. Now must find out why it dosen't got any starting unit and die immediatly but gotta keep reading the tuto for that ^^

sorry for bothering you with a false problem. at least trying to upload my folder have show me the problem ^^

Re: Need help - java AI

Posted: 15 Feb 2010, 17:33
by hoijui
:-)
which version of spring are you using?
in case you use master spring, you have to follow this to get start units:
http://springrts.com/phpbb/viewtopic.ph ... 84#p411084

Re: Need help - java AI

Posted: 15 Feb 2010, 18:02
by zeross
Well i used another map (was Nuclear Winter V01 and now i use country-crossing V06) and now i have a commander for each bot.

i'm following the tuto right now, trying to build a solar plant, but it dosen't seem to get the order for now, gotta figure it out ^^


My versions are :

SpringLobby : 0.63 msw
Spring : 0.81.1.3
Maps: country-crossing V06
Mod : BA 7.11


Edit : got it. Was just giving the order on frame 0 and it seem that was too early. i've put it on frame 10 and it's good.
now i have the basis i should be able to learn faster =)
thanks for your quick answers =)

Re: Need help - java AI

Posted: 15 Feb 2010, 18:43
by hoijui
good :-)

the map should really not make a difference there, you shoudl get commanders everywhere.

have fun!

Re: Need help - java AI

Posted: 17 Feb 2010, 18:19
by zeross
Hi again. I'm back for some more questions :p

Is there any updated javadoc for javaInterface ?
i've found this page : http://abma.de/projects/agai/doc-ai-interface/

But it dosen't seem realy up to date since we can find things like :
http://abma.de/projects/agai/doc-ai-int ... Command%29

wich describe a 3 parameter method and descibe 5 parameter bellow.



Well my problem this time is that i try to give an attack or move order but engine keep telling me "Warning: AI for team 0 failed handling event with topic 3, error:2" that is not realy helpfull to know what is wrong ^^

My command is built like this :

Code: Select all

AICommand command = new MoveUnitAICommand(this.commander,-1,null, 10000, new AIFloat3(3200,200,100));
this.callback.getEngine().handleCommand(AICommandWrapper.COMMAND_TO_ID_ENGINE,-1, command);
Maybe my coordinate are false and the AI ignore the command ?
In game when i see "pos: 3200 200 elevation:100" wich are the x,y and z ? Some programer use z for the elevation but others use y so i don't realy know wich is used in spring.

is there some doc i missed somewhere that tell us all those infos ? i have not find anything like that on the website.



sorry for my noobs questions, and thanks for your answers =)

Re: Need help - java AI

Posted: 17 Feb 2010, 20:07
by hoijui
i dont get what you mean with the 5 parameter describe.

for the error you get, i guess that means an exception (or error) is thrown in your AI.
best thing to do, is using all events like this:

Code: Select all

@Override
public int update() {
   try {
      // all the stuff you want to do
      return 0;
   } catch (Throwable t) {
      .. do something with t here, eg. t.printStackTrace(); or write to a log file or whatever
      return -55;
   }
}
edit:
abmas javadoc is from spring master, i guess you are using spring release, but it should be practically equal.

edit2:
... ahhh now i got it, the 5 params:
the Java interface is auto generated from C source code. the C version of the function has 5 params. it would be too much hassle to convert javadoc too. also.. many things are not documented...
you know.. documenting is not one thing that people like to do, and as they work for free on spring, and just for fun.. there naturally is little code docu.

Re: Need help - java AI

Posted: 18 Feb 2010, 18:08
by zeross
Not having doc don't realy help to create AI ^^

even with a try/catch my logfile is empty (and its not my log method that is wrong cause with a valid command the log is created corectly, only when command fail there is no log).

Code: Select all

int res=-1;
try
{
	 res = this.callback.getEngine().handleCommand(AICommandWrapper.COMMAND_TO_ID_ENGINE,
		-1, command);
}
catch(Throwable t)
{
	 log.WriteLine("Resultat : "+res);
	log.WriteLine(t.toString());
}
and the game still tell me "command failed with topic: 3 error: 2" wich i don't know what it mean.

can you show me an exemple of a valid attack/move command please ? i must miss something somewhere and i'm sure it's something obvious but i can't see it ^^"

Re: Need help - java AI

Posted: 18 Feb 2010, 22:43
by hoijui
:P
its not the command that failed, its handling of the event that failed (as you wrote correctly in your first topic).
topic 3 is the update event, the 2 means a Throwable has been caught.
it not necessarily have to be thrown in your code in the update() method. t.printStackTrace() is called, so it you have to grab that, maybe pipe stderr and stdout to files.
i remember someone else having had the same problem.. but i forgot what ultimately was the problem :/

Re: Need help - java AI

Posted: 24 Mar 2010, 19:32
by zeross
Me again \o/

i've got pretty far now and things start to look good.
I need to know if a constructor (factory or builder) is actualy building something (to spread the work order on all my units and not on the first on of the list). is there a function to tell if a unit is currently doing something or not ?

i've tried unit.isActivated() but i got always "true" so i asume it's not this one.

Re: Need help - java AI

Posted: 24 Mar 2010, 20:32
by imbaczek
check the first command in the queue.

Re: Need help - java AI

Posted: 24 Mar 2010, 20:35
by LoidThanead
As far as I know there is no such function.

It's probably best to keep track of what commands you've given to each unit, then select one without orders to give new orders to.

Re: Need help - java AI

Posted: 25 Mar 2010, 08:58
by hoijui
try imbaczeks solution first.
if it works, it is better, because Spring allows for multiple controllers (Players & AIs) to control a single team. this sometimes makes sense, and it means you can not rely on units having (only) the commands you gave them, but they may also executing commands given by a user. There is a special event for this though, you may just temporarily ignore units that were given orders by a user, until they finished these orders (that is what other AIs do).

Re: Need help - java AI

Posted: 25 Mar 2010, 20:49
by zeross
It worked, thanks a lot :)


i can't do like others AI do, because i have some special conditions (doing this AI is part of a schoolwork) but with a personalised version of command queue it worked fine :)

Re: Need help - java AI

Posted: 28 Mar 2010, 14:17
by zeross
Another question :(

i'm doing the "what do we need" function. In this one i'm doing :

Code: Select all

float incomeEnergie = callback.getEconomy().getIncome(Ressources.energie);
float usageEnergie = callback.getEconomy().getUsage(Ressources.energie);
float storageEnergie = callback.getEconomy().getStorage(Ressources.energie);
float currentEnergie = callback.getEconomy().getCurrent(Ressources.energie);
And the same for Metal, but i always get :

income energie : 25.0
usage energie : 0.0
storage energie : 1020.0
current energie : 1020.0

and :

income Metal : 1.5
usage Metal : 0.0
storage Metal : 1020.0
current Metal : 1020.0


and never get the reals numbers.

Ressources.metal and Ressources.energie are get like this :

Code: Select all

 List<Resource> resources;
		 resources = aicallback.getResources();
	
		 for( Resource resource : resources ) 
		 {
			 if( resource.getName().toLowerCase().contains("metal"))
			 {
				 metal = resource;
			 }
			 if( resource.getName().toLowerCase().contains("energy"))
			 {
				 energie = resource;
			 }
		}
so i can't understand what i'm doing wrong ?

Re: Need help - java AI

Posted: 28 Mar 2010, 15:46
by hoijui
could it be these are the correct values (of the AI, eg. team 1) and you are building stuff with your commander (eg team 0) only?

Re: Need help - java AI

Posted: 28 Mar 2010, 16:20
by zeross
i'm building stuff with every builder i have (commander, constructor kbot etc..)


EDIT : got it, i was testing my AI vs my AI and those values where for the second AI. if i test my AI vs void or another AI it work fine.

Re: Need help - java AI

Posted: 30 Mar 2010, 13:43
by zeross
Project is over, the teachers was realy happy with our AI.

Thanks for the help, it saved me many times, and thanks to you i'll got a good mark on this one =)

i've told the teachers that your community was realy great and they should give more project on spring to the students the next years ;)

Re: Need help - java AI

Posted: 30 Mar 2010, 18:19
by hoijui
niiiice!! :D that is just what we need!

what does your AI do? i mean, could it be interesting for us as players or AI devs, or is it just useful in a special case scenario (eg. your class project)?

thanks for the good testament!
i am glad it worked out well for you.