Merge remote-tracking branch 'origin/main'

This commit is contained in:
Tim Buchalka
2022-01-09 06:51:08 +10:30

View File

@@ -1,183 +1,202 @@
def GenRandom(C):
C=int(random()*5)+1
def BadInput850():
print ( "\nHAMURABI: I CANNOT DO WHAT YOU WISH.")
print ( "GET YOURSELF ANOTHER STEWARD!!!!!")
Z=99
def BadInput710(S):
print ( "HAMURABI: THINK AGAIN. YOU HAVE ONLY")
print ( S,"BUSHELS OF GRAIN. NOW THEN,")
def BadInput720(A):
print ( "HAMURABI: THINK AGAIN. YOU OWN ONLY",A,"ACRES. NOW THEN,")
def BadInput710(S):
print ( "HAMURABI: THINK AGAIN. YOU HAVE ONLY")
print ( S,"BUSHELS OF GRAIN. NOW THEN,")
def NationalFink():
print ( "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY")
print ( "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE")
print ( "ALSO BEEN DECLARED NATIONAL FINK!!!!")
def B_input(promptstring): #emulate BASIC input. It rejects non-numeric values
x=input(promptstring)
while x.isalpha():
x=input("?REDO FROM START\n? ")
return int(x)
from random import random from random import random
from random import seed from random import seed
def gen_random():
return int(random() * 5) + 1
def bad_input_850():
print("\nHAMURABI: I CANNOT DO WHAT YOU WISH.")
print("GET YOURSELF ANOTHER STEWARD!!!!!")
Z = 99
def bad_input_710(S):
print("HAMURABI: THINK AGAIN. YOU HAVE ONLY")
print(S, "BUSHELS OF GRAIN. NOW THEN,")
def bad_input_720(A):
print("HAMURABI: THINK AGAIN. YOU OWN ONLY", A, "ACRES. NOW THEN,")
def national_fink():
print("DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY")
print("BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE")
print("ALSO BEEN DECLARED NATIONAL FINK!!!!")
def b_input(promptstring): # emulate BASIC input. It rejects non-numeric values
x = input(promptstring)
while x.isalpha():
x = input("?REDO FROM START\n? ")
return int(x)
seed() seed()
title = "HAMURABI" title = "HAMURABI"
title = title.rjust(32,' ') title = title.rjust(32, ' ')
print (title) print(title)
attribution = "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" attribution = "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
attribution = attribution.rjust(15," ") attribution = attribution.rjust(15, " ")
print (attribution) print(attribution)
print ('\n\n\n') print('\n\n\n')
print ("TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA") print("TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA")
print ("FOR A TEN-YEAR TERM OF OFFICE.\n") print("FOR A TEN-YEAR TERM OF OFFICE.\n")
D1=0
P1=0 D1 = 0
Z=0 #year P1 = 0
P=95 #population Z = 0 # year
S=2800 #grain stores P = 95 # population
H=3000 S = 2800 # grain stores
E=H-S #rats eaten H = 3000
Y=3 #yield (amount of production from land). Reused as price per acre E = H - S # rats eaten
A=H/Y #acres of land Y = 3 # yield (amount of production from land). Reused as price per acre
I=5 #immigrants A = H / Y # acres of land
Q=1 #boolean for plague, also input for buy/sell land I = 5 # immigrants
D=0 # people Q = 1 # boolean for plague, also input for buy/sell land
while (Z<11): #line 270. main loop. while the year is less than 11 D = 0 # people
print ("\n\n\nHAMURABI: I BEG TO REPORT TO YOU")
Z=Z+1 #year while Z < 11: # line 270. main loop. while the year is less than 11
print ( "IN YEAR",Z,",",D,"PEOPLE STARVED,",I,"CAME TO THE CITY,") print("\n\n\nHAMURABI: I BEG TO REPORT TO YOU")
P=P+I Z = Z + 1 # year
if Q==0: print("IN YEAR", Z, ",", D, "PEOPLE STARVED,", I, "CAME TO THE CITY,")
P=int(P/2) P = P + I
print ("A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.")
print ("POPULATION IS NOW",P) if Q == 0:
print ("THE CITY NOW OWNS",A,"ACRES.") P = int(P / 2)
print ("YOU HARVESTED",Y,"BUSHELS PER ACRE.") print("A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.")
print ("THE RATS ATE",E,"BUSHELS.")
print ("YOU NOW HAVE ",S,"BUSHELS IN STORE.\n") print("POPULATION IS NOW", P)
C=int(10*random()) #random number between 1 and 10 print("THE CITY NOW OWNS", A, "ACRES.")
Y=C+17 print("YOU HARVESTED", Y, "BUSHELS PER ACRE.")
print ("LAND IS TRADING AT",Y,"BUSHELS PER ACRE.") print("THE RATS ATE", E, "BUSHELS.")
Q=-99 #dummy value to track status print("YOU NOW HAVE ", S, "BUSHELS IN STORE.\n")
while Q==-99: #always run the loop once C = int(10 * random()) # random number between 1 and 10
Q = B_input("HOW MANY ACRES DO YOU WISH TO BUY? ") Y = C + 17
if Q<0: print("LAND IS TRADING AT", Y, "BUSHELS PER ACRE.")
Q = -1 #to avoid the corner case of Q=-99
BadInput850() Q = -99 # dummy value to track status
Z=99 #jump out of main loop and exit while Q == -99: # always run the loop once
elif Y*Q>S: #can't afford it Q = b_input("HOW MANY ACRES DO YOU WISH TO BUY? ")
BadInput710(S) if Q < 0:
Q=-99 # give'm a second change to get it right Q = -1 # to avoid the corner case of Q=-99
elif Y*Q<=S: #normal case, can afford it bad_input_850()
A=A+Q #increase the number of acres by Q Z = 99 # jump out of main loop and exit
S=S-Y*Q #decrease the amount of grain in store to pay for it elif Y * Q > S: # can't afford it
C=0 #WTF is C for? bad_input_710(S)
if Q ==0 and Z!=99: #maybe you want to sell some land? Q = -99 # give'm a second change to get it right
elif Y * Q <= S: # normal case, can afford it
A = A + Q # increase the number of acres by Q
S = S - Y * Q # decrease the amount of grain in store to pay for it
C = 0 # WTF is C for?
if Q == 0 and Z != 99: # maybe you want to sell some land?
Q = -99 Q = -99
while Q==-99: while Q == -99:
Q = B_input( "HOW MANY ACRES DO YOU WISH TO SELL? ") Q = b_input("HOW MANY ACRES DO YOU WISH TO SELL? ")
if Q<0: if Q < 0:
BadInput850() bad_input_850()
Z=99 #jump out of main loop and exit Z = 99 # jump out of main loop and exit
elif Q<=A:#normal case elif Q <= A: # normal case
A=A-Q # reduce the acres A = A - Q # reduce the acres
S=S+Y*Q #add to grain stores S = S + Y * Q # add to grain stores
C=0 #still don't know what C is for C = 0 # still don't know what C is for
else: #Q>A error! else: # Q>A error!
BadInput720() bad_input_720(A)
Q=-99 #reloop Q = -99 # reloop
print ("\n") print("\n")
Q=-99
while Q==-99 and Z!=99: Q = -99
Q = B_input("HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ") while Q == -99 and Z != 99:
if Q<0: Q = b_input("HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ")
BadInput850() if Q < 0:
#REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS? bad_input_850()
elif Q>S: # REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
BadInput710 elif Q > S:
Q=-99 #try again! bad_input_710(S)
else: #we're good. do the transaction Q = -99 # try again!
S=S-Q #remove the grain from the stores else: # we're good. do the transaction
C=1 #set the speed of light to 1. jk S = S - Q # remove the grain from the stores
print ("\n") C = 1 # set the speed of light to 1. jk
D=-99 #dummy value to force at least one loop
while D == -99 and Z!=99: print("\n")
D = B_input("HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ") D = -99 # dummy value to force at least one loop
if D<0: while D == -99 and Z != 99:
BadInput850() D = b_input("HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ")
Z=99 if D < 0:
elif D>0: bad_input_850()
if D>A: Z = 99
#REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN? elif D > 0:
BadInput720(A) if D > A:
# REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
bad_input_720(A)
D = -99 D = -99
elif int(D/2)>S: elif int(D / 2) > S:
#REM *** ENOUGH GRAIN FOR SEED? # REM *** ENOUGH GRAIN FOR SEED?
BadInput710(S) bad_input_710(S)
D = -99 D = -99
elif D>=10*P: elif D >= 10 * P:
#REM *** ENOUGH PEOPLE TO TEND THE CROPS? # REM *** ENOUGH PEOPLE TO TEND THE CROPS?
print ("BUT YOU HAVE ONLY",P,"PEOPLE TO TEND THE FIELDS! NOW THEN,") print("BUT YOU HAVE ONLY", P, "PEOPLE TO TEND THE FIELDS! NOW THEN,")
D=-99 D = -99
else: #we're good. decrement the grain store else: # we're good. decrement the grain store
S=S-int(D/2) S = S - int(D / 2)
GenRandom(C)
#REM *** A BOUNTIFUL HARVEST! C = gen_random()
Y=C # REM *** A BOUNTIFUL HARVEST!
H=D*Y Y = C
E=0 H = D * Y
GenRandom(C) E = 0
if int(C/2)==C/2: #even number. 50/50 chance
#REM *** RATS ARE RUNNING WILD!! C = gen_random()
E=int(S/C) #calc losses due to rats, based on previous random number if int(C / 2) == C / 2: # even number. 50/50 chance
S=S-E+H #deduct losses from stores # REM *** RATS ARE RUNNING WILD!!
GenRandom(C) E = int(S / C) # calc losses due to rats, based on previous random number
#REM *** LET'S HAVE SOME BABIES S = S - E + H # deduct losses from stores
I=int(C*(20*A+S)/P/100+1)
#REM *** HOW MANY PEOPLE HAD FULL TUMMIES? C = gen_random()
C=int(Q/20) # REM *** LET'S HAVE SOME BABIES
#REM *** HORROS, A 15% CHANCE OF PLAGUE I = int(C * (20 * A + S) / P / 100 + 1)
#yeah, should be HORRORS, but left it # REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
Q=int(10*(2*random()-.3)) C = int(Q / 20)
if P>=C and Z!=99: #if there are some people without full bellies... # REM *** HORROS, A 15% CHANCE OF PLAGUE
#REM *** STARVE ENOUGH FOR IMPEACHMENT? # yeah, should be HORRORS, but left it
D=P-C Q = int(10 * (2 * random() - .3))
if D>.45*P: if P >= C and Z != 99: # if there are some people without full bellies...
print ("\nYOU STARVED",D,"PEOPLE IN ONE YEAR!!!") # REM *** STARVE ENOUGH FOR IMPEACHMENT?
NationalFink() D = P - C
Z=99 #exit the loop if D > .45 * P:
P1=((Z-1)*P1+D*100/P)/Z print("\nYOU STARVED", D, "PEOPLE IN ONE YEAR!!!")
P=C national_fink()
D1=D1+D Z = 99 # exit the loop
if Z!=99: P1 = ((Z - 1) * P1 + D * 100 / P) / Z
print ( "IN YOUR 10-YEAR TERM OF OFFICE,",P1,"PERCENT OF THE") P = C
print ( "POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF") D1 = D1 + D
print ( D1,"PEOPLE DIED!!")
L=A/P if Z != 99:
print ( "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH") print("IN YOUR 10-YEAR TERM OF OFFICE,", P1, "PERCENT OF THE")
print ( L,"ACRES PER PERSON.\n") print("POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF")
if (P1>33 or L<7): print(D1, "PEOPLE DIED!!")
NationalFink() L = A / P
elif (P1>10 or L<9): print("YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH")
print ( "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.") print(L, "ACRES PER PERSON.\n")
print ( "THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,") if P1 > 33 or L < 7:
print ( "FRANKLY, HATE YOUR GUTS!!") national_fink()
elif (P1>3 or L<10): elif P1 > 10 or L < 9:
print ( "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT") print("YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.")
print ( "REALLY WASN'T TOO BAD AT ALL. ",int(P*.8*random()),"PEOPLE") print("THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,")
print ( "WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR") print("FRANKLY, HATE YOUR GUTS!!")
print ( "TRIVIAL PROBLEMS.") elif P1 > 3 or L < 10:
print("YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT")
print("REALLY WASN'T TOO BAD AT ALL. ", int(P * .8 * random()), "PEOPLE")
print("WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR")
print("TRIVIAL PROBLEMS.")
else: else:
print ( "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND") print("A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND")
print ( "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!\n") print("JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!\n")
for N in range(1,10): for N in range(1, 10):
print ( '\a') print('\a')
print("\nSO LONG FOR NOW.\n") print("\nSO LONG FOR NOW.\n")