'Hamuradi.bas for SmallBASIC 0.12.8 [B+=MGA] 2017-01-24 translated to QB64 B+ 2019-07-21
' translated from Hamuradi.bas for Tinycat BASIC by felixv7
' whose source to this classic was
' http://apollowebworks.com/russell/samples/hamurabi.html
DIM SHARED land
, grain
, starved
, immigrants
, population
, rats
, planted
, yield
, price
, year
, plague
, buying
, selling
, fed
land = 1000
grain = 2800
starved = 10
immigrants = 5
population = 100
rats = 200
planted = 300
year = 1
plague = 0
update 'report to H
decisions 'H input
calcStats 'recalc conditions
PRINT "Hamurabi, I have bad news. Everyone is dead." PRINT "The city is lost." PRINT "If only you could try again..."
PRINT "I beg to report that in year "; year
PRINT "The people who starved to death was "; starved
PRINT "The people who came to the city was "; immigrants
PRINT " The population is now "; population
PRINT "The bushels we harvested was "; yield
* planted
PRINT "as bushels of grain per acre was "; yield
PRINT "but bushels destroyed by rats was "; rats
PRINT "This leaves us with the granary bushels "; grain
PRINT "The acres of land owned by the city is "; land
PRINT "The price, bushels per acre, is "; price
INPUT "How much land do you wish to buy? "; buying
land = land + buying
grain = grain - buying * price
PRINT "Very well, we are left with "; grain;
" bushels." PRINT "But, Hamurabi! We don't have enough grain!"
INPUT "How much land do you wish to sell? "; selling
land = land - selling
grain = grain + selling * price
PRINT "Very well, we now have "; grain;
" bushels." PRINT "But, Hamurabi, we only have ", land
, " acres!"
INPUT "How much grain should we feed our people? "; fed
grain = grain - fed
PRINT "But, Hamurabi! We only have ", grain
, " bushels!"
INPUT "How many acres of land should we seed? "; planted
IF planted
<= population
* 10 THEN PRINT "But, Hamurabi! We only have "; population;
" people!" PRINT "But, Hamurabi! We only have "; grain;
" bushels!" PRINT "But, Hamurabi! We only have "; land;
" acres!"
DIM immigrants1
, immigrants2
grain = grain + yield * planted
rats
= INT(RND * (grain
* 0.07)) grain = grain - rats
starved
= population
- INT(fed
/ 20) IF starved
< 0 THEN starved
= 0 population = population - starved
immigrants1
= INT(starved
/ 2) immigrants2
= INT((5 - yield
) * grain
/ 600 + 1) immigrants = immigrants1 + immigrants2
IF immigrants
> 50 THEN immigrants
= 50 IF immigrants
< 0 THEN immigrants
= 0 population = population + immigrants
IF plague
THEN population
= INT(population
/ 2) year = year + 1