Optimize Me #2
Forum » Contests / Optimize Me » Optimize Me #2
started by: burrburr
on: 1213766561|%e %b %Y, %H:%M %Z|agohover
number of posts: 10
rss icon RSS: new posts
Optimize Me #2
burrburr 1213766561|%e %b %Y, %H:%M %Z|agohover

Since we have pretty much finished optimizing the first program, here is another program to optimize. Like before, the goal is to optimize for size.

:0→Xmin
:94→Xmax
:1→Ymin
:63→Ymax
:PlotsOff
:CoordOff
:AxesOff
:GridOff
:FnOff
:Lbl A
:0→B
:randInt(10,85)→C
:ClrDraw
:ClrHome
:Line(C,1,C+5,1
:Line(C+1,2,C+4,2
:For(A,1,500)
:End
:Lbl B
:ClrDraw
:Input "SHOT POWER=",S
:B+1→B
:(1/S)→S
:Line(C,1,C+5,1
:Line(C+1,2,C+4,2
:For(X,0,95,.25
:(-S(X^2)+63)→Y
:Y→Z
:Pt-On(X,Y)
:If Z<0 or Z=0
:Goto C
:End
:Lbl C
:1→M
:If X>(C-1) and X<(C+6)
:Then
:2→M
:X→K
:Line(K,1,K-8,3
:Line(K,1,K+8,3
:Line(K,1,K-6,8
:Line(K,1,K+6,8
:Line(K,1,K-2,6
:Line(K,1,K+2,6
:End
:For(A,1,200)
:End
:If M=2
:Then
:ClrHome
:If B=1
:Then
:For(I,1,3)
:Output(4,4,"FIRST TRY!"
:For(A,1,100)
:End
:Output(4,4," (10 spaces)
:For(A,1,100)
:End
:End
:Output(4,4,"FIRST TRY!:"
:End
:If B>1
:Then
:Output(4,4,B
:Output(4,8,"SHOTS"
:End
:Pause
:ClrHome
:Goto D
:End
:ClrHome
:Disp "SHOOT AGAIN:"
:Goto B
:Lbl D
:ClrHome
:Menu("PLAY AGAIN?","YES",A,"NO",E
:Lbl E
:ClrHome
:Stop
unfold Optimize Me #2 by burrburr, 1213766561|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
Edward HEdward H 1213768298|%e %b %Y, %H:%M %Z|agohover

Do we need to replicate program behavior exactly? (Asides from the memory leaks, =p)

unfold Re: Optimize Me #2 by Edward HEdward H, 1213768298|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
burrburr 1213768577|%e %b %Y, %H:%M %Z|agohover

I would say it should remain as close to the original as possible.

unfold Re: Optimize Me #2 by burrburr, 1213768577|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
basickevinbasickevin 1213812691|%e %b %Y, %H:%M %Z|agohover

You can't do much to optimize this one. All that I've changed in the version I made is that I use DrawF to draw the line, moved some of the stuff to allow for a loop instead of lbl/gotos, and gotten rid of that menu at the end. Seriously, if you want to play it again, you can just press enter once it quits.
Edit: here's my code.

0→Xmin
1→ΔX
0→Ymin
1→ΔY
AxesOff
GridOff
FnOff 
PlotsOff 
DelVar BrandInt(10,85→C
ClrDraw
Line(C,0,C+5,0
Line(C+1,1,C+4,1
Pause 
While 1
ClrDraw
Input "SHOT POWER=",S
B+1→B
Line(C,0,C+5,0
Line(C+1,1,C+4,1
DrawF 62-X/S
0
For(D,0,5
Ans+pxl-Test(60,C+D
End
If Ans
Then
C+2
Line(Ans,1,C-6,3
Line(Ans,1,C+10,3
Line(Ans,1,C-4,8
Line(Ans,1,C+8,8
Line(Ans,1,C,6
Line(Ans,1,C+4,6
Pause 
ClrHome
If B=1
Then
For(I,1,3
Output(4,4,"FIRST TRY!
rand(20
Output(4,4,"          
rand(20
End
Output(4,4,"FIRST TRY!:
ClrHome
Return
End
Output(4,4,B
Output(4,8,"SHOTS
Pause 
Return
End
ClrHome
Disp "SHOOT AGAIN:
End
last edited on 1213819109|%e %b %Y, %H:%M %Z|agohover by basickevin + show more
unfold Re: Optimize Me #2 by basickevinbasickevin, 1213812691|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
Edward HEdward H 1213817364|%e %b %Y, %H:%M %Z|agohover

You can save some space by using "rand(some number" instead of an empty for on all your delays. Good idea using DrawF for the shot trajectory. Nice.

unfold Re: Optimize Me #2 by Edward HEdward H, 1213817364|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
burrburr 1214052500|%e %b %Y, %H:%M %Z|agohover

I think there is still more optimization to be done to the program:

:0→Xmin:1→ΔX
:0→Ymin:1→ΔY
:ClrDraw
:DelVar BrandInt(10,85→C
:Line(Ans,0,Ans+5,0
:Line(Ans+1,1,Ans+4,1
:Pause 
:Repeat Ans
:ClrDraw
:ClrHome
:Input "SHOT POWER=",S
:IS>(B,B
:Line(C,0,C+5,0
:Line(C+1,1,C+4,1
:DrawF 62-X/S
:sum(seq(pxl-Test(60,C+D),D,0,5
:If not(Ans:Disp "SHOOT AGAIN!
:End
:C+2:Line(Ans,1,C-6,3
:Line(Ans,1,C+10,3
:Line(Ans,1,C-4,8
:Line(Ans,1,C+8,8
:Line(Ans,1,C,6
:Line(Ans,1,C+4,6
:Pause 
:ClrHome
:If B>1:Then
:Output(4,4,B
:Output(4,8,"SHOTS
:Else
:For(C,1,3
:Output(4,4,"          
:rand(20
:Output(4,4,"FIRST TRY!
:rand(20
:End:End
:Pause
:ClrHome:"
unfold Re: Optimize Me #2 by burrburr, 1214052500|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
builderboybuilderboy 1214069859|%e %b %Y, %H:%M %Z|agohover

And its nice to note that the number is roughly 10 times less than its for( loop equivilent

for(f,0,100
end

is equal (Basicaly) to

rand(10

last edited on 1214069878|%e %b %Y, %H:%M %Z|agohover by builderboy + show more
unfold Re: Optimize Me #2 by builderboybuilderboy, 1214069859|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
darkstone knightdarkstone knight 1214070627|%e %b %Y, %H:%M %Z|agohover

for(f,0,100
end

for(f,0, E2
end

;)

unfold Re: Optimize Me #2 by darkstone knightdarkstone knight, 1214070627|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
burrburr 1214083578|%e %b %Y, %H:%M %Z|agohover

@builderboy: That's good to know, you should add that info to the rand( command page.

Do you guys see any more optimizations to be made to the program? Should we move on to the next program?

unfold Re: Optimize Me #2 by burrburr, 1214083578|%e %b %Y, %H:%M %Z|agohover
Re: Optimize Me #2
builderboybuilderboy 1214090873|%e %b %Y, %H:%M %Z|agohover

Oh, wow, i can edit pages.

"Wanders off"

Alright i edited it. Woot for me!

And thankz

unfold Re: Optimize Me #2 by builderboybuilderboy, 1214090873|%e %b %Y, %H:%M %Z|agohover
new post
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License