So I rewrote it in Erlang. And had a lot of fun doing it. Apart from the nostalgic kick, there were two points with the exercise: First of all, I just wanted to see the main algorithm as cleanly implemented as possible. But second, I wanted to see what it would be like to rewrite a piece of classic game code that was very clearly not written with functional programming in mind (though of course already cleaned up a bit by being rewritten in C from the original 6502 assembler). I think I like how the result turned out; it's quite clean and readable, and the data flows are easy to follow. I also found and fixed a bug in the "goat soup" function.
The code can be found on GitHub, along with the two scripts for testing found on Ian's page. You can run them like this:
erl -noshell -s txtelite main -s init stop < sinclair.txt(To play yourself, just skip the last "< sinclair.txt" part.) Of course, you need to compile the txtelite.erl file first. If you're new to Erlang, this is how:
erlc txtelite.erlIt's good to be back on Lave again!