Java Tutorial

Java Tutorial

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

Moderators: hoijui, Moderators

Post Reply
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Java Tutorial

Post by msm8bball »

I read the basic tutorial for how to create a Java AI and I'm having trouble with it. Makes me feel stupid, but I guess we have to start somewhere.

I've taken a few courses in Java, so I feel like once I get started I should be able to teach myself the rest of this without.

Basically, I'm having trouble getting my IDE setup and the basic two classes configured correctly. If someone could create a step by step walkthrough for NetBeans or Eclipse (or any other free IDE) I'd really appreciate it. The current tutorial says to make two class files, but it'd help me if I could see what their source should look like, and to know if my IDE will treat anything as an error. I tried to check out like the NullOOJavaAI's source but mine never seemed to work as well.

I'd really appreciate someone setting me off in the right direction!
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Re: Java Tutorial

Post by Petah »

Ill make you a tutorial for Netbeans.
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Re: Java Tutorial

Post by Petah »

Here you go, its basic but it should work.
Attachments
Spring AI.pdf
(1.27 MiB) Downloaded 382 times
User avatar
Beherith
Moderator
Posts: 5044
Joined: 26 Oct 2007, 16:21

Re: Java Tutorial

Post by Beherith »

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

Re: Java Tutorial

Post by hoijui »

i added it here:
http://springrts.com/wiki/AI:Development:Lang:Java

so if we get too many stickies in the forum, we can un-sticky this thread.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Java Tutorial

Post by msm8bball »

Wow thanks!
I'll be sure to run through that tonight. This should hopefully be a good project to keep my Java skills sharp, and I played OTA back when I was like ten years old so this should be very interesting. I really appreciate it!
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Java Tutorial

Post by msm8bball »

Alright, I got it compiled, put the .jar in the right directory along with the lua files, and I start the game from the TASclient and each time it crashes. I've tested using both BA and CA, and two separate maps, but nothing works. It crashes right when the game is supposed to begin, which I'm guessing is the moment it loads the AI.

Any ideas?
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Java Tutorial

Post by msm8bball »

After playing around with a bunch of things, I found out that it would work if I renamed my jar from "MyAI.jar" to "SkirmishAI.jar". I figured that out by comparing it to your NullOOJavaAI that comes with Spring. You might want to update the pdf tutorial so that other people don't run into the same problem.
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Re: Java Tutorial

Post by Petah »

Oh yeah, I forgot about that. Ill fix it tonight.


Strange though that it worked for me with it called MyAI.jar
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Java Tutorial

Post by msm8bball »

Okay. I'm off to a decent start. Got my commander to build a solar plant :)

Now, are there any examples of source code I can look at for a decently working AI?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java Tutorial

Post by hoijui »

check out spring source code through git, and get the submodules (git submodule update --init). there is HughAI, which is Java, and all the other AIs, which will also serve you well with examples, as it works similar in all the different languages.
gajop
Moderator
Posts: 3048
Joined: 05 Aug 2009, 20:42

Re: Java Tutorial

Post by gajop »

Petah wrote:Oh yeah, I forgot about that. Ill fix it tonight.


Strange though that it worked for me with it called MyAI.jar
I had the same problem as msm8bball, and I was stupid enough not to look here for comments. In any case, it should be fixed, both in this thread and link originating from http://springrts.com/wiki/AI:Development:Lang:Java http://filebin.ca/yfawpr/NetbeansJavaSk ... torial.pdf, not sure if it's the same address as one from this thread.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java Tutorial

Post by hoijui »

would be nice if you could edit it yourself in the PDF, and change the link in the Wiki.
gajop
Moderator
Posts: 3048
Joined: 05 Aug 2009, 20:42

Re: Java Tutorial

Post by gajop »

hoijui wrote:would be nice if you could edit it yourself in the PDF, and change the link in the Wiki.
done:
NetbeansJavaSkirmishAITutorial.pdf
(1.28 MiB) Downloaded 772 times
PS: I don't seem to have the permissions to edit the wiki, so here's the edited wiki which you can copy if you want to:
hope i didn't miss anything
edit:removed unnecessary code
Last edited by gajop on 15 Sep 2010, 15:14, edited 1 time in total.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java Tutorial

Post by hoijui »

ehh, good job! :-)
(though you could have used pastepin ;-) )
you have to login to the wiki, to be able to edit it. use your forum user-name and pwd.
gajop
Moderator
Posts: 3048
Joined: 05 Aug 2009, 20:42

