MegaHAL in C++ console source code
The MegaHAL C program was translated to the best of my ability to C++ over the course of two weeks. I preserved not just the essence but the exactitude of the algorithm, including one obscure bug I found:
The above code, copied from the function babble(), is incorrect in that it assumes find_word() == 0 to be "not found" when in fact a return result of zero could be either "not found" or simply "found at index zero."
To keep it simple, I copied the bug into the C++ port of MegaHAL. This allowed me to conveniently test it with the C program's output to fix my own bugs, of which there were many.
There is a preprocessor directive in MHDefs.h which turns off all randomization in MegaHAL's inner workings, so that two invocations with the same data files and the same user input will product the same output. This is also extremely useful for testing!
I did not comment the code very well, and the user interface is somewhat lacking. The #BRAIN command is not yet supported. Also, there is very little in the way of error checking. I plan to deal with these shortcomings, provided I don't get lucky and find a "significant other" in the immediate future. Wish me luck, either way!
October 8, 2002Download
posted by plushpuffin (5/12/2002)