|
Post by Carl Gundel on Apr 12, 2020 12:23:23 GMT -5
Okay, let's make a G rated simulation. Do not borrow any code from David Drake's simulator for this challenge.
The code should be less than one 1K, with similar kinds of colorful bouncing balls animation.
The simulation is the people (bouncing balls) are well, then they catch cold, then they get better and are immune.
|
|
|
Post by tsh73 on Apr 12, 2020 16:27:20 GMT -5
Here is what I have but 1) it is 1100 bytes, 158 of them responsible for nice lower-pane graph 2) that lower-pane graph DOES NOT WORK in LB And that's strange. Then I add printing, after line f(s(i))=f(s(i))+1 I see that f(0), f(1), f(2) contains right counters (0..100) But in drawing code #m.l "Set ";B-3;" ";100-f(i) f(0), f(1), f(2) contains either 0 or 1! Shouldn't it work just as I designed it to work? Any ideas? nomainwin B=310:C=220 graphicbox #m.g, 0, 0, B, C graphicbox #m.l, 0, C+1, B, 100 open "Cold" for window as #m #m "trapclose [q]" #m.g "down;size 5" #m.l "down" N=100:T=50 dim x(N),y(N),X(N),Y(N),s(N),t(N) c$(0)="black":c$(1)="red":c$(2)="blue":C$="color ": CW$=C$;"white" for i = 1 to N:x(i)=r(B):y(i)=r(B):X(i)=r(9)-4:Y(i)=r(9)-4:s(i)=r(20)<1:t(i)=T*s(i):next timer 200, [w]
[w] #m.g "discard" dim f(2) for i = 1 to N #m.g CW$;";set ";x(i);" ";y(i) xx=x(i)+X(i):if xx>B or xx<0 then X(i)=0-X(i) x(i)=x(i)+X(i) yy=y(i)+Y(i):if yy>C or yy<0 then Y(i)=0-Y(i) y(i)=y(i)+Y(i)
for j = 1 to N scan if s(i)=1 then if (abs(x(i)-x(j))<10) and (abs(y(i)-y(j))<10) and (s(j)=0) and (r(10)<3) then s(j)=1:t(j)=T end if next f(s(i))=f(s(i))+1
#m.g C$;c$(s(i));";Set ";x(i);" ";y(i) t(i)=t(i)-(s(i)=1): if t(i)<0 then s(i)=2 next
#m.l CW$;";goto ";B-3;" 0;go -100" for i = 0 to 2 #m.l C$;c$(i) #m.l "Set ";B-3;" ";100-f(i) next #m.l "getbmp b 1 0 ";B-3;" 100" #m.l "drawbmp b 0 0"
wait [q] timer 0 close #m end
function r(n) r=int(rnd(0)*n) end function
|
|
|
Post by tsh73 on Apr 14, 2020 0:21:35 GMT -5
What? No one else? I managed to squeeze same stuff in 999 bytes, by drawing chart ordinary way (without scrolling) And I managed to make it work in LB. It happened to be my computer not powerful enough - then I set timer delay to 500, it starts charting (likely timer somehow fired before chart drawing) nomainwin B=310:C=220 graphicbox #m.g, 0, 0, B, C graphicbox #m.l, 0, C+1, B, 100 open "Cold" for window as #m #m "trapclose [q]" #m.g "down;size 5" #m.l "down" N=100:T=50 dim x(N),y(N),X(N),Y(N),s(N),t(N) c$(0)="black":c$(1)="red":c$(2)="blue":C$="color ": CW$=C$;"white" for i = 1 to N:x(i)=r(B):y(i)=r(B):X(i)=r(9)-4:Y(i)=r(9)-4:s(i)=r(20)<1:t(i)=T*s(i):next timer 500, [w]
[w] #m.g "discard" dim f(2) for i = 1 to N #m.g CW$;";set ";x(i);" ";y(i) xx=x(i)+X(i):if xx>B or xx<0 then X(i)=0-X(i) x(i)=x(i)+X(i) yy=y(i)+Y(i):if yy>C or yy<0 then Y(i)=0-Y(i) y(i)=y(i)+Y(i)
for j = 1 to N scan if s(i)=1 then if (abs(x(i)-x(j))<10) and (abs(y(i)-y(j))<10) and (s(j)=0) and (r(10)<3) then s(j)=1:t(j)=T end if next f(s(i))=f(s(i))+1
#m.g C$;c$(s(i));";Set ";x(i);" ";y(i) t(i)=t(i)-(s(i)=1): if t(i)<0 then s(i)=2 next t=t+1
for i = 0 to 2 #m.l C$;c$(i) #m.l "Set ";t;" ";100-f(i) next wait [q] close #m end function r(n) r=int(rnd(0)*n) end function
|
|
|
Post by David Drake on Apr 14, 2020 7:21:21 GMT -5
Hmmmm, I guess I should try. But you made the stipulation "Do not borrow any code from David Drake's simulator for this challenge." Does that mean that any code I create for this challenge is instantly disqualified?
|
|
|
Post by tsh73 on Apr 14, 2020 7:56:57 GMT -5
|
|
|
Post by Carl Gundel on Apr 14, 2020 10:16:03 GMT -5
Hmmmm, I guess I should try. But you made the stipulation "Do not borrow any code from David Drake's simulator for this challenge." Does that mean that any code I create for this challenge is instantly disqualified? Go directly to jail. Do not pass Go. Do not collect $200. Yes of course you can participate. Just write the code from scratch, again.
|
|
|
Post by Carl Gundel on Apr 14, 2020 12:49:14 GMT -5
Hmmmm, I guess I should try. But you made the stipulation "Do not borrow any code from David Drake's simulator for this challenge." Does that mean that any code I create for this challenge is instantly disqualified? Go directly to jail. Do not pass Go. Do not collect $200. Yes of course you can participate. Just write the code from scratch, again. Actually now that I think about it, you don't need to write your own code from scratch again. It's your code after all. Just make it < 1K.
|
|
|
Post by Carl Gundel on Apr 14, 2020 13:37:45 GMT -5
What? No one else? I managed to squeeze same stuff in 999 bytes, by drawing chart ordinary way (without scrolling) And I managed to make it work in LB. It happened to be my computer not powerful enough - then I set timer delay to 500, it starts charting (likely timer somehow fired before chart drawing) It is a little confusing, but it seems like your graph is not drawing 1: 1 with each cycle because of the timer and scan? So that's a race condition. These sorts of things are usually made worse when the computer isn't fast enough to keep up with the timer resolution. EDIT: That reminds me a of race condition in a multitasking shop floor system I developed in Smalltalk/V on DOS many years ago. It was crashing periodically seemingly because it was continuously calling a small machine code routine to communicate with terminals over serial ports. The problem plagued us for some time, but we lived with it. Later we decided to upgrade to a faster processor just because we wanted better performance. The race condition caused crash disappeared and never reappeared.
|
|
|
Post by David Drake on Apr 14, 2020 15:02:57 GMT -5
Well, I tried to take a different approach. This one is text-only using the MAINWIN. 1075 characters.
mainwin 180 40:dim s(99,6):p=45:g=99 for c = 10 to p s(c,1)=int(rnd(1)*50):s(c,2)=int(rnd(1)*30):s(c,3)=(0.5-rnd(1))*4:s(c,4)=(0.5-rnd(1))*4:if rnd(1)<.5 then s(c,5)=1:s(c,6)=g:f=f+1 next c while f>0 for c=10 to p if s(c,5)=1 then s(c,6)=s(c,6)-1 if s(c,6)<=0 then s(c,5)=2:f=f-1 end if:end if s(c,1)=s(c,1)+s(c,3) s(c,2)=s(c,2)+s(c,4) if s(c,1)<1 then s(c,1)=2:s(c,3)=(-1)*s(c,3) if s(c,2)<1 then s(c,2)=1:s(c,4)=(-1)*s(c,4) if s(c,1)>50 then s(c,1)=49:s(c,3)=(-1)*s(c,3) if s(c,2)>30 then s(c,2)=29:s(c,4)=(-1)*s(c,4) next c for c=10 to p:for d=10 to p if c<>d then if int(s(c,1))=int(s(d,1)) and int(s(c,2))=int(s(d,2)) then if s(c,5)=1 and s(d,5)=0 then s(d,5)=1:s(d,6)=g:f=f+1 else if s(d,5)=1 and s(c,5)=0 then s(c,5)=1:s(c,6)=g:f=f+1 end if:end if:end if:end if:next d:next c r$="":for y=1 to 30:for x=1 to 50 i$="--" for c=10 to p if int(s(c,1))=x and int(s(c,2))=y then if s(c,5)=0 then i$=str$(c) if s(c,5)=1 then i$="XX" if s(c,5)=2 then i$="**" end if next c:r$=r$+i$ next x:r$=r$+chr$(13):next y cls:print r$;" ";f wend
|
|
|
Post by Carl Gundel on Apr 14, 2020 16:22:21 GMT -5
Well, I tried to take a different approach. This one is text-only using the MAINWIN. 1075 characters. Interesting. Does it simulate the three stages of not sick, sick, recovered?
|
|
|
Post by David Drake on Apr 14, 2020 17:58:17 GMT -5
Well, I tried to take a different approach. This one is text-only using the MAINWIN. 1075 characters. Interesting. Does it simulate the three stages of not sick, sick, recovered? Yes. The numbered elements are "not yet sick." "XX" is actively sick, and "**" is recovered. Simulation runs until no more are sick.
|
|
|
Post by tsh73 on Apr 15, 2020 6:28:22 GMT -5
We run it a few times. Kid cheered for number 16. In the end all got infected, though (on this particular run)
|
|
|
Post by David Drake on Apr 15, 2020 10:44:24 GMT -5
This is harder than it looks. Sprites are a natural solution to this challenge.
|
|
|
Post by tsh73 on Apr 15, 2020 15:32:49 GMT -5
Fear the power of BASIC! end if:end if:end if:end if:next d:next c
|
|
|
Post by tsh73 on Apr 15, 2020 16:01:07 GMT -5
Interesting but then I interrupt this mainwin program, it would not start again It errors with Class already exists(OS Error 16r582) I had to close/reload IDE
ah, then program ended normal way, I had same problem
Windows XP home 32 bit, LB 4.5.1
Error log:
Error log timestamp Wednesday 15.04.20 23:44:03
Runtime error: Class already exists(OS Error 16r582)
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'Class already exists...'> TimerTopPane(Object)>>osError: <1410> TimerTopPane(Object)>>osError TimerTopPane(ApplicationWindow)>>windowClass TimerTopPane(ApplicationWindow)>>buildWindow TimerTopPane(ApplicationWindow)>>validateBuild TimerTopPane>>validate [] in ApplicationWindow>>openIn: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>ifCurtailed: <aBlockClosure> TimerTopPane(ApplicationWindow)>>openIn: <aRectangle> TimerTopPane(ApplicationWindow)>>openWindow [] in ViewManager>>openWindow OrderedCollection>>do: <aBlockClosure> TimerWindow(ViewManager)>>openWindow TimerWindow>>open BasicProgram>>openTimerWindow BasicProgram>>run [] in BasicSourcePane>>run BasicCompiler class>>compileFromString: <'mainwin 180 40:dim s...'> notify: <aBasicSourcePane> ifSuccess: <aBlockClosure> BasicSourcePane>>run BasicSourceWindow>>run BasicEditorModel>>run: <aToolbarButton> BasicEditorModel(Object)>>perform: <#run:> with: <aToolbarButton> ToolbarButton>>triggerClickedEvent Message>>perform NotificationManager>>runPendingEvents NotificationManager>>runEventLoop Message>>perform Message>>evaluate Process>>safelyEvaluate: <aMessage> Process>>evaluate: <aMessage>
Also I just seen column of "nil" from counter down. It went on and off - but print screen did not registered it (Windows was too busy?) - it happens not every time - I am not able to printscreen it. but it looks somewhat like this
---------- ---------- ------**-- ---------- 26 nil nil nil nil
|
|