Old school Hamurabi
Posted: Mon Feb 11, 2019 11:09 am
Someone mentioned the early game of Hamurabi.
It triggered me to produce the game as i remember it. It is an old fashioned text based replica. I replaced the standard keyboard by a little numerical keypad, and designed my own simulation mechanisms.
Perhaps i will make a "modern" version with a graphical UI.
It triggered me to produce the game as i remember it. It is an old fashioned text based replica. I replaced the standard keyboard by a little numerical keypad, and designed my own simulation mechanisms.
Perhaps i will make a "modern" version with a graphical UI.
Code: Select all
' Old school Hamurabi, version 11-02-2019
'
' *** parameters
C=120 ' starting # of kids
V=300 ' starting # of adults
bo=0.04 ' starting value of birth rate
dco=0.01 ' starting value of mortuality of kids
dvo=0.02 ' starting value of mortuality of adults
S=100 ' starting value of acres of land
e=2 ' needed # of bushels food per person
m=3 ' needed # of adults per acre
z=2 ' needed # bushels seed per acre
q=13 ' basic # of bushels produced per acre
k=30 ' cost of additional purchased acre
effo=1 ' starting value of production efficiency
SQ=100 ' starting stock of bushels
Zt=200 ' starting value of bushels of seed
b=bo ! dc=dco ! dv=dvo ! eff=effo
print "REMEMBER!"
print "one person needs about 2 bushels of food/year"
print "one acre of land needs about 3 adults to harvest"
print
do
if yr<3 then init_numpad(570,70+340*yr,40,.8,.8,.8,1)
yr+=1 ! print ! print "Year ";yr;" of your reign"
Sf=min(S,V/m) ! Sf=min(Sf,Zt/z) ! dQ=int(eff*q*Sf)
SQ+=dQ ! print dQ;" bushels have been produced"
if rnd(1)<0.3 then
gr=200+rnd(300) ! SQ=max(.1,SQ-gr)
print "*** Grasshoppers ate";gr;"bushels!!! ***"
end if
stock() ! print "How many bushels food for the ";C+V;" people?"
Et=numpad(0,SQ) ! SQ=max(.1,SQ-Et)
stock() ! print "How many bushels as seed for new crops?"
Zt=numpad(0,SQ) ! SQ=max(.1,SQ-Zt)
stock() ! print "How many bushels for buying land at ";k;"/acre"
Kt=numpad(0,SQ) ! SQ=max(.1,SQ-Kt) ! S+=Kt/k
phi=Et/e/(C+V) ! phip=int(100*phi)
b=0.6*b+0.4*phi*bo ! eff=0.9*eff+0.1*phi*effo
dc=0.3*dc+0.7*dco/phi ! dv=0.4*dv+0.6*dvo/phi
adr=int(1000*(dc*C+dv*V)/(C+V))/10
aux=C
C=int(C+b*V-(dc+0.05)*C) ! V=int(V+.05*aux-dv*V)
if rnd(1)<.2 then
f=10+rnd(20)
print "*** The plague killed";f;"percent of the people!! ***"
f/=100 ! C=int((1-f)*C) ! V=int((1-f)*V)
end if
print ! print "Results for year ";yr
print "Population is now ";C;" kids & ";V;" adults"
print "Average health of the people was ";phip;"%"
print "Birth rate was ";int(1000*b)/10;"%"
print "Average death rate was ";adr;"%"
print "Production efficiency is ";int(100*eff);"%"
print "You now own ";S;" acres of land"
until forever
end
def stock() ! print "you have ";int(.SQ);" bushels left." ! end def
' numerical keypad
'
' produce a simple keypad to quickly enter a number in an app
' upon entry, the keypad disappears
' initialize once, multiple use after
' left upper corner is placed at "xtop,ytop"
' "bs" is the button size (keypad becomes 4.3 times larger)
'
def init_numpad(xtop,ytop,bs,R,G,B,alpha)
name$="numpad" ! cn=10
page name$ set
page name$ frame xtop,ytop,0,0
set buttons custom
if bs<20 then bs=20
sp=4 ! th=.5*bs+4 ! ww=4*bs+5*sp ! hh=th+4*bs+6*sp
fsize=.5*bs
draw font size fsize ! set buttons font size fsize
draw color 1,1,1 ! fill color .7,.7,.7
button "rec" title "" at 0,0 size ww,hh
button "res" title "" at 0,0 size ww,th+4
fill color R,G,B ! fill alpha alpha
button "0" title "0" at sp,th+3*bs+5*sp size bs,bs
for k=1 to 9
x=(k-1)%3 ! y=2-floor((k-1)/3)
button k title k at (x+1)*sp+x*bs,th+y*bs+(y+2)*sp size bs,bs
next k
button "-" title "-" at 2*sp+bs,th+3*bs+5*sp size bs,bs
button "." title "." at 3*sp+2*bs,th+3*bs+5*sp size bs,bs
button "Cl" title "C" at 4*sp+3*bs,th+2*sp size bs,bs
button "del" title "<-" at 4*sp+3*bs,th+bs+3*sp size bs,bs
button "ok" title "ok" at 4*sp+3*bs,th+2*bs+4*sp size bs,2*bs+sp
page name$ hide
page name$ frame xtop,ytop,ww,hh
set buttons default ! set buttons font size 20
draw font size 20 ! draw color 0,0,0
end def
' size of number is accepted between "minval" and "maxval"
' if both "minval" and "maxval" are zero, then no restrictions
' max number of tokens in the number is 10 (minus and dot included)
' works for option base 0 and 1
'
def numpad(minval,maxval)
page "numpad" set ! page "numpad" show
a$="" ! pflag=0 ! sflag=0 ! ob=1-option_base()
nump1:
if b_p("ok") then
number=val(a$) ! a$="" ! button "res" text ""
if minval<>0 or maxval<>0 then
if number<minval or number>maxval then
button "res" text "range error"
pflag=0 ! a$="" ! pause 1
button "res" text ""
goto nump1
end if
end if
page "numpad" hide ! page "" set
return number
end if
if b_p("Cl") then
a$ = "" ! pflag=0 ! sflag=0 ! goto nump3
end if
if b_p("del") and len(a$) then
ll=len(a$) ! if substr$(a$,ll-ob,ll-ob)="." then pflag=0
a$ = left$(a$,ll-1) ! sflag=0 ! goto nump3
end if
if b_p("-") then
a$ = "-" ! pflag=0 ! sflag=0 ! goto nump3
end if
if b_p(".") and not pflag and not sflag then
a$ &= "." ! pflag=1 ! goto nump3
end if
for k=0 to 9
t$=k
if b_p(t$) and not sflag then
a$ &= t$ ! goto nump3
end if
next k
goto nump1
nump3:
if len(a$)>10 then ! sflag=1 ! goto nump1 ! end if
button "res" text a$
goto nump1
end def
def b_p(a$) = button_pressed(a$)