simulator world red-ant black-ant generations
The simulator. Takes a world, two ants, and a number of generations as parameters.
Written in C because of familiarity with the language. It would have taken me much longer (I think) to write and equally well performing simulator in a functional language. OTOH this would probably have been much stabler and easier to read.
I'm not satisfied with the speed though. There's probably at least an order of magniture of speed improvement possible in the data structure alone (for example, determining dying ants). However, the big showstoppers seem no to be the data structures, but the division in the RNG and branch prediction. I have no idea if cache effects play a role, too (not enough time to use vtune or oprofile right now). (2004-06-07 ran it through cachegrind. No L2 misses to speak of.) I have tried a faster RNG w/o division, but it was not that much faster, so I kept the original. As for branch prediction in the Flip instruction, what can one do? The simulator still takes a few seconds for one test run with all 10 sample worlds - this is slower than I had hoped.
Had the simulator exactly reproducing the sample dump about 7 hours after contest start. (One hour after midnight local time.) Decided not to further improve it, but rather start generating ants.
Other notes:
In general: the code is not pretty. The is practically no validation of incorrent inputs. In error situations, there is no recovery - the program just writes a message to standard error and exits.
The ant parser is broken. In particular, it does not allow comments. It works for my ants, though.
antgen n
generates a random ant program of n states and writes it to standard output.
At first, I gave equal probabilities to the instructions. Later I changed that to generate less move, pickup, and drop instructions. Did not seem to make a difference.
ant_mutate ant n
randomly changes n instructions in the ant program in file ant and writes the resulting program to standard output.
crossover ant1 ant2 n
Very crude attemt at combining two ants. (I should have read up on genetic programming before attempting this approach.)
If the two ant programs have the same number of states, overwrite n random states in ant1 with those from ant2.
If the programs are not of the same length, overwrite n random states in ant1 with random states from ant2.