Thursday, January 31, 2008

A* Algorythm in Java - Download

I wrote this code a while ago, and I've finally got round to putting it here for public use. It's the A* path-finding algorythm, nicely self contained and ready for use. It can run in a thread if required, and to use it, you can simply write:-

AStar my_astar = new AStar(mymapclass);
WayPoints route = my_astar.findpath(start_x, start_y, end_x, end_y, b_run_in_thread);

Your
mymapclass must implement the IAStarMapInterface (included), which has 3 methods: getWidth(), getHeight() and isTraversable(). This tells the algorythm where it can and can't go. The class WayPoints is just an ArrayList of Points, giving the route.

I've used this code in all of my games (that require pathfinding) like Nuclear Graveyard and TremulousHulk.

(For those not in the know, the A* algorythm basically finds the closest path from one co-ordinate to another, taking into account blocked points.)

Monday, January 28, 2008

Tiny Web Server

There seems to be a durge (if that's the right word) of web servers called "Tiny Web Server", all vying to be the smallest web server. And now there's another one! I don't think it's the smallest, but it is a full web server for delivering static pages and documents.

It's written in Java, and the source comes to 23K. It should be pretty easy to extend to make it write dynamic web pages, so it should be ideal for starting your own web server project, or just giving you an idea of how web servers work. Or how not to write code. Take your pick.

It's available via SVN here. (That's svn://www.onlinegameplanner.co.uk/TinyWebServer).

Wednesday, January 16, 2008

Originality is a Curse

...That's probably why most games companies still churn out mostly FPS's and endless sequels to those FPS's.

I've written a game called Nuclear Graveyard which (IMHO) has a bit of originality: it's what I call pseudo-realtime. This means that rather than be proper realtime, it uses action points (e.g. walking forwards costs 1AP) but unlike most games that use APs, the player's APs are replenished automatically as both sides use them up.



Unfortunately, when most people play it, they don't seem to read the instructions, and assume that it's either a normal FPS ("why can't I move?") or a normal turn-based game ("How do I end my turn?"). I can't blame people for not reading instructions - who does? - but I've tried my best to make it self-explanatory, and included a tutorial, but to no avail. What do I do?

Friday, January 11, 2008

Multiple Platforms, Multiple Databases

SQL Enterprise Manager (or SQL Server Studio, as M$ like to keep changing the name) isn't a bad program, but obviously it only works with MS SQL, and only on Windows. Since I use MySQL, PostgreSQL, Oracle and MS SQL on Windows and Linux, I've been looking for a single program that can handle all of these databases, and I've found one: Aqua Data Studio.

It's written in Java (though there are other versions available) so it runs on Windows and Linux, and it easily connects to almost every kind of database, allowing you to do all the impotant things that SQL Server Studio does, like view the tables, edit the data, run queries etc...

I'm not affiliated with Aqua Fold in any way, but I thought I'd mention a program that is really useful and pretty good. It's free for personal use as well.

Wednesday, January 09, 2008

Domain Name Front Running

I wondered if any companies do this (i.e. you search for a domain with the intention of buying it, and the company that you use to search for it buys it up, knowing that you want it). And yes! Of course it happens...

Friday, January 04, 2008

My New Language

I have finally abandoned my attempt at a new Lisp-like language. I don't think I realised how hard it would be. Converting a text file of my new language into an AST (an active syntax tree) was the easy part. The hard part was storing variables (globals v locals, scope, identically named vars overriding each other, etc...) and calling functions (i.e. replacing the params in the function) among other things.

I should have planned it all better as I was also going round in circles with my language definition: I was changing it to fit one circumstance, but then forgetting why I'd done that, and then I'd change it back again to fit the original circumstance.

However, the final nail in the coffin was my thought "what am I going to do with it when I've finished?" It obviously had no IDE, barely any libraries, no debugging facilities, probably lots of bugs, and probably lots of flaws in the design. Why would I, never mind anyone else, choose to use it when there's plenty of other better languages out there?

Still, it's given me a new insight into how languages (might) work, and hopefully made me a better programmer. Now onto my next project: a mega-multithreaded program, where every little aspect has it's own thread. It's how the human body (i.e. cells) work (I think) so it must be a step in the right direction. And with all this talk of parallel programming, it can't do any harm for me to fail at that as well.

Thursday, December 13, 2007

Don't Buy Western Digital Hard Drives

More political posting I'm afraid...

Anyway, to get straight to the point, Western Digital HD's are crippled with DRM to prevent files with certain media extentions (e.g. AVI, MP3) from being shared across network drives. Even if they are your own creation! And the name of the software that does this? "WD Anywhere Access". You couldn't make it up!

Friday, December 07, 2007

My Programming Adventure - Is the journey nearly over?

I've alluded before to the fact that I sometimes think of my time spent programming as an adventure, looking for the reason why I program and what I hope to achieve. (I'm talking about my hobby programming of course - I do my profesional programming to pay the bills).

