Design
Perverse is a fairly straightforward three-state machine:
In a map with more than one Home Base, the Searching state should never occur. This leads me to a list of known weaknesses:
Balancing that, a few things I'm happy about:
Other things...
The A* search algorithm wants a quirky data structure. A priority queue is desirable for finding the lowest-cost Open node. However, you also frequently search the Open list for a given node in order to compare a new g() value with the best g() found so far for that node. Essentially, we want a sequence which is uniquely keyed in one dimension (by node id) but sorted in another dimension (by node cost g()).
On the surface, a std::Map seems perfect for this, but I was unable to get it to do what I wanted. I now suspect that Map is not in fact the right mechanism - he and I seem to disagree on the meaning of "key".
In the end, I wound up using a heap to manage the Open list. Since only one A* search could be going on at a time, I could store node costs directly in the World data structure. This is precisely the kind of thing that gives me the heebie-jeebies, but at least it's fast.
Mechanics, or "How I spent my long weekend"
I hadn't planned on entering this year. Friday afternoon I changed my mind; wrapped up what I was working on and finally set to work about midnight. The time breakdown was approximately:
The submission is written in C++, which is entirely masochistic (and leads to the name of the entry: this was truly a perverse way to enter the contest). I haven't done any serious development in C++ in about 3.5 years... and of course the landscape has changed in that time. For example, the STL is more powerful than I recall, but also more inscrutable.
Of course, re-learning a programming language on the fly is not a winning strategy. As it is, I spent far too much time getting basic infrastructure working and fighting with the STL (see std::Map above).
Conclusions
C++ is not an efficient way to compete in a contest such as this. My own clumsiness exacerbates the situation to the point that more time was spent on infrastructure than solving the core problem (again, see the contest entry name).
Despite this, it was a fun weekend, and I think that Perverse is competitive. The things it does, it does fairly well; I just wish I had time to make it do more things.
Source/binariesThe submission tarball: perverse.tgz
- Jon Pile, Team Eikkel