ICFP '02 Programming Contest

Team: I don't need to stinkin' team

Language: Prolog

Programmer: Harry Chesley

 

It's Friday afternoon. I'm reading /. and see this pointer to a programming contest. What better way to waste -- er, spend -- my weekend? I check with the family and they don't mind not seeing me for a few days, so I'm off...

I've been programming in Prolog lately for some AI projects, and it seemed a good match for the contest, so that's what I used. Which is a good place to say something about this "best language" thing. There is no best language. There are only programmers who can't see things from all the perspectives. So if my entry should win (however unlikely that may be), I hope it won't be used by some Prolog fanatic to beat up some other flavor of language fanatic. In fact, as I'm fairly new to Prolog, I'll bet "real" Prolog programmers will look at my code and cringe...

My algorithm is low on strategy, a bit better on tactics, and (hopefully) very solid on implementation. Three days just isn't enough to develop complex strategy. It would be very interesting to see what people came up with given, say, three weeks, or given a series of competitions where programs could be refined in between.

My strategy is simply to choose one of the following in this order of priority:

  1. If the bot has a package and is at the package destination, drop it.
  2. If the bot is standing on a package and has room for it, pick it up.
  3. If the bot has a package, go to the package destination.
  4. If the bot knows where a package or base is, go there.
  5. If the bot doesn't know anything, go to every space on the board (who knows, it might have missed something).
  6. Do nothing (it should never come down to this; just in case something above breaks).

Tactics cover a variety of local situations, in no order of priority:

Implementation-wise, I think it was important to use a language like Prolog, not one like C, to leverage the development time and to avoid several classes of potential crashes -- there just wasn't enough time to fully test things. But I did run the bot against as many boards and with other bots as much and as long as I could, including every one of the single-bot test boards. I've seen contests like this in past where someone had an absolutely brilliant algorithm, but the code crashed two seconds after starting because the program ran into a situation that wasn't anticipated. Sometimes the implementation quality is more important than the algorithm.

Anyway, I hope everyone else had as much fun as I did.

P.S. The Prolog source code (for SWI Prolog) is available here. The full submission is here.