CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 123 users online: 1 member, 85 guests and 37 bots.
Members: Ashbad.
Bots: VoilaBot (4), Spinn3r (1), Magpie Crawler (3), VoilaBot (10), Googlebot (19).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    » Goto page Previous  1, 2
» View previous topic :: View next topic  
Author Message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55886
Location: Earth, Sol, Milky Way

Posted: 07 Oct 2010 05:08:45 pm    Post subject:

This is an epic optimization, I'll explain it when I get home:


Code:
:DCS
:"7EFFC3C0C0C3FF7E
:ClrHome
:Output(1,4,"CALCULATOR
:Output(2,7,"DUEL
:Output(7,4,"PRESS ENTER
:Pause
:ClrHome
:Output(1,5,"CONTROLS
:Output(3,1,"LEFT AND RIGHT
:Output(4,1,"ARROWS MOVE
:Output(6,1,"EXIT- CLEAR
:Output(7,1,"DROP BOMBS- 2ND
:Pause
:ClrHome
:7→X
:DelVar SDelVar B1→W
:Repeat 45=abs(K
:Output(2,X,"(*)"
:Output(8,W," <=>"
:W+1→W
:If W=14:Then
:Output(8,14,"   
:1→W:End
:If B:Then
:Output(C,B,"
:C+1→C
:If C=9:Then
:B=W+1
:Output(4,6,sub("MISS!HIT! ",1+5Ans,5
:S+Ans→S
:Output(6,5,"SCORE:
:Output(6,12,S
:DelVar B
:Else
:Output(C,B,"*
:End:End
:getKey→K
:If 1=abs(K-25
:Output(2,X,"   
:X+(K=26)-(K=24→X
:X+14(not(X)-(X=15→X
:If K=21:Then
:X+1→B:2→C
:End
:End

_________________


Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 07 Oct 2010 05:09:36 pm    Post subject:

I also use labels, but only for menus. As for hobonerd, he has a lot of things to learn. His style of programming reminds me of my style last year.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
Weregoose


Cemetech Expert


Joined: 23 Oct 2009
Posts: 467

Posted: 07 Oct 2010 05:10:50 pm    Post subject:

Same gameplay, radically different way of structuring it:

Code:
:7→A
:8→B
:DelVar C1→D
:ClrHome
:Repeat E=45
:Output(2,A,"( )
:Output(B-6(B=8),A+1,"*
:Output(B-1,A+1,"  //1 space
:getKey→E
:A+(Ans=26)-(Ans=24
:If A≠Ans
:Output(2,A,"    //3 spaces
:If B=8
:Ans+14(not(Ans)-(Ans=15→A
:If D=14
:Output(1,12,"      //5 spaces
:Output(8,D,"    //3 spaces
:If B=7
:Then
:Ans=D→E
:Output(1,12,sub("MISS! HIT!",5Ans+1,5
:C+Ans→C
:If E
:Then
:Output(1,1,"SCORE
:Output(1,7,Ans
:14→D
:End
:End
:D+1-14(D=14→D
:Output(8,Ans,"<=>
:min(8,B+1-6(B=8 and E=21→B
:End
:ClrHome
:"QUITTED


Just to point out one thing in your program:

Code:
:Lbl LT
:X-1→X
:If X<1:Then
:14→X
:Output(2,1,"                "
:Goto 1
:Else
:Output(2,1,"                "
:End
:End

If both outputs are going to happen no matter what number X is, then it would make sense to call them unconditional – the If X<1 doesn't apply to them. Merge the two outputs and slide it up to above the If.

Code:
:Lbl LT
:X-1→X
:Output(2,1,"                "
:If X<1:Then
:14→X
:Goto 1
:Else
:End
:End

This will make the Else have zero lines to execute, so now it can be removed:

Code:
:Lbl LT
:X-1→X
:Output(2,1,"                "
:If X<1:Then
:14→X
:Goto 1
:End
:End

But why Goto 1 now? The lower End is about to carry the interpreter back up to the outermost While. Plus, as you've now heard, this is what causes a memory leak. Remove the Goto...

Code:
:Lbl LT
:X-1→X
:Output(2,1,"                "
:If X<1:Then
:14→X
:End
:End

...and see that the Then now has only one line left to execute. This "If-Then-code-End" block can be reduced to a meager "If-code":

Code:
:Lbl LT
:X-1→X
:Output(2,1,"                "
:If X<1
:14→X
:End


I'll stop there, but there's way more that can be done with this. It really doesn't need to be branched off with labels, for starters.

@KermMartian: That wasn't all written in two minutes! I swear!
_________________
Common Errors in English · How To Ask Questions The Smart Way
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55886
Location: Earth, Sol, Milky Way

Posted: 07 Oct 2010 06:16:01 pm    Post subject:

Weregoose, nicely done on your optimizations. Wink I'm looking forward to seeing what HoboNerd thinks of the optimizations when he returns.
_________________


Back to top
HoboNerd


Newbie


Joined: 06 Oct 2010
Posts: 19

Posted: 07 Oct 2010 08:17:12 pm    Post subject:

@KermMartian: Ok, I like the way Weregoose explained what he did but there are some if-then statements that i would have no idea how to convert.

Also, as I mentioned in my original post, I have only started programming things bigger than running variables through a formula for about a month. I have no idea what these mean:

Delvar, abs(, *how B1 works*, Output(4,6,sub("MISS!HIT! ",1+5Ans,5, Repeat, and your method of getkey...
Most of the other programming, i get the function, but have no idea how it would work together.
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 07 Oct 2010 08:22:47 pm    Post subject:

Delvar deletes a variable. When you use the variable again, the variable is set to 0. Also any command you put after the Delvar statement doesn't need a line break or a colon

abs() is absolute value

Output(Y,X,<Something>) displays something on the homescreen at X,Y

sub(<Str#>,<Start Position>,<Number of characters>) is substring. The way this works is that it takes <Number of characters> characters from a string starting with <Start Position>.

Str# is Str1, Str2,... (found by pressing VARS->7)
_________________
CALCnet Tournament-38%


deviantArt
Back to top
MufinMcFlufin


Advanced Member


Joined: 29 Aug 2009
Posts: 252
Location: C:\Users\Admin\Desktop

Posted: 07 Oct 2010 08:23:12 pm    Post subject:

HoboNerd wrote:
@KermMartian: Ok, I like the way Weregoose explained what he did but there are some if-then statements that i would have no idea how to convert.

Also, as I mentioned in my original post, I have only started programming things bigger than running variables through a formula for about a month. I have no idea what these mean:

Delvar, abs(, *how B1 works*, Output(4,6,sub("MISS!HIT! ",1+5Ans,5, Repeat, and your method of getkey...
Most of the other programming, i get the function, but have no idea how it would work together.

Delvar deletes a variable, and will set it's value to zero, while being one byte more memory efficient than storing the value of zero into said variable. It's also used to delete lists, strings, and matrices, without setting a value to those.

abs( is the absolute value of. Absolute value (just in case you don't already know) basically always makes a number positive.

sub( is the substring. This means that, it will take part of a larger string. With the part of the code you said you didn't understand, it will output "MISS!" if Ans is false (0), and will output "HIT! " if Ans is true (1).

Repeat is a loop like While, except that it will repeat until true. Also it will only check the condition at the end of the loop, so it's always guaranteed to go through the loop at least once.

I haven't gone through the code much yet so I don't know about his use of getKey.
_________________

MufinMcFlufin's quote of the week:
"Diapers and Politicians should both be changed often for the same reason."
-Anonymous
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55886
Location: Earth, Sol, Milky Way

Posted: 07 Oct 2010 10:17:07 pm    Post subject:

Other that what the people above said, what else do you need me to explain from my code? I spent quite a while optimizing it as much as possible (note the absence of labels) and it works functionally-identical to your code, so I'd love to explain anything. Smile
_________________


Back to top
HoboNerd


Newbie


Joined: 06 Oct 2010
Posts: 19

Posted: 09 Oct 2010 08:30:56 am    Post subject:

I made this new version of this program! It no longer lags out.
Laughing
I took out some of the neumerous labels, and of course, fixed the memory leak problem. Any further suggestions? (not more complete optimizations)


Code:

:ClrHome
:Output(1,4,"CALCULATOR
:Output(2,6,"BOMBER
:Output(5,4,"PRESS ENTER
:If O≠0:Output(8,1,"HIGHSCORE-
:If O≠0:Output(8,12,O
:Pause
:ClrHome
:Output(1,5,"CONTROLS
:Output(3,1,"LEFT AND RIGHT
:Output(4,1,"ARROWS MOVE
:Output(6,1,"DROP BOMBS- 2ND
:Output(7,1,"EXIT- CLEAR
:Pause
:ClrHome
:7→X
:DelVar S
:
:While 1
:Output(2,X,"(*)
:Output(8,W," <=>
:W+1→W
:If W=14:Output(8,14,"   "
:If W=14:1→W
:getKey→K
:If K=24:Goto LT
:If K=26:Goto RT
:If K=21:Goto BO
:If K=45:Goto EX
:End
:End
:
:Lbl LT
:X-1→X
:Output(2,1,"                "
:If X<1:14→X
:End
:End
:
:Lbl RT
:X+1→X
:Output(2,1,"                "
:If X>14:1→X
:End
:End
:
:Lbl BO
:X+1→B
:3→Y
:Repeat Y=8
:Output(Y-1,B," "
:Output(Y,B,"*
:Output(8,W," <=>
:Y+1→Y
:W+1→W
:If W=14:Output(8,14,"   "
:If W=14:1→W
:End
:
:Output(Y-1,B," "
:Output(1,12,"     "
:If B=W+1:S+1→S
:If B=W+1:Output(1,13,"HIT!
:If B=W+1:Output(8,1,"                "
:If B=W+1:Output(1,1,"SCORE
:If B=W+1:Output(1,7,S
:If B=W+1:S→O
:If B≠W+1:Output(1,12,"MISS!
:If B=W+1:1→W
:End
:Lbl EX
:ClrHome
:S→O
:Output(1,1,"QUITTED
Back to top
Raylin


Expert


Joined: 05 May 2008
Posts: 567
Location: Illinois Institute of Technology

Posted: 09 Oct 2010 08:52:26 am    Post subject:

Sir, if I may direct you to this topic...

And on that note, you can include the same conditions in one If-Then.


Code:
:If B=W+1
:Then
:S+1→S
:Output(1,13,"HIT!
:Output(8,1,"                "
:Output(1,1,"SCORE
:Output(1,7,S
:S→O
:1→W
:Else
:Output(1,12,"MISS!
:End

_________________



The Labyrinthine Chronicles
Prophecy: 0% (planning)
The Journalist: 0%
Image of Imperfection: 0%
Phantom Sanctuary: 0%
Godslayer: 0%
Back to top
HoboNerd


Newbie


Joined: 06 Oct 2010
Posts: 19

Posted: 09 Oct 2010 09:16:22 am    Post subject:

Would that mean that whenever B=W+1, the loop wouldn't end?
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55886
Location: Earth, Sol, Milky Way

Posted: 09 Oct 2010 06:54:08 pm    Post subject:

I still consider it pretty bad form that you're Goto'ing out of the While loop, but at least you're using Ends properly to recover, so that's good. I still think you should study our restructurings of your programs to see how a change in structure can effect a smaller, faster program with the same functionality.

In regards to your question for Raylin, If/Then/End is not a loop, it's a conditional block. Only While/End, Repeat/End, and For/End are loops.
_________________


Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page Previous  1, 2
» View previous topic :: View next topic  
Page 2 of 2 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.037501 seconds.