Several times I've been in the middle of writing one of my games, and suddently realised I'm not actually enjoying writing it. Or I've finished a game and realised it's not that much fun to play, or I think it is but the ROTW disagrees.

However, I have now found my holy grail. I've written a small, simple and (AFAIK) original puzzler called Chain Reaction. It's pretty addictive, but what has caused it to really take of here where I work is the high score table. People are falling over themselves to try and beat each other, and I'm loving the fact the people are telling me they hate the game because they're spending too much time playing it but they can't stop! I may be egotistical, but I think it's the kind of praise and recognition I've been looking for all these years.

Thursday, December 06, 2007

New Language Update

Here's a tip for anyone who's thinking about writing their own language - plan it first. I know I should have. I've got a reasonable understanding of how Lisp works (i.e. evaluate everything inside the brackets recursively, and then process it) but I made some silly mistakes...

..Like evaluating the brackets each time I read them. For example, the program:-

(defvar lst (quote 1 2 3) ; <- "lst" now contains (1 2 3), correct.
(print (lst)) ; Error! I've processed "lst", but the function "1" (i.e. the first item in the list) is (obviously) unknown!

This is just one example. I'm going to start again. I've learnt a lot from my mistakes though, and my aim is to have a language with the best Lisp features like Macros, but more practical with simple functions to connect to databases etc...

Thursday, November 29, 2007

My New Programming Language - "Harry".

Being a programmer who has no fear of programming a disaster, I've decided to write my own programming language.

"Madman!" I hear you cry, but no, seriously. And on the face of it, it's not that difficult. On the face of it, it's just a case of reading a text file and turning that into "symbols", which your interpreter/compiler converts into something existing, whether it's Bytecodes or good old machine code.

My language is called "Harry", and is similar to Lisp, since everyone seems to rave about it, and I've been quite impressed with it. However, there are a few (minor) problems with Lisp, which no doubt people will take me to task for. Here's my : it's not standard enough (there seem to be lots of variants), and it's not very practical (in order to do something like graphics or databases, you need to find libraries).

I've written the interpreter in Java for platform-independence. It's still in the development stage, so no download yet. The current problem I've got is functions and the variables contained within. What happens if a function names a variable with the same name as a global variable? And scope is a problem, i.e. "unsetting" the variable once the function has finished, so the global var becomes available. But what if the function calls another function? And recursion? And what about if a parameter to the function has the same name as a variable?

Anyway, to whet your appetite, here's an example of the code (which should be self-explanatory):

; Add, eq, print
(print (eq 2 (+ 1 1))) ; returns 1

; Set
(set lst (quote 1 2 3))

;quote, contains, if, return
(print (if (contains 2 lst)(ret true)(ret false))) ; prints "True";

Monday, November 19, 2007

Why Are Named Parameters Rare?

One of the things that seems common to most languages, even the supposedly better new ones, is the lack of "named parameters". Surely it must have come to the attention of most language designers that having a line like the following is ridiculous:-

// Do some stuff
int x = MyFunction(true, false, true, true);

Okay, it's probably bad programming practise to have something like this, but even a simpler line with just one boolean would be bad. What on earth does each parameter mean? The only way of finding out is to query the underlying function's code, but that defeats the object of having well named functions. I'm still surprised that having named parameters isn't in most modern languages. How much better is the next line:=

int x = MyFunction(foo:true, bar:false);

Here you can see, without having to browse the underlying function, what each parameter means. Okay, this is nothing earth-shattering that will lead to perfect code, but it has to be a step in the right direction.

Thursday, November 15, 2007

Eclipse and Subversion (Subclipse)

I've blogged before about using Subversion and Eclipse - if you haven't installed Subclipse then don't do it! However, I've discovered another problem and solution to Subclipse...

Even when Subclipse is installed, if you have seperate src and bin directories, the bin directory can confuse Subclipse, since Eclipse likes to effectively delete it and recreate it with each build. The solution to this (apart from adding the bin directory to your ignore list) is to not "Scrub output Folder when cleaning projects".

Wednesday, November 14, 2007

New Game - Chain Reaction

And this time it's original! I knocked it up in Java over about a day (though most of that was trying to work out how to turn "bouncing balls into each other" into something resembling a game).


It's called Chain Reaction. Basically, you have to bounce a certain number of balls into each other. The page (just like all my other applets) keeps track of your scores in a global high-score table, which I think greatly improves the competitiveness. And it's pretty addicitve (and hard) to boot!

Tuesday, November 13, 2007

I Bought a Domain!

I've finally bitten the bullet and bought a domain - http://www.onlinegameplanner.co.uk/. My original "default" domain was "ng.game-host.org", which doesn't really roll off the tongue quite as well, and bears no meaning to the content of the website.

Thursday, November 08, 2007

New Project

It's called Survival (at the moment).


[Added 19/11/07] A few other details since the original post was so sparse: it's written in Java and uses jMonkeyEngine to do the 3D.

Tuesday, November 06, 2007

BBC & Microsoft

(This blog is getting a bit political, I know). What happens when an ex-Microsoft employee starts working for the BBC? They develop a Windows-only iPlayer and claim that only 400-600 Linux users visit the BBC site, before hastily correcting themselves after getting it 16,000% wrong.

Wednesday, October 31, 2007

Software Exams! Grr!!

One thing that annoys me a lot are "software exams", where you can become a certified drone of the particular software company, typically Sage or Microsoft. They are a two-pronged attack by the software company on free software, gaining them money (because you have to pay to take their exam) and locks you into their software, since you are more likely to stay with software that you have spent money and time learning.

But they also have ridiculous questions! One of the Sage exams has the question "What is the maximum number of lines you can have on an invoice?" What?? So Sage has decided (either due to their inability to write software that allows as many invoice lines as possible, or their marketing dept. decided that it looked good in a brochure) that you can only have 99 lines on an invoice. And people have to memorise this (and a myriad of other completely pointless facts) in order to pass an exam.

Excuse me if I'm not impressed with anyone who's been stupid enough to take this exam.

Monday, October 29, 2007

Off Lisp

I don't see why Lisp is so great. I wrote a "random movie star selector", and it came up with Tom Cruise.

Thursday, October 25, 2007

Shadowfire Remake

Shadowfire is a classic Spectrum game from 1985, and I'm always surprised that no-one has remade this, since it seems perfect to me. The original game had some great ideas, plot and gameplay, but was limited by the platform. Some modern graphics would enhance it no end.

So I've taken it upon myself to do the remake, which is located here.

Screenshot

I've given it an RTS-style interface. It's still unfinished; at the moment you can walk around, teleport your team in, and shoot the enemies. It currently uses sprites from the original game, which weren't designed to be used in a top-down game, so if anyone could provide me with new sprites that would be good. I've got the code to rotate them to all 8 directions, so you only need to draw one copy of each!

Tuesday, October 23, 2007

Java Threads

Unfortunately, one of the (few :) ) drawbacks of Java applets is that in order to have a consistent game loop, you need to run the main game code in another thread. (I may be wrong here; please let me know if I am). I've blogged before about why threads in any language are a pain as they exponentially complicate a program, not least because variables can change mid-line.

Another problem that I always forget, is that in Java, threads don't access another threads data directly (unless you use the volatile keyword). Forgetting this caused me several hours of frustration and I even wrote my own ArrayList class to try and fix it. Basically, the code in my thread's run() function was accessing the class-level arraylist. But completely failing to affect it! It was calling "arraylist.remove(13)" (say), but after it had run, that object still existed in the list! What was going wrong?!?

Well, I've already said the answer. It was accessing a copy of the arraylist, not the list itself. As soon as I discovered and fixed this, all was well and I could go back to enjoying writing applets again.