# Hamurabi # Converted from the original FOCAL program and modified # for EDUSYSTEM 70 by David Ahl, Digital. # Modified for 8K Microsoft BASIC by Peter Turnbull. # Then translated to C# by Bill Lange on codeproject.com. # And now it is in Unicon. class Babylon ( Z, # Year D, # People died this turn D1, # People died, cumulative I, # Immigrants P, # Population P1, # Starvation percentage A, # Acres Y, # Yield E, # Eaten S, # Store C, # Random yearly yield modifier Q, # Input L, # Acres per person H ) method play() repeat { report() buy() sell() plant() harvest() } end method report() write("\n\nHamurabi: I beg to report to you,") Z +:= 1 write("in year ", Z, ", ", D, " people starved; ", I, " came to the city.") P +:= I if Q <= 0 then { P /:= 2 write("A horrible plague struck! Half the people died.") } write("Population is now " , P, ". The city now owns " , A , " acres.") write("You harvested ", Y, " bushels per acre. Rats ate ", E, " bushels.") write("You now have " , S , " bushels in store.\n") if Z == 11 then evaluate() end method buy() C := ?11-1 Y := C + 17 write("Land is trading at " , Y , " bushels per acre.") repeat { writes("How many acres do you wish to buy? ") Q := integer(read()) if Q < 0 then finish("quit") else if Y * Q <= S then return else { write("Hamurabi: think again. You have only ", S) write(" bushels of grain. Now then,") } } end method sell() if Q == 0 then { repeat { writes("How many acres do you wish to sell? ") Q := integer(read()) if Q < 0 then finish("quit") else if Q < A then { A -:= Q; S +:= Y * Q; C := 0 write() break } else { write("Hamurabi: think again. You own only " , A , " acres. Now then,") } } } else { A +:= Q; S -:= Y * Q; C := 0 write() } repeat { writes("How many bushels do you wish to feed your people? ") Q := integer(read()) if Q < 0 then finish("quit") else { # Trying to use more grain than in the silos? if Q <= S then break else { write("Hamurabi: think again. You have only") write(S , " bushels of grain. Now then,") } } S -:= Q C := 1 write() } end method plant() repeat { writes("How many acres do you wish to plant with seed? ") D := integer(read()) if D == 0 then return else if D < 0 then finish("quit") # TRYING TO PLANT MORE ACRES THAN YOU OWN? else if D <= A then { # ENOUGH GRAIN FOR SEED? if D / 2 < S then { # ENOUGH PEOPLE TO TEND THE CROPS? if D < 10 * P then { S -:= D / 2 return } else { write("but you have only " , P , " people to tend the fields. Now then,") next } } else { write("Hamurabi: think again. You have only ", S, " bushels of grain. Now then,") next } break } else { write("Hamurabi: think again. You own only " , A , " acres. _ Now then,") } } end method harvest() C := integer(?0 * 5 + 1) # A bountiful harvest!! Y := C; H := D * Y; E := 0 C := integer(?0 * 5 + 1) if C % 2 = 0 then { # THE RATS ARE RUNNING WILD!! E := S / C } S := S - E + H C := ?0 * 5 + 1 # Lets have some babies I := integer((C * (20 * A + S) / P / 100 + 1)) # How many people had full tummies? C := integer(Q / 20) # Horrors, a 15% chance of plague Q := integer(10 * (2 * ?0 - .3)) if P < C then { D:= 0; return } else { # Starve enough for impeachment? D := P - C if D > .45 * P then { write("\nYou starved " , D , " people in one year!!!") finish("fink") } else { P1 := ((Z - 1) * P1 + D * 100 / P) / Z P := C D1 +:= D return } } end method evaluate() write("In your 10-year term of office, " , P1 , " percent of the") write("population starved per year on average, i.e., a total of") write(D1 , " people died!!") L := A / P write("You started with 10 acres per person and ended with ", L , " acres per person.\n") if P1 > 33 | L < 7 then finish("fink") else if P1 > 10 | L < 9 then finish("nero") else if P1 > 3 | L < 10 then finish("notbad") else finish("fantastic") end method finish(as) case as of { "quit": { write("Hamurabi: I cannot do what you wish.") write("Get yourself another steward!!!!!") } "fantastic": { write("A fantastic performance!!! Charlemagne, Disraeli,") write("and Jefferson combined could not have done better!") } "fink": { write("Due to this extreme mismanagement you have not only") write("been impeached and thrown out of office but you have") write("also been declared 'national fink' !!") } "nero": { write("Your heavy-handed performance smacks of Nero and Ivan IV.") write("The people (remaining) find you an unpleasant ruler, and,") write("frankly, hate your guts!") } "not bad": { write("Your performance could have been somewhat better, but really") write("wasn't too bad at all. ", integer(P * .8 * ?0) , " people") write("would dearly like to see you assassinated but we all have") write("our trivial problems.") } } stop("So long for now.") end initially Z := D := I := P := A := Y := E := S := C := Q := D1 := P1 := Z := 0 P := 95 S := 2800 H := 3000 E := H - S Y := 3 A := H / Y I := 5 Q := 1 write("Try your hand at governing ancient Sumeria\n_ successfully for a 10 year term of office.") end procedure main() Babylon().play() end