Hamurabi (#223)

On Tue, Nov 3, 2009 at 1:48 PM, Benoit D. [email protected]
wrote:

So here is my pastie:
http://pastie.textmate.org/681199

Still bugged, because I couldn’t understand so much the part with planting
seeds. (and why using the variable dead at that moment?)

he reused some of the variables for two separate things. the seed
planting bit was “calculate a random yield per acre, and see how many
bushels you got after planting so many bushels”.

martin

Cool. Caveat for the non-bleed users: ruby1.9 required (1.8.6 here).

I must admit, I didn’t even try to understand certain design decisions.
I
basically followed flow and then cleaned up the code a little later. I
believe the for loop was to play the system alert seven times (ASCII
char
7). I think. Sound effects on a PDP-8 terminal. :slight_smile:

There were many great solutions to this week’s quiz. Most of the
solutions took the route of translating the BASIC code into Ruby
though James Edward G. III actually built a BASIC interpreter.

James uses regex based parsing and makes use of StringScanner1,
which provides for lexical scanning operations on a String. BASIC is
pretty amenable to parsing with regex because of it’s simple syntax.
I’m not familiar enough with BASIC to know if a grammar would be
required to provide a full implementation, but it may add simplicity
in some situations of complex expressions. I ran into some glitches
with my grain count getting extremely large and plagues happening
every turn, but overall this was definitely the most adventurous
attempt.

Benoit D.'s solution translated the original statement sections
into Ruby methods. Each of these methods ended with a call to another
method as the last expression in the method. This is to simulate
either an implicit fallthrough or an explicit goto to another logical
section of the code.

genericpenguin gives us another translation, though with a little bit
more of the control flow abstracted into the run_iteration method.

Martin DeMello has the most Rubyish translation. Each logical section
was translated into a method and the overall program flow was
controlled by a main loop. The main loop can easily be extended to
have the game run for a 20 year term, or even thousands (maybe even
rivalling Civilization).

It is interesting to look back on these older computer games and the
spectrum of complexity and see how even simple games can provide so
much enjoyment. And to also note how even simple games can be tricky
to implement. Speaking of tricky, there was some lively discussion
about a multiplayer version. Some possible game mechanics include: a
free market for buying and selling land, migrant populations, and the
tradeoffs of public healthcare. Maybe even a cap and trade system for
carbon emissions, who knows?

In playing many of these solutions I was doing pretty well, up until
the point where everyone died. This quiz was a lot of fun, special
thanks go to Martin DeMello2 who suggested3 it. Thank you everyone
for the great solutions and discussion!

Hamurabi (#223) - Solutions4