HAMURABI Notes -*-org-*- Date: 2011/12/19 Annotated HAMURABI BASIC source (Twenex version line numbering). * Variables |------+------+-------------------------------------------| | Var | Init | Content | |------+------+-------------------------------------------| | D1 | 0 | Total deaths during reign | | P1 | 0 | Average annual percent starvation | | Z | 0 | Report year | | P | 95 | Total population | | S | 2800 | Report bushels in storage | | H | 3000 | Total bushels harvested | | E | 200 | (H-S) Report grain loss to rats | | Y[*] | 3 | 235: Report yield (bsh./acre) | | | | 311: Current land price (bsh./acre) | | | | 515: Harvest yield (bsh./acre) | | A | 1000 | (H/Y) Report acres | | I | 5 | Report immigrants | | Q[*] | 1 | 227: <0 -> plague occurred in report year | | D[*] | 0 | 221: Report starvation deaths | | | | | |------+------+-------------------------------------------| [*] Variable is reused for multiple purposes. * Source ** Banner 10 PRINT TAB(32);"HAMURABI" 20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" 30 PRINT 31 PRINT 32 PRINT 80 PRINT "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA" 90 PRINT "FOR A TEN-YEAR TERM OF OFFICE." 91 PRINT ** Initialization 95 D1=0 96 P1=0 100 Z=0 101 P=95 102 S=2800 103 H=3000 104 E=H-S 110 Y=3 111 A=H/Y 112 I=5 113 Q=1 ** Annual loop Reinitialize starvation death toll each year 20+ bushels per person allocated for food. 210 D=0 *** Annual report 215 PRINT 216 PRINT 217 PRINT "HAMURABI 218 I BEG TO REPORT TO YOU," 219 3 Z=Z+1 220 REM 217-218 ==> 221-222 221 PRINT "IN YEAR";Z;",";D;" PEOPLE STARVED,";I;" CAME TO THE CITY," 222 P=P+I 227 IF Q>0 THEN 230 228 P=INT(P/2) 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 "THE RATS ATE";E;" BUSHELS." 260 PRINT "YOU NOW HAVE ";S;" BUSHELS IN STORE." 261 PRINT Leave main loop after year 11 report. 270 IF Z=11 THEN 860 *** Orders for coming year **** Set land price Land price is a random integer [17,26] 310 C=INT(10*RND(1)) 311 Y=C+17 **** Land purchase Purchase acres check: >= 0, <= <grain in storage> / <price> 312 PRINT "LAND IS TRADING AT";Y;" BUSHELS PER ACRE." 320 PRINT "HOW MANY ACRES DO YOU WISH TO BUY"; 321 INPUT Q 322 IF Q<0 THEN 850 323 REM 322-324 ==> 324-326 324 IF Y*Q<=S THEN 330 325 GOSUB 710 326 GOTO 320 330 IF Q=0 THEN 340 Purchase results: Purch. acres added to owned land, grain in storage reduced by <acres purchased> * <price> 331 A=A+Q 332 S=S-Y*Q 333 C=0 334 GOTO 400 **** Land sale Sale acres check: >= 0, < acres owned 340 PRINT "HOW MANY ACRES DO YOU WISH TO SELL"; 341 INPUT Q 342 IF Q<0 THEN 850 343 REM 342-344 ==> 344-346 344 IF Q<A THEN 350 345 GOSUB 720 346 GOTO 340 Sale results: acres owned reduced by acres sold, grain in storage increased by <acres sold> * <price> 350 A=A-Q 351 S=S+Y*Q 352 C=0 **** Grain for food Food bsh. check: >= 0, <= grain in storage 400 PRINT 410 PRINT "HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE"; 411 INPUT 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 Food allocation result: grain in storage reduced by food allocation 430 S=S-Q 431 C=1 **** Acres to plant 432 PRINT 440 PRINT "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED"; Plant acres check: >= 0, <= acres owned, <= 2 * grain in storage, 441 INPUT D 442 IF D=0 THEN 511 443 REM 442,444-447 ==> 444-448 444 IF D<0 THEN 850 445 REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN? 446 IF D<=A THEN 450 447 GOSUB 720 448 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 *** Determine results for coming year **** Starvation deaths 510 S=S-INT(D/2) **** Grain harvest 511 GOSUB 800 512 REM *** A BOUNTIFUL HARVEST! 515 Y=C 516 H=D*Y 517 E=0 **** Loss to rats 521 GOSUB 800 Rat infestation occurs with 40% chance (C, random [1,5] is even). 522 IF INT(C/2)<>C/2 THEN 530 523 REM *** RATS ARE RUNNING WILD!! 525 E=INT(S/C) 530 S=S-E+H **** Population growth 531 GOSUB 800 532 REM *** LET'S HAVE SOME BABIES 533 I=INT(C*(20*A+S)/P/100+1) **** Food ration population 539 REM *** HOW MANY PEOPLE HAD FULL TUMMIES? 540 C=INT(Q/20) **** Chance of plague 541 REM *** HORROS, A 15% CHANCE OF PLAGUE 542 Q=INT(10*(2*RND(1)-.3)) Loop if no starvation deaths 550 IF P<C THEN 210 *** Collect starvation death statistics 551 REM *** STARVE ENOUGH FOR IMPEACHMENT? 552 D=P-C Impeachment and end game if starvation death toll for year > 45% of population. 553 IF D>.45*P THEN 560 554 REM 553,555 ==> 555-556 555 P1=((Z-1)*P1+D*100/P)/Z 556 P=C 557 D1=D1+D Loop without reinitializing starvation deaths 558 GOTO 215 ** Subroutines *** Impeachment before 10th year message (fall-through) 560 PRINT 561 PRINT "YOU STARVED";D;" PEOPLE IN ONE YEAR!!!" *** Fink-level (1/4) performance message Avg. annual starvation rate > 33% or acres per person < 7 OR starved more than 45% of pop. in any year (impeachment) 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 *** Attempt to use more grain than in storage message For land purch., feed people, planting 710 PRINT "HAMURABI: THINK AGAIN. YOU HAVE ONLY" 712 REM 711-712 ==> 713-714 713 PRINT S;" BUSHELS OF GRAIN. NOW THEN," 714 RETURN *** Attempt to use more land than owned message For land sale, planting 720 PRINT "HAMURABI 721 THINK AGAIN. YOU OWN ONLY";A;" ACRES. NOW THEN," 730 RETURN *** Set C to random integer [1-5] 800 C=INT(RND(1)*5)+1 801 RETURN *** Negative input error message -> end program 850 PRINT 851 PRINT "HAMURABI: I CANNOT DO WHAT YOU WISH." 855 PRINT "GET YOURSELF ANOTHER STEWARD!!!!!" 857 GOTO 990 *** Final summary report 860 PRINT "IN YOUR 10-YEAR TERM OF OFFICE,";P1;" PERCENT OF THE" 862 PRINT "POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF" 865 PRINT D1;" PEOPLE DIED!!" Calculate land acres per person. 866 L=A/P 870 PRINT "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH" 875 PRINT L;" ACRES PER PERSON." 876 PRINT Determine performance level. 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 *** Charlemagne-level (4/4) performance message Average starvation deaths per year <= 3% or acres per person >= 10 900 PRINT "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND" 905 PRINT "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!" 906 GOTO 990 *** Nero-level (2/4) performance message Average starvation deaths per year > 10% or acres per person < 9 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!!" 951 GOTO 990 *** Mid-level (3/4) performance message Average starvation deaths per year > 3% or acres per person < 9 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." ** Program termination 990 PRINT 991 FOR N=1 TO 10 992 PRINT CHR$(7); 993 REM 991 ==> 994 994 NEXT N 995 PRINT "SO LONG FOR NOW." 996 PRINT 999 END