šŸ‘½ Lee Tusman

ā† Nosebook šŸ‘ƒšŸ““

HAMURABI in 2025 - 57 years and growing šŸ°

08 Feb 2025

Four-minute read

This is my first entry on porting early text-based economic simulation games to a modern Basic variant so they work on a variety of computers. Iā€™m interested in permacomputing, particularly looking at keeping computers useful and engaging/fun without buying into increased consumption. Working with old codebases as a form of exploration and a way to strip back complex systems can also be empowering and a tool for learning, both from a computer science perspective as well as in the digital humanities.

King of Sumeria or The Sumer Game, later called Hamurabi, was originally written by Doug Dyment in the Focal language for DEC computers in 1968.

The game consists of ten rounds wherein the player, as the ancient Babylonian king Hammurabi, manages how much of their grain to spend on crops for the next round, feeding their people, and purchasing additional land, while dealing with random variations in crop yields and plagues. The Sumer Game was inspired by The Sumerian Game, a much more in-depth text-based economic simulation intended for children, developed from 1964 to 1966 by designer and elementary school teacher Mabel Addis and IBM programmer William McKay.

Around 1971 David Ahl ported the game to DEC BASIC, and then published it in his classic type-in program book 101 BASIC COMPUTER GAMES (listed as HMRBI) in 1973 and in expanded form in Microsoft BASIC in 1978 for BASIC Computer Games. These are the sources Iā€™ve been working with, porting old simulation games to a modern BASIC dialect, Yabasic.

Translating Hamurabi between BASIC implementations

I was able to translate Hamurabi from its original code in BASIC Computer Games to Yabasic with only minor changes needed.

These were:

  • I added more spacing for better formatting around variables in PRINT lines with concatenation, and changed all semicolon separators to commas.
  • Any line with a conditional and implied goto jump needed an explicit GOTO and ENDIF functions added. For example: if L<7 THEN 565 needed to be changed to IF L<7 THEN GOTO 565 ENDIF in Yabasic.
  • RND(1) is translated to ran() (or in upper case) in Yabasic.
  • After some tests with various BASIC emulators I believe PRINT CHR$(7) produces a bell sound, so I translated line 990 to bell in Yabasic, however I couldnā€™t get this to produce sound on my computer.

I considered whether to take advantage of the modern use of functions, called subroutines in some languages.

For example in Yabasic one could write:

sub hello()
  print "hey world"
end sub

hello() REM OUTPUT: hey world

In Edsger Dijkstraā€™s famous 1968 letter to the editor Go To Statement Considered Harmful he argues that excessive use of GOTO statements causes hard to follow code and poor coding practice. On the one hand, I want to push back because the use of GOTO likely allows for as-you-go ā€œamateurā€ programming, though this also leads to a ā€œwrite onlyā€ style of programming thatā€™s hard to decipher later. On the one hand, reviewing the Basic code for these 1970s program has led to exactly that: code that can be hard to follow because of its excessive use of GOTOs that jump all around. On the other hand, the code largely ā€œjust worksā€ and thus a result of its simplicity in readability (itā€™s very clear what it means, jump to that line number) and its minimum of syntax. Porting between code bases and languages is not out of band, but it would certainly be more work than Iā€™m taking now to have to rewrite the syntax (or attempt to script or find/replace all). But instead, Iā€™m able to more or less use the code with the exception of the points mentioned above for translating the code. Total time to port was exceedingly fast, and for that, Iā€™m thankful for the GOTOs.

The tradeoff is that to modify the code, one would have a much easier time altering variables or text output rather than reorganize, or more seriously structurally output the program, and add more subroutines and the like.

With these minimum of edits to complete a port, the game is engaging, and yet Iā€™m still not a great player of the game. I have not yet won! In the coming months Iā€™ll publish more about porting other BASIC games as well.

Further Reading

David H. Ahl. 101 BASIC Computer Games. Digital Equipment Corp., Maynard, MA, 1974. Internet Archive, http://archive.org/details/101basiccomputer0000davi.

Ahl, David H., and Steve North, editors. Basic Computer Games. Microcomputer ed, Creative Computing Press, 1978.

Dijkstra, Edsger W. ā€œLetters to the Editor: Go to Statement Considered Harmful.ā€ Commun. ACM, vol. 11, no. 3, Mar. 1968, pp. 147ā€“48. ACM Digital Library, https://doi.org/10.1145/362929.362947.

McCracken, Harry. ā€œFifty Years of BASIC, the Programming Language That Made Computers Personal.ā€ TIME, 29 Apr. 2014, https://time.com/69316/basic/.