SERENDIPITY
 created by Philip Taylor (philip@zaynar.demon.co.uk)
 for the ICFP Programming Contest 2002


This entry actually consists of two programs; the first is the
robot controller (runme), and the second (potentially
more interesting) one is replay.pl:

runme has the ability to record a log for each game it plays in
(to turn this on, edit runme and change the line near the top to
"use constant LOGGING => 1;" - it's not enabled by default because
it's usually just a waste of resources).
When the program is run, it will create a text file which is ready
to be played back by replay.pl

replay.pl does what its name suggests - it plays back a recorded
game visually, so you can see the little robots running around
with packages and getting themselves confused and drowning each
other.
To use it, you need to install the Tk module for Perl (available
from CPAN at www.perl.com, and probably from lots of other places)
and run the program from a GUI.

It will ask you to select a log file to load, so select one.
Depending on the size of the map, it might take a while to
generate the display, but then it will start playing back the
game. To stop it, either close the window or wait for it to reach
the end.
The display is fairly simple - the green bits are paths,
the brown bits are walls, the blue bits are water, and the
cardboard boxes are bases (the robot, and therefore the replayer,
doesn't know where all individual packages are and so none are drawn
on the map).
The robots look like robots. The decapitated robot heads indicate
dead robots, ready to be put into packages for the next game...


The actual robot program is far less interesting - the pathfinding
seems to be reasonably speedy (although not always totally accurate),
splitting the map into rectangles so that it can search through several
hundred nodes rather than tens of thousands. The actual implementation
is fairly inefficient, though, and I'm sure there are many better
methods.

The brain is much less successful, and works by thinking of lots
of possible actions and then deciding which of those to do
based on lots of arbitrary numbers, with very little experimentation
to work out optimal values.
It repeats this for every turn, often leading to endless shuddering
between two locations, which is exceedingly annoying. But it works
at least some of the time, and I am therefore happy :-)


Both programs together add up to about 1200 lines (if you count
the comments and blank lines...), all written in pure Perl.
