View topic - Java Tutorial



All times are UTC + 1 hour


Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Java Tutorial
PostPosted: 02 Aug 2010, 05:12 

Joined: 09 Oct 2009, 07:08
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!


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 02 Aug 2010, 08:11 
User avatar

Joined: 13 Jan 2008, 19:40
Location: New Zealand
Ill make you a tutorial for Netbeans.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 02 Aug 2010, 10:23 
User avatar

Joined: 13 Jan 2008, 19:40
Location: New Zealand
Here you go, its basic but it should work.


Attachments:
Spring AI.pdf [1.27 MiB]
Downloaded 333 times
Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 02 Aug 2010, 15:17 
Moderator
User avatar

Joined: 26 Oct 2007, 15:21
Great stuff. Stickied.


Top
 Online Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 02 Aug 2010, 19:28 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 03 Aug 2010, 00:00 

Joined: 09 Oct 2009, 07:08
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!


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 04 Aug 2010, 01:05 

Joined: 09 Oct 2009, 07:08
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?


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 04 Aug 2010, 01:47 

Joined: 09 Oct 2009, 07:08
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 04 Aug 2010, 01:58 
User avatar

Joined: 13 Jan 2008, 19:40
Location: New Zealand
Oh yeah, I forgot about that. Ill fix it tonight.


Strange though that it worked for me with it called MyAI.jar


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 04 Aug 2010, 03:11 

Joined: 09 Oct 2009, 07:08
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?


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 04 Aug 2010, 07:06 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 14 Sep 2010, 17:39 
Moderator

Joined: 05 Aug 2009, 19:42
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 14 Sep 2010, 21:26 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
would be nice if you could edit it yourself in the PDF, and change the link in the Wiki.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 15 Sep 2010, 12:54 
Moderator

Joined: 05 Aug 2009, 19:42
hoijui wrote:
would be nice if you could edit it yourself in the PDF, and change the link in the Wiki.

done:
Attachment:
NetbeansJavaSkirmishAITutorial.pdf [1.28 MiB]
Downloaded 488 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, 14:14, edited 1 time in total.

Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 15 Sep 2010, 13:52 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 15 Sep 2010, 14:16 
Moderator

Joined: 05 Aug 2009, 19:42
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 15 Sep 2010, 17:39 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
ehh nice, i like you! :D
one of the few "professional" forum users here. :D


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 15 Sep 2010, 20:50 

Joined: 09 Oct 2009, 07:08
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 16 Sep 2010, 10:37 
Moderator

Joined: 05 Aug 2009, 19:42
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.


Top
 Offline Profile  
 
 Post subject: Re: Java Tutorial
PostPosted: 24 Nov 2011, 16:03 
AI Coder
User avatar

Joined: 17 Oct 2006, 03:14
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.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.