|
Post by tenochtitlanuk on Nov 15, 2018 17:24:40 GMT
Fun, playing God, is it not??? I enjoyed Hamurabi for exactly the same reason- a mix of deterministic choices/consequences, and random events. Again, good training for economists/ politicians/ climate-change-deniers... Wow, it's a long time since I put that up on the web. I lost access to the site when the school moved to a different host. File is there on my new site's copy- malthus.txt
|
|
|
Post by bluatigro on Nov 16, 2018 10:57:21 GMT
update : changed the logic added graphics
'' bluatigro 14 nov 2018 '' fish and shark input "fish : " ; fish input "shark : " ; shark input "fish get child : " ; a input "shark eat fish : " ; b input "shark get child : " ; c input "shark die : " ; d WindowWidth = DisplayWidth WindowHeight = DisplayHeight nomainwin open "fish and sharks ." for graphics as #m #m "trapclose [quit]" #m "size 5" tel = 0 while shark > 0 and tel < WindowWidth call pixel tel , WindowHeight - fish , "green" call pixel tel , WindowHeight - shark , "red" dfish = fish * a - shark * fish * b dshark = shark * fish * c - shark * d fish = fish + dfish shark = shark + dshark tel = tel + 1 wend if shark > 0 then notice "[ shark are exterminated . ]" else notice "[ end sim ]" end if wait [quit] close #m end sub pixel x , y , kl$ #m "color " ; kl$ #m "goto " ; x ; " " ; y #m "down" #m "set " ; x ; " " ; y #m "up" end sub
|
|
|
Post by B+ on Nov 16, 2018 19:24:48 GMT
I found some old Fox Rabbit code. It is poor model because more fox than rabbits come up often, but I think it is what bluatigro is attempting to do. ' predator prey trans.txt for JB v2 B+ 2018-11-16 ' 2018-11-16 translated from SmallBASIC Code Library and adopted for JB GUI ' from that code: ' program to plot the interaction between predator population (fox) and prey population (rabbit) ' set up the differential equations. fp=df/dt and rp=dr/dt ' fox populations grow with rabbits present but shrink with no rabbits ' rabbit populations decline when more foxes are around to eat them! ' the shape of the plot is very sensative to the exponent "w"
' INSTRUCTIONS: ' Click Run for default settings Fox = 10, Fox Exponent w = .5 and Rabbit = 100 ' Or try your own settings with ranges listed for text box labels.
global H$, XMAX, YMAX H$ = "gr" XMAX = 800 '<======================================== actual drawing space needed YMAX = 600 '<======================================== actual drawing space needed
nomainwin WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 UpperLeftX = (DisplayWidth - XMAX) / 2 'or delete if XMAX is 1200 or above UpperLeftY = (DisplayHeight - YMAX) / 2 'or delete if YMAX is 700 or above
graphicbox #gr.gb, 5, 5, XMAX-10, YMAX - 50 statictext #gr.lbfox, "", 10, YMAX - 40, 165, 20 textbox #gr.tbfox, 10, YMAX - 20, 165, 20 statictext #gr.lbfoxE, "", 210, YMAX - 40, 165, 20 textbox #gr.tbfoxE, 210, YMAX - 20, 165, 20 statictext #gr.lbR, "", 410, YMAX - 40, 200, 20 textbox #gr.tbR, 410, YMAX - 20, 200, 20 button #gr.bRun, "Run", [Run], UL, XMAX - 130, YMAX - 35, 80, 30 open "Predator Prey: Red = Rabbit, Blue = Fox " for graphics_nsb_nf as #gr #gr "setfocus" #gr "trapclose quit" #gr "when leftButtonUp lButtonUp" #gr "when characterInput charIn" #gr "fill cyan" #gr.gb "down" #gr.gb "size 3" '============================== main code global w 'so functions can use it #gr.lbfox, " Fox population (1-1000):" #gr.lbfoxE, " Fox exponent (0 to 1):" #gr.lbR, " Rabbit population (1-10000):" wait 'for edit of text boxes and go
[Run] #gr.tbfoxE, "!contents? w" if w <= 0 or w >= .98 then w = .5 : #gr.tbfoxE, ".5" 'w = .5 '<<<<<<<<<<<<<<<< actually numbers < .5 look more realistic
#gr.tbfox, "!contents? f" if f < 1 or f >= 1000 then f = 10 : #gr.tbfox, "10"
#gr.tbR, "!contents? r" if r < 1 or r >= 10000 then r = 100 : #gr.tbR, "100"
n = XMAX - 20 h = .1 'orig .0025 yscale = YMAX / (5 * r)
#gr.gb "fill white" #gr.gb "color black" #gr.gb "line ";0;" ";YMAX - 60;" ";XMAX;" ";YMAX - 60 'integrate the equations FOR q = 1 TO n kfp1 = h * fp(f,r) krp1 = h * rp(f,r)
kfp2 = h * fp(f + .5 * kfp1, r + .5 * krp1) krp2 = h * rp(f + .5 * kfp1, r + .5 * krp1)
kfp3 = h * fp(f + .5 * kfp2, r + .5 * krp2) krp3 = h * rp(f + .5 * kfp2, r + .5 * krp2)
kfp4 = h * fp(f + .5 * kfp3, r + .5 * krp3) krp4 = h * rp(f + .5 * kfp3, r + .5 * krp3)
f = f + (kfp1 + 2 * kfp2 + 2 * kfp3 + kfp4) / 6 r = r + (krp1 + 2 * krp2 + 2 * krp3 + krp4) / 6
'plot the results if q > 1 then #gr.gb "color blue" #gr.gb "line ";q + 4;" ";YMAX - 60 - lastf * yscale;" ";q + 5;" ";YMAX - 60 - f * yscale #gr.gb "color red" #gr.gb "line ";q + 4;" ";YMAX - 60 - lastr * yscale;" ";q + 5;" ";YMAX - 60 - r * yscale end if lastf = f lastr = r NEXT #gr.gb "flush" wait
' these are the differential functions used: function fp(f, r) 'change in fox df/dt 'global w is exponent of fox population fp = .1 * (f ^ w) * r - f end function
function rp(f, r) rp = r * (2 - .05 * f) end function
' for GUI hit a key to quit or click mouse sub lButtonUp H$, mx, my 'must have handle and mouse x,y call quit H$ '<=== H$ global window handle end sub
sub charIn H$, c$ call quit H$ end sub
sub quit H$ close #H$ end end sub
|
|