mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,30 +1,39 @@
|
|||||||
def GenRandom(C):
|
from random import random
|
||||||
C=int(random()*5)+1
|
from random import seed
|
||||||
def BadInput850():
|
|
||||||
|
|
||||||
|
def gen_random():
|
||||||
|
return int(random() * 5) + 1
|
||||||
|
|
||||||
|
|
||||||
|
def bad_input_850():
|
||||||
print("\nHAMURABI: I CANNOT DO WHAT YOU WISH.")
|
print("\nHAMURABI: I CANNOT DO WHAT YOU WISH.")
|
||||||
print("GET YOURSELF ANOTHER STEWARD!!!!!")
|
print("GET YOURSELF ANOTHER STEWARD!!!!!")
|
||||||
Z = 99
|
Z = 99
|
||||||
def BadInput710(S):
|
|
||||||
|
|
||||||
|
def bad_input_710(S):
|
||||||
print("HAMURABI: THINK AGAIN. YOU HAVE ONLY")
|
print("HAMURABI: THINK AGAIN. YOU HAVE ONLY")
|
||||||
print(S, "BUSHELS OF GRAIN. NOW THEN,")
|
print(S, "BUSHELS OF GRAIN. NOW THEN,")
|
||||||
def BadInput720(A):
|
|
||||||
|
|
||||||
|
def bad_input_720(A):
|
||||||
print("HAMURABI: THINK AGAIN. YOU OWN ONLY", A, "ACRES. NOW THEN,")
|
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 national_fink():
|
||||||
def NationalFink():
|
|
||||||
print("DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY")
|
print("DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY")
|
||||||
print("BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE")
|
print("BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE")
|
||||||
print("ALSO BEEN DECLARED NATIONAL FINK!!!!")
|
print("ALSO BEEN DECLARED NATIONAL FINK!!!!")
|
||||||
|
|
||||||
def B_input(promptstring): #emulate BASIC input. It rejects non-numeric values
|
|
||||||
|
def b_input(promptstring): # emulate BASIC input. It rejects non-numeric values
|
||||||
x = input(promptstring)
|
x = input(promptstring)
|
||||||
while x.isalpha():
|
while x.isalpha():
|
||||||
x = input("?REDO FROM START\n? ")
|
x = input("?REDO FROM START\n? ")
|
||||||
return int(x)
|
return int(x)
|
||||||
|
|
||||||
from random import random
|
|
||||||
from random import seed
|
|
||||||
seed()
|
seed()
|
||||||
title = "HAMURABI"
|
title = "HAMURABI"
|
||||||
title = title.rjust(32, ' ')
|
title = title.rjust(32, ' ')
|
||||||
@@ -35,6 +44,7 @@ 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
|
D1 = 0
|
||||||
P1 = 0
|
P1 = 0
|
||||||
Z = 0 # year
|
Z = 0 # year
|
||||||
@@ -47,14 +57,17 @@ A=H/Y #acres of land
|
|||||||
I = 5 # immigrants
|
I = 5 # immigrants
|
||||||
Q = 1 # boolean for plague, also input for buy/sell land
|
Q = 1 # boolean for plague, also input for buy/sell land
|
||||||
D = 0 # people
|
D = 0 # people
|
||||||
while (Z<11): #line 270. main loop. while the year is less than 11
|
|
||||||
|
while Z < 11: # line 270. main loop. while the year is less than 11
|
||||||
print("\n\n\nHAMURABI: I BEG TO REPORT TO YOU")
|
print("\n\n\nHAMURABI: I BEG TO REPORT TO YOU")
|
||||||
Z = Z + 1 # year
|
Z = Z + 1 # year
|
||||||
print("IN YEAR", Z, ",", D, "PEOPLE STARVED,", I, "CAME TO THE CITY,")
|
print("IN YEAR", Z, ",", D, "PEOPLE STARVED,", I, "CAME TO THE CITY,")
|
||||||
P = P + I
|
P = P + I
|
||||||
|
|
||||||
if Q == 0:
|
if Q == 0:
|
||||||
P = int(P / 2)
|
P = int(P / 2)
|
||||||
print("A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.")
|
print("A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.")
|
||||||
|
|
||||||
print("POPULATION IS NOW", P)
|
print("POPULATION IS NOW", P)
|
||||||
print("THE CITY NOW OWNS", A, "ACRES.")
|
print("THE CITY NOW OWNS", A, "ACRES.")
|
||||||
print("YOU HARVESTED", Y, "BUSHELS PER ACRE.")
|
print("YOU HARVESTED", Y, "BUSHELS PER ACRE.")
|
||||||
@@ -63,62 +76,66 @@ while (Z<11): #line 270. main loop. while the year is less than 11
|
|||||||
C = int(10 * random()) # random number between 1 and 10
|
C = int(10 * random()) # random number between 1 and 10
|
||||||
Y = C + 17
|
Y = C + 17
|
||||||
print("LAND IS TRADING AT", Y, "BUSHELS PER ACRE.")
|
print("LAND IS TRADING AT", Y, "BUSHELS PER ACRE.")
|
||||||
|
|
||||||
Q = -99 # dummy value to track status
|
Q = -99 # dummy value to track status
|
||||||
while Q == -99: # always run the loop once
|
while Q == -99: # always run the loop once
|
||||||
Q = B_input("HOW MANY ACRES DO YOU WISH TO BUY? ")
|
Q = b_input("HOW MANY ACRES DO YOU WISH TO BUY? ")
|
||||||
if Q < 0:
|
if Q < 0:
|
||||||
Q = -1 # to avoid the corner case of Q=-99
|
Q = -1 # to avoid the corner case of Q=-99
|
||||||
BadInput850()
|
bad_input_850()
|
||||||
Z = 99 # jump out of main loop and exit
|
Z = 99 # jump out of main loop and exit
|
||||||
elif Y * Q > S: # can't afford it
|
elif Y * Q > S: # can't afford it
|
||||||
BadInput710(S)
|
bad_input_710(S)
|
||||||
Q = -99 # give'm a second change to get it right
|
Q = -99 # give'm a second change to get it right
|
||||||
elif Y * Q <= S: # normal case, can afford it
|
elif Y * Q <= S: # normal case, can afford it
|
||||||
A = A + Q # increase the number of acres by Q
|
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
|
S = S - Y * Q # decrease the amount of grain in store to pay for it
|
||||||
C = 0 # WTF is C for?
|
C = 0 # WTF is C for?
|
||||||
|
|
||||||
if Q == 0 and Z != 99: # maybe you want to sell some land?
|
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
|
Q = -99
|
||||||
while Q == -99 and Z != 99:
|
while Q == -99 and Z != 99:
|
||||||
Q = B_input("HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ")
|
Q = b_input("HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ")
|
||||||
if Q < 0:
|
if Q < 0:
|
||||||
BadInput850()
|
bad_input_850()
|
||||||
# REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
|
# REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?
|
||||||
elif Q > S:
|
elif Q > S:
|
||||||
BadInput710
|
bad_input_710(S)
|
||||||
Q = -99 # try again!
|
Q = -99 # try again!
|
||||||
else: # we're good. do the transaction
|
else: # we're good. do the transaction
|
||||||
S = S - Q # remove the grain from the stores
|
S = S - Q # remove the grain from the stores
|
||||||
C = 1 # set the speed of light to 1. jk
|
C = 1 # set the speed of light to 1. jk
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
D = -99 # dummy value to force at least one loop
|
D = -99 # dummy value to force at least one loop
|
||||||
while D == -99 and Z != 99:
|
while D == -99 and Z != 99:
|
||||||
D = B_input("HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ")
|
D = b_input("HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ")
|
||||||
if D < 0:
|
if D < 0:
|
||||||
BadInput850()
|
bad_input_850()
|
||||||
Z = 99
|
Z = 99
|
||||||
elif D > 0:
|
elif D > 0:
|
||||||
if D > A:
|
if D > A:
|
||||||
# REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
|
# REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?
|
||||||
BadInput720(A)
|
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?
|
||||||
@@ -126,17 +143,20 @@ while (Z<11): #line 270. main loop. while the year is less than 11
|
|||||||
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)
|
|
||||||
|
C = gen_random()
|
||||||
# REM *** A BOUNTIFUL HARVEST!
|
# REM *** A BOUNTIFUL HARVEST!
|
||||||
Y = C
|
Y = C
|
||||||
H = D * Y
|
H = D * Y
|
||||||
E = 0
|
E = 0
|
||||||
GenRandom(C)
|
|
||||||
|
C = gen_random()
|
||||||
if int(C / 2) == C / 2: # even number. 50/50 chance
|
if int(C / 2) == C / 2: # even number. 50/50 chance
|
||||||
# REM *** RATS ARE RUNNING WILD!!
|
# REM *** RATS ARE RUNNING WILD!!
|
||||||
E = int(S / C) # calc losses due to rats, based on previous random number
|
E = int(S / C) # calc losses due to rats, based on previous random number
|
||||||
S = S - E + H # deduct losses from stores
|
S = S - E + H # deduct losses from stores
|
||||||
GenRandom(C)
|
|
||||||
|
C = gen_random()
|
||||||
# REM *** LET'S HAVE SOME BABIES
|
# REM *** LET'S HAVE SOME BABIES
|
||||||
I = int(C * (20 * A + S) / P / 100 + 1)
|
I = int(C * (20 * A + S) / P / 100 + 1)
|
||||||
# REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
|
# REM *** HOW MANY PEOPLE HAD FULL TUMMIES?
|
||||||
@@ -149,11 +169,12 @@ while (Z<11): #line 270. main loop. while the year is less than 11
|
|||||||
D = P - C
|
D = P - C
|
||||||
if D > .45 * P:
|
if D > .45 * P:
|
||||||
print("\nYOU STARVED", D, "PEOPLE IN ONE YEAR!!!")
|
print("\nYOU STARVED", D, "PEOPLE IN ONE YEAR!!!")
|
||||||
NationalFink()
|
national_fink()
|
||||||
Z = 99 # exit the loop
|
Z = 99 # exit the loop
|
||||||
P1 = ((Z - 1) * P1 + D * 100 / P) / Z
|
P1 = ((Z - 1) * P1 + D * 100 / P) / Z
|
||||||
P = C
|
P = C
|
||||||
D1 = D1 + D
|
D1 = D1 + D
|
||||||
|
|
||||||
if Z != 99:
|
if Z != 99:
|
||||||
print("IN YOUR 10-YEAR TERM OF OFFICE,", P1, "PERCENT OF THE")
|
print("IN YOUR 10-YEAR TERM OF OFFICE,", P1, "PERCENT OF THE")
|
||||||
print("POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF")
|
print("POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF")
|
||||||
@@ -161,13 +182,13 @@ if Z!=99:
|
|||||||
L = A / P
|
L = A / P
|
||||||
print("YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH")
|
print("YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH")
|
||||||
print(L, "ACRES PER PERSON.\n")
|
print(L, "ACRES PER PERSON.\n")
|
||||||
if (P1>33 or L<7):
|
if P1 > 33 or L < 7:
|
||||||
NationalFink()
|
national_fink()
|
||||||
elif (P1>10 or L<9):
|
elif P1 > 10 or L < 9:
|
||||||
print("YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.")
|
print("YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.")
|
||||||
print("THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,")
|
print("THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND,")
|
||||||
print("FRANKLY, HATE YOUR GUTS!!")
|
print("FRANKLY, HATE YOUR GUTS!!")
|
||||||
elif (P1>3 or L<10):
|
elif P1 > 3 or L < 10:
|
||||||
print("YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT")
|
print("YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT")
|
||||||
print("REALLY WASN'T TOO BAD AT ALL. ", int(P * .8 * random()), "PEOPLE")
|
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("WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR")
|
||||||
@@ -177,7 +198,5 @@ if Z!=99:
|
|||||||
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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user