Here I have changed the game so that it's more modular, I have expanded the variable names so they are understandable, and it should me easy to upgrade.
Also, I like the additions that Henko put in, such as splitting the population between kids and adults. I may add men and women, and it may be sexist today, but back then parents with children, the women spent less time harvesting and more time raising children. This added to the game can affect how many acres can be both planted and harvested, so planning needs to be done accordingly.
And that is just the start of the features and functions that will turn this game into a top of the line strategy and planning game.
Code: Select all
/*
Program: Hamurabi – v1.10
Written by George McGinn – March 8, 2018.
Updated by George McGinn - October 19, 2018
HAMMURABI (Or Hamurabi) is a game that requires resource and population management, and was the game that launched other strategy games such as Civilization and Sim City. Written originally in 1967 in DEC's FOCAL language, this version is a merge of the Altair's 4K BASIC and the game update written by David Ahl.
In Version 2 I plan to expand the game to include more natural disasters and methods to attempt mitigating, in advance, these damages, except for the plague. Whether or not mitigating rats is sucessful, the plague may have contaminated the shipment while in storage, out of the control of Hammarabi's efforts. Unlike the damage caused by rats after the harvest, natural disasters will reduce the production capabilites prior to the harvest, such as making less acres availabe for growing to stunting the growth by reducing the number of barrels per acre.
Screen Input:
Written by George McGinn – March, 2018
This is a very basic screen input that uses a graphical user interface for both input and output display.
UPDATES AND NOTES ON IMPROVEMENTS
—————————————————————————————————
v1.00 - March 8, 2018 (George McGinn)
Initial program based on the game written in 1973 (BASIC version. Originally written in
FOCAL in 1968). Future updates will add a GUI so that the game takes on some compleity
while maintaining the Hamurabi game play.
——————————————————————————————————————————
v1.01 - October 19, 2018 (George McGinn)
Fixed the RND generator calculation pertaining to damage due to rats in techBASIC.
SmartBASIC, the random generator works differently depending on which CLASS you
use. Also renamed all the variables to names that make sense (back in 1963 BASIC
could only handle variables with either a single character or a character and number).
NOTE: Now thinking about adding pestilent damage as insects do damages crops far
worse that rats do. Rats cause more damage if grain is shipped and causes plagues.
Review the game to possibly add an increase to the chance of a plague based on how
much damage rats cause.
——————————————————————————————————————————
v1.10 - October 19, 2018 (George McGinn)
Added a separate routine to take in pestilent damage (all inclusive) damaging
crops before they are harvested. This is accomplished by reducing the number of
acres planted before calculating the harvest and damage caused by rats.
——————————————————————————————————————————
ABOUT HAMRURABI
---------------
Hamurabi is a text-based strategy video game centered on resource management in which the player, identified in the text as the ancient Babylonian King Hammurabi, enters numbers in response to questions posed by the game. The resources that the player must manage are people, land, and bushels of grain. These are managed over the course of ten rounds, each of which represents a year. Each person can farm a set amount of land, which produces grain. Grain, in turn, can be used to feed people, who otherwise die the following round, or planted for the following year's crop. The player may also buy or sell land to their neighbors each turn in exchange for grain. Each round begins with an adviser stating "Hamurabi: I beg to report to you" the current status of the city, including the prior year's harvest and change in population, followed by a series of questions as to how many bushels of grain to spend on land, seeds, and feeding the people.
The game's variations are driven by random numbers: the price of land is randomly decided each round from between 17 to 26 bushels per acre, the amount of bushels generated each round is randomly decided, random amounts of bushels are eaten by rats, and new people come to the city each year in random amounts. Each year also presents the possibility of a plague reducing the population by half. The game ends after ten rounds, or earlier if the entire population of the city dies or at least 45 percent of the people starve in a single round.
The end-game appraisal, added in the 1973 version of the game, compares the player to historical rulers—such as "Your heavy-handed performance smacks of Nero and Ivan IV."
The main draw of this game is that you must learn how to play it while playing it. Unless you wrote the code or have it available, so much of it is randomized that even using the code as a guide, the results are unpredictable.
King Hammurabi's was born in 1810 bc, and his reign lasted 42 years from 1792 BC til his death in 1750 BC at the age of 60. He is well known as the first ruler to codify laws for his kingdom. however, the Code of Hammurabi is not the earliest surviving law code; it is predated by the Code of Ur-Nammu, the Laws of Eshnunna, and the Code of Lipit-Ishtar. Nonetheless, the Code of Hammurabi shows marked differences from these earlier law codes and ultimately proved more influential. For more information, see: https://en.m.wikipedia.org/wiki/Hammurabi
PSALM WRITTEN IN THE WORDS OF HAMMURABI AFTER HIS DEATH:
————————————————————————————————————————————————————————
I am the king, the brace that grasps wrongdoers, that makes people of one mind,
I am the great dragon among kings, who throws their counsel in disarray,
I am the net that is stretched over the enemy,
I am the fear-inspiring, who, when lifting his fierce eyes, gives the disobedient the death sentence,
I am the great net that covers evil intent,
I am the young lion, who breaks nets and scepters,
I am the battle net that catches him who offends me,
I am Hammurabi, the king of justice.
*/
GRAPHICS
OPTION ANGLE DEGREES
OPTION BASE 1
'*** SET TOOLBAR OFF
OPTION KEYBOARD ON
GET SCREEN SIZE sw,sh
GRAPHICS CLEAR .4,.4,.4
SET ORIENTATION LANDSCAPE
GET SCREEN SIZE W,H
RANDOMIZE TIMER
dev$=DEVICE_TYPE$()
iostest=1 '*** set to 1 to test other iOS devices on iPad
IF iostest THEN
dev$=""
W=667!H=375 '*** to test iPhone 6
ENDIF
'*** Needed to provide compatability with other modules (from other programmers)
sw=W!sh=H '*** sw,sh is Screen Width, Height
'*** scale factor for other iOS devices
ratw=W/1024!rath=H/768!vadj=0!hadj=20!cr$=CHR$(10)
.rw=ratw!.rh=rath
IF dev$="iPad" THEN
hm=4 '*** horizontal margin
vm=100 '*** vertical margin
heightshift=0!titleshift=0!tvshift=0!bvshift=30
ELSE
hm=4*ratw '*** horizontal margin
vm=130*rath-20 '*** vertical margin
heightshift=20!titleshift=25!tvshift=10!bvshift=10
ENDIF
REM *** For the About Box: https://en.m.wikipedia.org/wiki/Hammurabi
PRINT TAB(32);"HAMURABI"
PRINT
PRINT "You are the ruler of the ancient kingdom of Sumeria."
PRINT "Your people call you 'Hamurabi the Wise'."
PRINT
PRINT "Your task is for the next 10 years is to develop"
PRINT "a stable economy by the wise management of your"
PRINT "resources. You will be beset from time to time"
PRINT "by natural events."
PRINT
PRINT "The only help I can give you is the fact that it"
PRINT "takes 1 bushel of grain as seed to plant two acres."
PRINT
PRINT "May you judge well, alknowing Hamurabi!"
PRINT
PRINT "***********HAMURABI IS HERE***********"
PRINT
HamurabiInit:
STARVED=0 '*** D=0
PEOPLE_DIED=0 '*** D1=0
PCT_STARVED=0 '*** P1=0
YEAR=0 '*** Z=0
POPULATION=95 '*** P=95
BUSHELS=2800 '*** S=2800
HARVESTED=3000 '*** H=3000
RATS_ATE=HARVESTED-BUSHELS '*** E=H-S
PESTILENCE=0 '*** NEW FIELD
PRICE=3 '*** Y=3
ACRES=HARVESTED/PRICE '*** A=H/Y
IMMIGRATED=5 '*** I=5
C=1 '*** C=1 VARIABLE USED FOR ALL RANDOM NUMBER GENERATORS
PlayGame:
PRINT
PRINT
PRINT "HAMURABI, I beg to report to you"!
PRINT
YEAR=YEAR+1
PRINT "In year "&YEAR&", "&STARVED&" People starved, "&IMMIGRATED&" Came into the city."
POPULATION=POPULATION+IMMIGRATED
CheckForPlague:
'*** check for plague and if found, reduce population by 1/2. (15% chance of plague)
' PI=INT(10*(2*RND(1)-.3)) REM *** Random generator for TechBASIC
PI=RND(100)*.10
'*** PRINT "(DEBUG): PLAGUE INDICATOR ="&"##.##":PI
PRINT
IF PI>=8.5 AND YEAR>1 THEN
PLAGUE=INT(POPULATION/2)!POPULATION=PLAGUE
PRINT "A horrible plague struck! Half the people died."
PRINT "Half ("&PLAGUE&") died of the plague."
END IF
Display_Population:
PRINT "Our Population is now "&POPULATION
PRINT "The city owns "&ACRES&" acres, "
PRINT "You havested "&PRICE&" bushels per acre"
PRINT "Rats destroyed "&RATS_ATE&" bushels. "
PRINT "You have "&BUSHELS&" bushels in storage."
PRINT
IF YEAR=11 THEN GOTO PlayEvaluation
C=INT(10*RND(1))
PRICE=C+17
PRINT "Land is trading at ";PRICE;" bushels per acre."
BuyLand:
INPUT "How much land (in acres) do you wish to buy? ":ACRES_BUY
PRINT "How much land (in acres) do you wish to buy? ";ACRES_BUY
IF ACRES_BUY<0 THEN GOTO FedUp
IF PRICE*ACRES_BUY<=BUSHELS THEN
IF ACRES_BUY=0 THEN GOTO SellLand
ACRES=ACRES+ACRES_BUY
BUSHELS=BUSHELS-PRICE*ACRES_BUY
C=0
PRINT
GOTO FeedPopulation
END IF
GOSUB NotEnoughGrain
GOTO BuyLand
SellLand:
INPUT "How many acres of land do you wish to sell? ":ACRES_SELL
PRINT "How many acres of land do you wish to sell? ";ACRES_SELL
IF ACRES_SELL<0 THEN GOTO FedUp
IF ACRES_SELL<ACRES THEN
ACRES=ACRES-ACRES_SELL
BUSHELS=BUSHELS+PRICE*ACRES_SELL
C=0
GOTO FeedPopulation
END IF
GOSUB NotEnoughAcres
GOTO SellLand
FeedPopulation:
INPUT "How many bushels do you wish to set aside for food? ":BUSHELS_FEED
PRINT "How many bushels do you wish to set aside for food? ";BUSHELS_FEED
IF BUSHELS_FEED<0 THEN GOTO FedUp
IF BUSHELS_FEED=0 THEN
GOSUB NotEnoughGrain
GOTO FeedPopulation
END IF
REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
IF BUSHELS_FEED<=BUSHELS THEN
BUSHELS=BUSHELS-BUSHELS_FEED
C=1
PRINT
GOTO AcresToPlant
END IF
GOSUB NotEnoughGrain
GOTO FeedPopulation
AcresToPlant:
INPUT "How many acres do you wish to plant? ":ACRES_PLANTED
PRINT "How many acres do you wish to plant? ";ACRES_PLANTED
REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
IF ACRES_PLANTED=0 THEN GOTO HarvestCrops
IF ACRES_PLANTED<0 THEN GOTO FedUp
REM *** ENOUGH GRAIN FOR SEED (TWO BUSHELS PER ACRE)?
IF ACRES_PLANTED<=ACRES THEN
IF INT(ACRES_PLANTED/2)<=BUSHELS THEN
REM *** ENOUGH PEOPLE TO TEND THE CROPS?
IF ACRES_PLANTED<10*POPULATION THEN
BUSHELS=BUSHELS-INT(ACRES_PLANTED/2)
GOTO HarvestCrops
ELSE
PRINT "But you only have ";POPULATION;" people to tend the fields!, Now then, "
GOTO AcresToPlant
END IF
ELSE
GOSUB NotEnoughGrain
GOTO AcresToPlant
END IF
END IF
GOSUB NotEnoughAcres
GOTO AcresToPlant
HarvestCrops:
REM *** A BOUNTIFUL HARVEST!
GOSUB Randomizer
PRICE=C
HARVESTED=ACRES_PLANTED*PRICE
RATS_ATE=0
GOSUB Randomizer
IF INT(C/2)<>C/2 THEN GOTO PopulationControl
REM *** RATS ARE RUNNING WILD!!
RATS_ATE=INT(BUSHELS/C)
PopulationControl:
BUSHELS=BUSHELS-RATS_ATE+HARVESTED
GOSUB Randomizer
REM *** LET'S HAVE SOME BABIES
IMMIGRATED=INT(C*(20*ACRES+BUSHELS)/POPULATION/100+1)
REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
C=INT(BUSHELS_FEED/20)
REM *** HORROS, A 15% CHANCE OF PLAGUE
' PI=INT(10*(2*RND(1)-.3))
PI=RND(10)
IF POPULATION<C THEN
STARVED=0
GOTO PlayGame
END IF
REM *** STARVED ENOUGH FOR IMPEACHMENT?
STARVED=POPULATION-C
IF STARVED>.45*POPULATION THEN GOTO StarvedMSG
PCT_STARVED=((YEAR-1)*PCT_STARVED+STARVED*100/POPULATION)/YEAR
POPULATION=C
PEOPLE_DIED=PEOPLE_DIED+STARVED '*** D1=D1+D
GOTO PlayGame
StarvedMSG:
PRINT
PRINT "You starved "&STARVED&" people in this year!!!"
ExtremeMismangement:
PRINT "Due to extreme mismanagement you have been impeached and thrown out of office."
PRINT "You have failed to honor your promise or lacked courage or commitment."
PRINT "The people have declared you a National Fink!!!!"
GOTO endProg
NotEnoughGrain:
PRINT " HAMURABI: Think again. You have only"
PRINT BUSHELS&" bushels of grain. Now then,"
RETURN
NotEnoughAcres:
PRINT "HAMURABI: Think again. You own only "&ACRES&" acres. Now Then,"
RETURN
Randomizer:
C=INT(RND(1)*5)+1
RETURN
FedUp:
PRINT
PRINT "HAMURABI: I cannot do what you wish."
PRINT "Get yourself another steward!!!!!"
GOTO endProg
PlayEvaluation:
PRINT "In your 10-year term of office,"&"##.##":PCT_STARVED;
PRINT " percent of the"
PRINT "population starved per year on average, i.e. a total of"
PRINT PEOPLE_DIED&" people died!!"
PRINT
DeterminePlay:
LAND_PER_PERSON=ACRES/POPULATION
PRINT "You started with 10 acres per person and ended with"
PRINT LAND_PER_PERSON&" arces per person."
PRINT
IF PCT_STARVED>33 THEN GOTO ExtremeMismangement
IF LAND_PER_PERSON<7 THEN GOTO ExtremeMismangement
IF PCT_STARVED>10 THEN GOTO HeavyHanded
IF LAND_PER_PERSON<9 THEN GOTO HeavyHanded
IF PCT_STARVED>3 THEN GOTO MediocurePlay
IF LAND_PER_PERSON<10 THEN GOTO MediocurePlay
PRINT "A fantastic performance! Charlemange, Disraeli, and"
PRINT "Jefferson combined could not have done better!"
GOTO endProg
HeavyHanded:
PRINT "Your heavy-handed performance smacks of Nero and Ivan IV."
PRINT "The remaining people find you an unpleasant ruler, and,"
PRINT "frankly, hate your guts!!"
GOTO endProg
MediocurePlay:
PRINT "Your performance could have been somewhat better, but"
PRINT "really wasn't too bad at all. "&INT(POPULATION*.8*RND(1))&" people"
PRINT "would dearly like to see you assassinated but we all have our"
PRINT "trivial problems."
endProg:
PRINT
FOR N=1 TO 10
PRINT CHR$(7);
NEXT N
PRINT "So long, for now."
PRINT
END