DECLARE SUB cprint (t$) DECLARE SUB DisplayIntro () DECLARE SUB initialize (F() AS ANY) DECLARE SUB Move1To2 (F() AS ANY) DECLARE SUB Move2to1 (F() AS ANY) DECLARE SUB DisplayProportions (F() AS ANY, t) SCREEN 9 WINDOW SCREEN (0, 0)-(12, 2) VIEW (100, 100)-(600, 300) LINE (0, 0)-(12, 2), 15, BF LINE (0, 0)-(12, 2), 4, B LINE (0, 1)-(12, 1), 4 TYPE AFish pond AS INTEGER col AS INTEGER END TYPE CONST NumFish = 2300 DIM Fish(NumFish) AS AFish initialize Fish() DisplayIntro DO Move1To2 Fish() Move2to1 Fish() ct = ct + 1 DisplayProportions Fish(), ct / 100 LOOP SUB Comment (t$) 'print comments while program executes BEEP COLOR 2, 0 cs = CSRLIN ps = POS(1) PRINT "Comment: "; PRINT t$ PRINT "Press any key to continue..." WHILE INKEY$ = "" WEND cs2 = CSRLIN COLOR 7, 0 LOCATE cs, ps FOR j = cs TO cs2 PRINT SPACE$(80) NEXT j LOCATE cs, ps END SUB SUB cprint (t$) 'center print l = 41 - LEN(t$) \ 2 IF l < 1 THEN l = 1 LOCATE , l PRINT t$ END SUB SUB DisplayIntro LOCATE 10, 1 PRINT "Small Pond" LOCATE 18, 1 PRINT "large Pond" LOCATE 1, 1 cprint "This is a simulation of transfering fish" cprint "The large pond has 50% black fish" cprint "The small pond has 100% black fish" cprint "Poportion of black fish in each pond is graphed as tranfers occur" END SUB SUB DisplayProportions (F() AS AFish, t) 'display contents of ponds STATIC x1 STATIC x2 STATIC t1 n = UBOUND(F) DIM Black(2), pond(2) FOR j = 1 TO n IF F(j).col = 0 THEN Black(F(j).pond) = Black(F(j).pond) + 1 pond(F(j).pond) = pond(F(j).pond) + 1 NEXT j y1 = Black(1) / pond(1) y2 = Black(2) / pond(2) LOCATE 11, 1 PRINT y2 LOCATE 19, 1 PRINT y1 LINE (t1, 2 - x1)-(t, 2 - y1), 2 LINE (t1, 1 - x2)-(t, 1 - y2), 2 t1 = t x1 = y1 x2 = y2 END SUB SUB initialize (Fish() AS AFish) 'initialize colors and ponds FOR j = 1 TO 2200 Fish(j).pond = 1 Fish(j).col = (j MOD 2) NEXT j FOR j = 2200 TO 2300 Fish(j).pond = 2 Fish(j).col = 0 NEXT j END SUB SUB Move1To2 (F() AS AFish) 'move a fish at random from Pond 1 'just try fishing n = UBOUND(F) k = INT(RND * n + 1) WHILE F(k).pond = 2 k = INT(RND * n + 1) WEND F(k).pond = 2 END SUB SUB Move2to1 (F() AS AFish) 'move a fish at random from Pond 2 'just try fishing n = UBOUND(F) k = INT(RND * n + 1) WHILE F(k).pond = 1 k = INT(RND * n + 1) WEND F(k).pond = 1 END SUB SUB shuffle (Deck()) 'Shuffle the deck of cards n = UBOUND(Deck) ns = n FOR j = 1 TO n 'take a card at random and put it away k = INT(RND(1) * ns + 1) SWAP Deck(k), Deck(ns) ns = ns - 1 NEXT j END SUB