Re: Java Tutorial

Post by gajop »

hoijui wrote:ehh, good job! :-)
(though you could have used pastepin ;-) )
you have to login to the wiki, to be able to edit it. use your forum user-name and pwd.
I avoid using pastebins for things that may be read at unknown times, as they often have an expiration date.
Anyway, I've edited it now, I'm not sure what was the problem previously, I was pretty sure I was logged in, guess I was wrong.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Java Tutorial

Post by hoijui »

ehh nice, i like you! :D
one of the few "professional" forum users here. :D
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Java Tutorial

Post by msm8bball »

I think it would be nice if we could get more information about getting started on there. Yes, we have a tutorial for setting up the system, and from there a good programmer would be able to turn out something decent. But for someone like me, that knows a bit of programming but is trying to use this project to practice my skills, it's a high learning curve. Taking a look at some other guy's source code has been a great help, but I think more focused help would be good. I'd be willing to help someone experienced come up with something if anyone is interested.
gajop
Moderator
Posts: 3048
Joined: 05 Aug 2009, 20:42

Re: Java Tutorial

Post by gajop »

msm8bball wrote:I think it would be nice if we could get more information about getting started on there. Yes, we have a tutorial for setting up the system, and from there a good programmer would be able to turn out something decent. But for someone like me, that knows a bit of programming but is trying to use this project to practice my skills, it's a high learning curve. Taking a look at some other guy's source code has been a great help, but I think more focused help would be good. I'd be willing to help someone experienced come up with something if anyone is interested.
Well I don't have much experience regarding spring bots, but in most of these cases you should start off trying to get the basic things running first (assuming you completed the tutorial from here http://springrts.com/wiki/AI:Development:Lang:Java):
1. create a build order, have your commander execute it one thing by one (hint: create a list of UnitDef and order them one by one as they get finished, and use getResourceMapSpotsPositions and findClosestBuildSite from http://abma.de/projects/agai/doc-ai-int ... o/Map.html to achieve that)
2. have your commander help your veh/kbot factory by using the guard command, and have your veh/kbot plant spam one type of units (it's the same BuildUnitAICommand http://abma.de/projects/agai/doc-ai-int ... mmand.html but with position as new AIFloat3() - managed to find that trick out from searching hughs AI sources)
3. set cheats to enabled
4. use getEnemyUnits() from http://abma.de/projects/agai/doc-ai-int ... lback.html to get enemy units
5. find closest group, send your units to move there
6. ?? (bit of luck really :P)
7. defeat some of the easier non-trivial bots
8. notice what you're doing wrong and improve; if your bot manages to beat all existing bots in all sorts of maps eventually, try playing yourself against it, you are most likely a better player than bots are, and you best know it's weaknesses
Oh, and most importantly, don't try to ever perfect one sort of bot behavior! It will take you literally ages, if ever to do so, make the whole thing boring as hell, and probably, won't even matter much since you didn't get to work in areas that were causing you to lose in the first place. Avoid thinking: but this simple build order surely isn't general enough - I should find as many replays as possible for all sorts of maps and mods, use PCA + KMeans/EM to cluster maps into different types and based on all that create an SVM that uses all these parameters to decide my build order, when your base is still easily destroyed by a couple of fleas :p.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Java Tutorial

Post by hughperkins »

Personally, I found the easiest way was just to play with getting the AI to do different things. The initial goal isn't to annihilate the enemy or anything, but just to get some stuff building.

Just use a null ai as an opponent to start with, so you dont have to deal with being attacked.

Get the AI to build something. A solar panel makes a great start.

From there you can think about how to build a metal collector. Just build it anywhere there is metal, even if its on the other side of the map.

Once you've built a metal collector, maybe think about how to go about placing the metal collector optimally. I think there is an algorithm for that somewhere. Oh, here: https://github.com/hughperkins/HughAI/b ... Metal.java , function "SearchMetalSpots".

Then build a factory.

Then think about getting the factory to build some simple unit, just something generic, like a tank, or a scout, or something.

Then think about getting that tank/scout to move somewhere.

Then get it to move to lots of "somewhere"s.

By the time you've got this far, you're already quite familiar with lots of thing about springrts AIs, and can start setting yourself some new short-term goals.
Post Reply

Return to “AI”