Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.     REM
  2.     REM --- Tiny BASIC Interpreter and Compiler Project
  3.     REM --- Hammurabi Demonstration Game
  4.     REM
  5.     REM --- Released as Public Domain by Damian Gareth Walker, 2019
  6.     REM --- Created: 25-Aug-2019
  7.     REM
  8.  
  9.     REM --- Variable List
  10.     REM
  11.     REM A - A random number returned by the Random Number Generator
  12.     REM B - The amount of land bought/sold by the player
  13.     REM D - The number of people who died of starvation
  14.     REM E - Average percentage of deaths
  15.     REM F - The amount of grain fed to the people
  16.     REM G - The quantity of stored grain
  17.     REM I - The number of immigrants on a given turn
  18.     REM L - How much land the city owns
  19.     REM M - Maximum land that can be planted
  20.     REM P - The number of people in the city
  21.     REM R - The amount of grain eaten by rats
  22.     REM S - The amount of grain planted as seed
  23.     REM T - Time played
  24.     REM V - The value of land per acre
  25.     REM Y - The grain yield of each piece of land
  26.     REM Z - The random number seed
  27.  
  28.     REM --- Initialise the random number seed
  29.     PRINT "Think of a number."
  30.     INPUT Z
  31.  
  32.     REM --- Initialise the game
  33.     LET D=0
  34.     LET E=0
  35.     LET G=2800
  36.     LET I=5
  37.     LET L=1000
  38.     LET P=100
  39.     LET R=200
  40.     LET T=1
  41.     LET Y=3
  42.  
  43.     REM --- Print the report
  44.  15 PRINT "Hammurabi, I beg to report to you,"
  45.     PRINT "In year ",T,", ",D," people starved,"
  46.     PRINT "and ",I," came to the city."
  47.     PRINT "You harvested ",Y," bushels of grain per acre."
  48.     PRINT "Rats destroyed ",R," bushels."
  49.     PRINT "Population is now ",P,","
  50.     PRINT "and the city owns ",L," acres of land."
  51.     PRINT "You have ",G," bushels of grain in store."
  52.     IF D>P*45/100 THEN GOTO 100
  53.     IF T=11 THEN GOTO 90
  54.  
  55.     REM --- Buy land
  56.     GOSUB 250
  57.     LET V=17+A-A/10*10
  58.     PRINT "Land is trading at ",V," bushels per acre."
  59.  30 PRINT "How many acres do you wish to buy (0-",G/V,")?"
  60.     INPUT B
  61.     IF B>G/V THEN GOTO 30
  62.     IF B>0 THEN GOTO 40
  63.  
  64.     REM --- Sell land
  65.  35 PRINT "How many acres do you wish to sell (0-",L,")?"
  66.     INPUT B
  67.     IF B>L THEN GOTO 35
  68.     LET B=-B
  69.  
  70.     REM --- Feed the people
  71.  40 PRINT "How many bushels to feed the people (0-",G-B*V,")?"
  72.     INPUT F
  73.     IF F>=0 THEN IF F<=G-B*V THEN GOTO 45
  74.     GOTO 40
  75.  
  76.     REM --- Plant with seed
  77.  45 LET M=2*(G-F-B*V)
  78.     IF 10*P<M THEN LET M=10*P
  79.     IF L+B<M THEN LET M=L+B
  80.  50 PRINT "How many acres do you wish to plant with seed (0-",M,")?"
  81.     INPUT S
  82.     IF S>M THEN GOTO 50
  83.  
  84.     REM --- Work out the result
  85.     LET L=L+B
  86.     LET G=G-B*V-F-S/2
  87.  
  88.     REM Yield
  89.     GOSUB 250
  90.     LET Y=1+A-A/5*5
  91.  
  92.     REM Rats
  93.     GOSUB 250
  94.     LET A=1+A-A/5*5
  95.     LET R=0
  96.     IF A>2 THEN GOTO 70
  97.     GOSUB 250
  98.     IF G>0 THEN LET R=1+A-A/G*G
  99.  
  100.     REM Recalculate grain
  101.  70 LET G=G+S*Y-R
  102.     IF G<0 THEN LET G=0
  103.  
  104.     REM Immigration/Birth
  105.     GOSUB 250
  106.     LET A=1+A-A/5*5
  107.     LET I=A*(L+S/20)/P/5+1
  108.  
  109.     REM Feeding the people
  110.     LET D=0
  111.     IF P<=F/20 THEN GOTO 80
  112.     LET D=P-F/20
  113.     LET E=((T-1)*E+(100*D/P))/(T+1)
  114.  80 LET P=P-D+I
  115.     IF P<=0 THEN GOTO 210
  116.     LET T=T+1
  117.  
  118.     REM Back to report
  119.     PRINT ""
  120.     GOTO 15
  121.  
  122.     REM --- Evaluation
  123.  90 PRINT "Your reign ends after ",T-1," years."
  124.     PRINT "You leave your city with ",P," people."
  125.     PRINT "You have ",L," acres of land to support them."
  126.     PRINT G," bushels of grain remain in store."
  127.     PRINT ""
  128.     IF E<=3 THEN IF L/P>=10 THEN GOTO 110
  129.     IF E<=10 THEN IF L/P>=9 THEN GOTO 120
  130.     IF E<=33 THEN IF L/P>=7 THEN GOTO 130
  131.  
  132.     REM --- Terrible performance - including premature end
  133. 100 PRINT "Your performance has been so terrible that"
  134.     PRINT "you were driven from your throne after ",T," years!"
  135.     END
  136.  
  137.     REM --- Best performance
  138. 110 PRINT "Your expert statesmanship is worthy of Hammurabi himself!"
  139.     PRINT "The city will honour your memory for all eternity."
  140.     END
  141.  
  142.     REM --- Average performance
  143. 120 PRINT "Your competent rule is appreciated by your citizens."
  144.     PRINT "They will remember you fondly for some time to come."
  145.     END
  146.  
  147.     REM --- Poor performance
  148. 130 PRINT "Your mismanagement left your city in a very poor state."
  149.     PRINT "Your incompetence and oppression will not be missed by your people."
  150.     END
  151.  
  152.     REM --- Everybody starved
  153. 210 PRINT "You have starved your entire kingdom to death!"
  154.     END
  155.  
  156.     REM --- Random Number Generator
  157. 250 LET Z=5*Z+35
  158.     LET Z=Z-Z/4096*4096
  159.     LET A=Z
  160.     RETURN
  161.