ICFP 2008

Created 15th July, 2008 02:30 (UTC), last edited 15th July, 2008 02:46 (UTC)

So there I was reading the ICFP competition task for this year and I downloaded the ISO image and fired it up under VMWare. Having done that I grabbed one of the simulators and thought it might be fun to just telnet to it and drive the rover around for a bit.

After having done a bit of fiddling around to get the simulator running on my 64 bit Hardy installation I discovered that the simulator crashed when it encountered any whitespace in the command stream. As telnet wouldn't send any data without me hitting enter there was something of an impasse – if I wanted to play around with it I'd have to actually write some code. Oh well.

I kind of wanted to do something in Haskell but the prospect of trying to do all the TCP/IP stuff in a pure functional language didn't really appeal. Python would have been interesting, but it wasn't included and that left me with either learning a whole new programming language or doing it in C++, but without any of my normal C++ tools like Boost. I figured it would probably be good to learn how to do some simple networking stuff on Linux because I'd want that code to port the FOST.3™ TCP streams anyway.

This meant I spent a couple of hours on Saturday and a few more on Sunday knocking up what would be about the simplest thing to do that wouldn't totally suck. In total I think I probably used about eight hours, of which probably three went into working out how to get the network connection open (sending and receiving data was pretty easy once I'd got the connection open) and the rest went into working out a few simple heuristics to get the rover through the three supplied sample maps more often than not.

The things that were trickiest were:

  1. Translating the C sample code for opening a socket connection to C++. My code still has some nasty Cisms in it, but seems to work well enough.
  2. I can't believe the amount of maths I've forgotten. My collision detection code checks to see if the bearing to any obstacle in visual range is is within three degrees of the current direction. If so it turns the rover left. Clearly this doesn't always work, but it was very simple to write.
  3. Working out how to make a tar ball. Sounds pathetic I know, but I've never made one before. In the end I didn't work out how to gzip it, but as it was 20KB uncompressed I figured it probably didn't matter.

I was expecting the parser for the telemetry and other messages to be quite hard. In the end I just dropped the string into a std::stringstream and used the extraction operators. Extremely straightforward. I was also a bit miffed that I'd have to write my own smart pointers rather than use the Boost ones, but in the end I didn't use a single memory allocation so it didn't matter.

How do I think it will do? I fully expect the rover to do well enough to get knocked out in the first round of heats.

The code is available for download.

17 src/main.cpp