Click here to Skip to main content
Click here to Skip to main content

Hammurabi

, 10 Oct 2008
Rate this:
Please Sign up or sign in to vote.
A C# port of the classic Hammurabi game.

Introduction

Michael Birken's Star Trek article rekindled my interest in classic BASIC games.

As a kid, I spent many hours typing in programs from magazines such as Antic, Analog, and Compute!, as well as from various books such as David Ahl's BASIC Computer Games (1978) and More BASIC Computer Games (1979). After typing in a program and getting it to successfully run, the next step would be to make changes, modify code, add features, etc.

Hammurabi was originally written as 'The Sumer Game' (1969) in FOCAL on a DEC PDP-8 computer, by Richard Merrill. Sometime later, it was ported to PDP-8 BASIC. David Ahl ported this version of Hammurabi to BASIC, and added the 10-year performance assessment.

Back in the day, I also played Atari's Kingdom game program which came on cassette. After looking at the BASIC listing for Hammurabi, Atari's Kingdom seems to be a direct port of Hammurabi, modified to use the Atari screen capabilities.

Porting

I started out with an Atari 400 home computer back in 1982. At the time, I sometimes found it a challenge to get generic BASIC programs such as the programs in BASIC Computer Games and More BASIC Computer Games to work correctly. Atari BASIC handled STRING arrays differently than other 8-bit machines of that era. Atari BASIC was also missing FNA(), FNB(), FNC() types of statements which had to be converted to subroutines. Fortunately, Hammurabi did not require any of these changes.

As Michael Birken's article points out, it is fairly easy to port BASIC programs to C#. To Birkenize a BASIC listing, follow these steps:

  • Change BASIC line numbers to C# labels:
  • For example:

    551 REM *** STARVE ENOUGH FOR IMPEACHMENT?
    552 D=P-C:IF D>.45*P THEN 560
    553 P1=((Z-1)*P1+D*100/P)/Z
    555 P=C:D1=D1+D:GOTO 215

    becomes:

    _551: ; // REM *** STARVE ENOUGH FOR IMPEACHMENT?
    _552: D = P - C; if (D > .45 * P) goto _560;
    _553: P1 = ((Z - 1) * P1 + D * 100 / P) / Z;
    _555: P = C; D1 = D1 + D; goto _215;
  • Change BASIC GOSUB statements to method calls.
  • Change BASIC PRINT statements to Console.Write[Line] method calls.
  • For example:

    229 PRINT "A HORRIBLE PLAGUE STRUCK!  HALF THE PEOPLE DIED."
    230 PRINT "POPULATION IS NOW"P 
    232 PRINT "THE CITY NOW OWNS"A"ACRES."
    235 PRINT "YOU HARVESTED"Y"BUSHELS PER ACRE."
    250 PRINT "RATS ATE"E"BUSHELS."
    260 PRINT "YOU NOW HAVE"S"BUSHELS IN STORE.":PRINT

    becomes:

    _229: Console.WriteLine("A HORRIBLE PLAGUE STRUCK!  HALF THE PEOPLE DIED.");
    _230: Console.WriteLine("POPULATION IS NOW " + P.ToString());
    _232: Console.WriteLine("THE CITY NOW OWNS " + A.ToString() + " ACRES.");
    _235: Console.WriteLine("YOU HARVESTED " + Y.ToString() + " BUSHELS PER ACRE.");
    _250: Console.WriteLine("RATS ATE " + E.ToString() + " BUSHELS.");
    _260: Console.WriteLine("YOU NOW HAVE " + S.ToString() + 
                            " BUSHELS IN STORE."); Console.WriteLine();
  • As C# uses zero-based indexing and BASIC uses one-based indexing, for array structures, either modify the data to add an unused zeroth element datum, or modify the code to subtract one from the existing indexing logic.
  • Review remaining statements; modify code, variables, and logic to compile in C#.

Playing

In the game of Hammurabi, you direct the administrator of Sumeria, Hammurabi, how to manage the city. At the start of the game, Sumeria initially has 1,000 acres of land, a population of 100 people, and 3,000 bushels of grain in storage.

You may buy and sell land with your neighboring city-states for bushels of grain. The price of land will vary between 17 and 26 bushels per acre. You also must use grain to feed your people and as seed to plant the next year's crop.

You will quickly find that a certain number of people can only tend a certain amount of land, and that people starve if they are not fed enough. You also have the unexpected to contend with such as a plague, rats destroying stored grain, and variable harvests.

You will also find that managing just the few resources in this game is not a trivial job over a period, of say, ten years. The crisis of population density rears it head very rapidly.

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

BillLange1968
Software Developer Citrix
United States United States
Bill is a senior software engineer. He designs and developments cloud based, web accessible on-demand provisioning system used for provisioning Citrix-based training and demo environments in Visual Studio 2010, .NET Framework, C# and SQL Server 2008. He resides in NJ with his wife Lucy and their dog Yoda.
 
Prior to web development, he spent seven years in the mobile enterprise space working at companies such as Peak Technologies, Countermind, and Blue Dot Solutions in the Denver, Colorado metropolitan area building enterprise solutions in the .Net Compact Framework, XML and SQL. He also has significant experience in the telecommunication space with various roles at AT&T Bell Laboratories, Lucent Technologies and Avaya where he worked on development and localization of the AUDIX platform and other voice messaging technologies.
 
Having spend his salad days playing around with his Atari 400, in his spare time, he likes to tinker with game programming, 8-bit computers and the classic arcade machines of his youth.
Follow on   Twitter

Comments and Discussions

 
GeneralMemories [modified] PinmemberIlíon13-Oct-08 5:33 
GeneralRe: Memories PinmemberBillLange196813-Oct-08 13:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 10 Oct 2008
Article Copyright 2008 by BillLange1968
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid