16 Apr 2000 jrennie   » (Apprentice)

Even though I should realize that "back then," K&R-style function declarations were the right way to go, nowadays, it pisses me off to not see nice, ANSI C-style declarations.

As you might guess, I've been hacking on some old C code; namely, the war game xbattle. Xbattle is a pretty fun game; you and your opponent begin with blobs of stuff (your troops) occupying various cells around the board. You move this stuff around the board intending to destroy any and all enemy blobs in sight. If you're lucky, you have the whole board covered with your blobs in a matter of 2-3 minutes. It's a fast-paced, real-time game that can be pretty exciting---it's multiplayer fun in the sense of Doom or Quake. The graphics don't quite compare, but it's still fun :-)

Anyway, I'm currently taking this "Embodied Intelligence" grad course where they expect us to complete a project by the course's end. Lucky for me, "evolving some sort of creature in some sort of world" is an acceptable project. Two of my friends and I jumped at the chance to "evolve" xbattle players.

Xbattle is a bit dated. If you visit the web page, you'll see written in large letters, "There has been no work done on xbattle since 9/1/96." A good chunk of the code is not ANSI C compliant, include files are somewhat numerous and run up to three levels deep and the make system is based on xmkmf. Ick, ick, and double ick.

Giving xbattle a decent make system was my first priority. I broke out the autoconf info pages and had a GNU-style make system up-and-running in a matter of an hour or two. Not long after that, I decided that it would be nice to bring in C++ classes in order to define a player module. Since I was going to change a good bit of the code anyway, I decided it was time to give in and bring xbattle's coding style up to speed. I ended up combining most of the .h files into one, xbattle.h, rewriting every function header in ANSI C style and compiling a list of function declarations in xbattle.h (declarating functions to avoid compiler warnings must have been an unpopular thing in the early 90s...).

So, now I can look at the code and not scream in horror. I still don't dare to try to fix all of the bits that g++ will complain about given the -Wall argument. It was painful enough to fix all of the function headers. What I find to be very cool about the code is that it is almost to the point that it could be released to allow others to write xbattle players. I'm thinking about running a small computer-player xbattle competition here at MIT. I also need to go talk to the original authors---see if they'd be interested in releasing ANSI C code rather than the K&R-style that they currently put out.

Even though I'm complaining about the xbattle code, I do have to say that I am greatly indebted to the authors. It's quite an impressive and versitile bit of code; things are well documented and it wasn't too hard to get in and add a wholly-autonomous computer player. Cheers go to Steve Lehar and Greg Lesher for writing the thing in the first place :-)

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!