Post by georgemcginn on May 18, 2021 9:12:57 GMT -5
Hammurabi is a game that started the strategy games. Sid Meir's game Civilization was heavily influenced by this game, converted from FOCAL to BASIC by David Ahl.
The original author is unknown, but this version is the one many played on their new IBM PC's and Apple II computers, as well as those using Commodore and in Great Britian, the ZX Spectrum computers.
This code is the original that was published in Creative Computing in 1978. However, I remember playing this game in 1973 on a DEC PDP/8E computer with a teletype console.
Here is the write up from a readme file I found awhile back, and a listing of the original code with some minor changes.
The code is the same except for lines 1 & 2. To test this code, I ran it in both FreeBASIC and QB64. Line 2 is not needed for QB64, but it does give you a larger window to display your text. I also ran the original code in TechBASIC and SmartBASIC (now A BASIC Programming Language) on my iPad, and in BestBASIC on my MAC OSX. The program runs in FB/QB64 on Linux, Windows and MAC OSX.
However, there is one issue I found in FB: The RANDOMIZE TIMER is not correctly seeding the randomizer, and every run has the same return results (maybe someone more versed in FB can show me what I'm doing wrong.
Here is the write up from a readme file I found awhile back, and a listing of the original code with some minor changes.
The code is the same except for lines 1 & 2. To test this code, I ran it in both FreeBASIC and QB64. Line 2 is not needed for QB64, but it does give you a larger window to display your text. I also ran the original code in TechBASIC and SmartBASIC (now A BASIC Programming Language) on my iPad, and in BestBASIC on my MAC OSX. The program runs in FB/QB64 on Linux, Windows and MAC OSX.
However, there is one issue I found in FB: The RANDOMIZE TIMER is not correctly seeding the randomizer, and every run has the same return results (maybe someone more versed in FB can show me what I'm doing wrong.
Here is the text from the readme file, then the source listing. My next post will show what the code now looks like once I modernized it and converted it into a modular structured program.
README:
Hammurabi
By: David Ahl; Digital Equipment Corporation
Publication date: 1978
Usage: CC0 1.0 Universal Creative Commons License
In this game you direct the administrator of Sumeria, Hammurabi, how to manage the city. The city initially has 1,000 acres, 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 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 its head very rapidly.
This program was originally written in Focal at DEC; author unknown. David Ahl converted it to BASIC and added the 10-year performance assessment. If you wish to change any of the factors, the extensive remarks in the program should make modification fairly straightforward.
Note for trivia buffs: somewhere along the line an m was dropped out of the spelling of Hammurabi in the Ahl version of the computer program. This error has spread far and wide until a generation of students who have used this program now think that Hammurabi is the incorrect spelling (The original game was Hamurabi.bas, as back in those days, filenames were limited to 8 characters).
By: David Ahl; Digital Equipment Corporation
Publication date: 1978
Usage: CC0 1.0 Universal Creative Commons License
In this game you direct the administrator of Sumeria, Hammurabi, how to manage the city. The city initially has 1,000 acres, 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 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 its head very rapidly.
This program was originally written in Focal at DEC; author unknown. David Ahl converted it to BASIC and added the 10-year performance assessment. If you wish to change any of the factors, the extensive remarks in the program should make modification fairly straightforward.
Note for trivia buffs: somewhere along the line an m was dropped out of the spelling of Hammurabi in the Ahl version of the computer program. This error has spread far and wide until a generation of students who have used this program now think that Hammurabi is the incorrect spelling (The original game was Hamurabi.bas, as back in those days, filenames were limited to 8 characters).
PROGRAM CODE:
01 RANDOMIZE TIMER
02 REM *** LINE 03 IS FOR QB64 ONLY
03 SCREEN NEWIMAGE(600, 800, 32)
10 PRINT TAB(32); "HAMURABI"
20 PRINT TAB(15); "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT
40 PRINT
50 PRINT
80 PRINT "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA"
90 PRINT "FOR A TEN-YEAR TERM OF OFFICE.": PRINT
95 D1 = 0: P1 = 0
100 Z = 0: P = 95: S = 2800: H = 3000: E = H - S
110 Y = 3: A = H / Y: I = 5: Q = 1
210 D = 0
215 PRINT: PRINT
216 PRINT "HAMURABI: I BEG TO REPORT TO YOU, ": Z = Z + 1
217 PRINT "IN YEAR ";Z;", ";D;" PEOPLE STARVED, ";I;" CAME TO THE CITY,"
218 P = P + I
219 PRINT "THE PLAGUE FACTOR = ";Q
220 IF Q > 0 THEN 230
225 P = INT(P / 2): PRINT "A HORRIBLE PLAGUE STRUCK: HALF THE PEOPLE DIED."
230 PRINT "POPULATION IS NOW" ;P
235 PRINT "THE CITY NOW OWNS";A;" ACRES."
240 PRINT "YOU HARVESTED";Y;" BUSHELS PER ACRE."
250 PRINT "THE RATS ATE";E;" BUSHELS."
260 PRINT "YOU NOW HAVE";S;" BUSHELS IN STORE.": PRINT
270 IF Z = 11 THEN 860
310 C = INT(10 * RND(1)): Y = C + 17
315 PRINT "LAND IS TRADING AT";Y; " BUSHELS PER ACRE."
320 INPUT "HOW MANY ACRES DO YOU WISH TO BUY ";Q
321 IF Q < 0 THEN 850
322 IF Y * Q <= S THEN 330
323 GOSUB 710
324 GOTO 320
330 IF Q = 0 THEN 340
335 A = A + Q: S = S - Y * Q: C = 0: GOTO 400
340 INPUT "HOW MANY ACRES DO YOU WISH TO SELL ";Q
341 IF Q < 0 THEN 850
342 IF Q < A THEN 350
343 GOSUB 720
344 GOTO 340
350 A = A - Q
400 S = S + Y * Q: C = 0
410 INPUT "HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE ";Q
412 IF Q < 0 THEN 850
418 REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
420 IF Q <= S THEN 430
421 GOSUB 710
422 GOTO 410
430 S = S - Q: C = 1
435 REM
440 INPUT "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED ";D
441 IF D = 0 THEN 511
442 IF D < 0 THEN 850
444 REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
445 IF D <= A THEN 450
446 GOSUB 720
447 GOTO 440
449 REM *** ENOUGH GRAIN FOR SEED?
450 IF INT(D / 2) <= S THEN 455
452 GOSUB 710
453 GOTO 440
454 REM *** ENOUGH PEOPLE TO TEND THE CROPS?
455 IF D < 10 * P THEN 510
460 PRINT "BUT YOU HAVE ONLY ";P;" PEOPLE TO TEND THE FIELDS! NOW THEN,"
470 GOTO 440
510 S = S - INT(D / 2)
511 GOSUB 800
515 REM *** A BOUNTIFUL HARVEST!
520 Y = C: H = D * Y: E = 0: GOSUB 800
521 IF INT(C / 2) <> C / 2 THEN 530
523 REM *** RATS ARE RUNNING WILD!!
525 E = INT(S / C)
530 S = S - E + H
531 GOSUB 800
532 REM *** LETS HAVE SOME BABIES
533 I = INT(C * (20 * A + S) / P / 100 + 1)
539 REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
540 C = INT(Q / 20)
541 REM *** HORROS, A 15% CHANCE OF PLAGUE
542 Q = INT(10 * (2 * RND(1) - .3))
550 IF P < C THEN 210
551 REM *** STARVED 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
560 PRINT: PRINT "YOU STARVED ";D; " PEOPLE IN ONE YEAR!!!"
565 PRINT "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY"
566 PRINT "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE"
567 PRINT "ALSO BEEN DECLARED NATIONAL FINK!!!!"
568 GOTO 990
710 PRINT "HAMURABI: THINK AGAIN. YOU HAVE ONLY"
711 PRINT S; " BUSHELS OF GRAIN. NOW THEN,"
712 RETURN
720 PRINT "HAMURABI: THINK AGAIN. YOU OWN ONLY ";A;" ACRES. NOW THEN,"
730 RETURN
800 C = INT(RND(1) * 5) + 1
801 RETURN
850 PRINT: PRINT "HAMURABI: I CANNOT DO WHAT YOU WISH."
855 PRINT "GET YOURSELF ANOTHER STEWARD!!!!!"
857 GOTO 990
860 PRINT "IN YOUR 10-YEAR TERM OF OFFICE, ";P1;" PERCENT OF THE"
861 PRINT "POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF"
862 PRINT D1; " PEOPLE DIED!!"
865 L = A / P
870 PRINT "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH"
875 PRINT L;" ACRES PER PERSON.": PRINT
880 IF P1 > 33 THEN 565
885 IF L < 7 THEN 565
890 IF P1 > 10 THEN 940
892 IF L < 9 THEN 940
895 IF P1 > 3 THEN 960
896 IF L < 10 THEN 960
900 PRINT "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND"
905 PRINT "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!"
910 GOTO 990
940 PRINT "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV."
945 PRINT "THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,"
950 PRINT "FRANKLY, HATE YOUR GUTS!!"
955 GOTO 990
960 PRINT "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT"
965 PRINT "REALLY WASN'T TOO BAD AT ALL. ";INT(P * .8 * RND(1));" PEOPLE"
970 PRINT "WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR"
975 PRINT "TRIVIAL PROBLEMS."
990 PRINT: FOR N = 1 TO 10: PRINT CHR$(7);: NEXT N
995 PRINT "SO LONG FOR NOW.": PRINT
999 END
02 REM *** LINE 03 IS FOR QB64 ONLY
03 SCREEN NEWIMAGE(600, 800, 32)
10 PRINT TAB(32); "HAMURABI"
20 PRINT TAB(15); "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT
40 PRINT
50 PRINT
80 PRINT "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA"
90 PRINT "FOR A TEN-YEAR TERM OF OFFICE.": PRINT
95 D1 = 0: P1 = 0
100 Z = 0: P = 95: S = 2800: H = 3000: E = H - S
110 Y = 3: A = H / Y: I = 5: Q = 1
210 D = 0
215 PRINT: PRINT
216 PRINT "HAMURABI: I BEG TO REPORT TO YOU, ": Z = Z + 1
217 PRINT "IN YEAR ";Z;", ";D;" PEOPLE STARVED, ";I;" CAME TO THE CITY,"
218 P = P + I
219 PRINT "THE PLAGUE FACTOR = ";Q
220 IF Q > 0 THEN 230
225 P = INT(P / 2): PRINT "A HORRIBLE PLAGUE STRUCK: HALF THE PEOPLE DIED."
230 PRINT "POPULATION IS NOW" ;P
235 PRINT "THE CITY NOW OWNS";A;" ACRES."
240 PRINT "YOU HARVESTED";Y;" BUSHELS PER ACRE."
250 PRINT "THE RATS ATE";E;" BUSHELS."
260 PRINT "YOU NOW HAVE";S;" BUSHELS IN STORE.": PRINT
270 IF Z = 11 THEN 860
310 C = INT(10 * RND(1)): Y = C + 17
315 PRINT "LAND IS TRADING AT";Y; " BUSHELS PER ACRE."
320 INPUT "HOW MANY ACRES DO YOU WISH TO BUY ";Q
321 IF Q < 0 THEN 850
322 IF Y * Q <= S THEN 330
323 GOSUB 710
324 GOTO 320
330 IF Q = 0 THEN 340
335 A = A + Q: S = S - Y * Q: C = 0: GOTO 400
340 INPUT "HOW MANY ACRES DO YOU WISH TO SELL ";Q
341 IF Q < 0 THEN 850
342 IF Q < A THEN 350
343 GOSUB 720
344 GOTO 340
350 A = A - Q
400 S = S + Y * Q: C = 0
410 INPUT "HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE ";Q
412 IF Q < 0 THEN 850
418 REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
420 IF Q <= S THEN 430
421 GOSUB 710
422 GOTO 410
430 S = S - Q: C = 1
435 REM
440 INPUT "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED ";D
441 IF D = 0 THEN 511
442 IF D < 0 THEN 850
444 REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
445 IF D <= A THEN 450
446 GOSUB 720
447 GOTO 440
449 REM *** ENOUGH GRAIN FOR SEED?
450 IF INT(D / 2) <= S THEN 455
452 GOSUB 710
453 GOTO 440
454 REM *** ENOUGH PEOPLE TO TEND THE CROPS?
455 IF D < 10 * P THEN 510
460 PRINT "BUT YOU HAVE ONLY ";P;" PEOPLE TO TEND THE FIELDS! NOW THEN,"
470 GOTO 440
510 S = S - INT(D / 2)
511 GOSUB 800
515 REM *** A BOUNTIFUL HARVEST!
520 Y = C: H = D * Y: E = 0: GOSUB 800
521 IF INT(C / 2) <> C / 2 THEN 530
523 REM *** RATS ARE RUNNING WILD!!
525 E = INT(S / C)
530 S = S - E + H
531 GOSUB 800
532 REM *** LETS HAVE SOME BABIES
533 I = INT(C * (20 * A + S) / P / 100 + 1)
539 REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
540 C = INT(Q / 20)
541 REM *** HORROS, A 15% CHANCE OF PLAGUE
542 Q = INT(10 * (2 * RND(1) - .3))
550 IF P < C THEN 210
551 REM *** STARVED 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
560 PRINT: PRINT "YOU STARVED ";D; " PEOPLE IN ONE YEAR!!!"
565 PRINT "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY"
566 PRINT "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE"
567 PRINT "ALSO BEEN DECLARED NATIONAL FINK!!!!"
568 GOTO 990
710 PRINT "HAMURABI: THINK AGAIN. YOU HAVE ONLY"
711 PRINT S; " BUSHELS OF GRAIN. NOW THEN,"
712 RETURN
720 PRINT "HAMURABI: THINK AGAIN. YOU OWN ONLY ";A;" ACRES. NOW THEN,"
730 RETURN
800 C = INT(RND(1) * 5) + 1
801 RETURN
850 PRINT: PRINT "HAMURABI: I CANNOT DO WHAT YOU WISH."
855 PRINT "GET YOURSELF ANOTHER STEWARD!!!!!"
857 GOTO 990
860 PRINT "IN YOUR 10-YEAR TERM OF OFFICE, ";P1;" PERCENT OF THE"
861 PRINT "POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF"
862 PRINT D1; " PEOPLE DIED!!"
865 L = A / P
870 PRINT "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH"
875 PRINT L;" ACRES PER PERSON.": PRINT
880 IF P1 > 33 THEN 565
885 IF L < 7 THEN 565
890 IF P1 > 10 THEN 940
892 IF L < 9 THEN 940
895 IF P1 > 3 THEN 960
896 IF L < 10 THEN 960
900 PRINT "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND"
905 PRINT "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!"
910 GOTO 990
940 PRINT "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV."
945 PRINT "THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,"
950 PRINT "FRANKLY, HATE YOUR GUTS!!"
955 GOTO 990
960 PRINT "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT"
965 PRINT "REALLY WASN'T TOO BAD AT ALL. ";INT(P * .8 * RND(1));" PEOPLE"
970 PRINT "WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR"
975 PRINT "TRIVIAL PROBLEMS."
990 PRINT: FOR N = 1 TO 10: PRINT CHR$(7);: NEXT N
995 PRINT "SO LONG FOR NOW.": PRINT
999 END