Friday, September 30, 2011

Morgan wrote a program!

Thanks to Microsoft SmallBasic, I coached Morgan through writing her very first program today!
It was a lot of fun to show her a bit of the development world and explain a little bit about OOP.

AStar in Java.. and this WYSIWYG editor sucks

I'm on another game programming kick. This happens every several months or so, I play around with it for a while before getting lost in the enormity of it all and wandering away again.
This semester, I'm taking a programming class which uses Java. Not being at all familiar with Java, I was pleasantly surprised to discover that it is very similar to my main language, C#.
While investigating Java game programming I came across jMonkeyEngine (a Java 3d game engine), and while going through some tutorials on their site I came across an AStar tutorial.
I decided to gain some Java experience by implementing AStar in Java. I got a basic version working pretty quickly, but it wasn't taking the fastest route - it was taking 9 blocks to do what should only have taken 8.
I kept playing around with it and got it down to finding the fastest route, but it wasn't nearly as efficient as it could be (it kept searching blocks that it didn't need to). I fixed this by recording what iteration the algorithm was on when each block was discovered, then weighting my search to sort first by distance (asc), then by iteration (desc).
So, given the following blocks:

BlockDistance From TargetIteration
1101
3102
2201

the old version would pick either block 1 or block 3 when searching; the new version would always pick block 3. Anyways, the end result is that the path my program finds is identical to the one in the tutorial:

Not really a big accomplishment, but it's exciting for me, so I figured I'd post it.


On a side note, I just changed the font to Arial then went back to the HTML and ugh! It took my nice simple text and added a span on every line with inline styles all over the place. Blechh.


Download Sample (Open the HTML page)
Download Source Code (Netbeans project)