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
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```_________________
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
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
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. I'm looking forward to seeing what HoboNerd thinks of the optimizations when he returns._________________
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.
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,) displays something on the homescreen at X,Y sub(,,) is substring. The way this works is that it takes characters from a string starting with . Str# is Str1, Str2,... (found by pressing VARS->7)_________________CALCnet Tournament-38% deviantArt
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
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. _________________
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. 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 ```
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%
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?
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._________________
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
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.

»
 » Goto page Previous  1, 2 Page 2 of 2 » All times are GMT - 5 Hours

 Jump to: Select a forum Announcements----------------Cemetech AnnouncementsCemetech LabsContests General Discussion----------------Technology & Calculator Open Topic-- Electronics/Hardware Development-- Calculator HardwareYour ProjectsGeneral Open Topic-- Politics & Rants-- Reviews-- Humour/Jokes Cemetech's Projects----------------Doors CSSourceCoderMember Features-- TI-Freak8x-- Merthsoft-- GrammerOther & Upcoming Projects-- The BASIC Elite-- mobileTunes-- CALCnet 2.2-- SuggestionsProgramming the TI-83 Plus/TI-84 PlusUsing the TI-83 Plus/TI-84 PlusWebsite Programming & Design----------------General Programmingz80 AssemblyTI-BASICCasio Prizm/FX Development & ProgrammingWebsite Markup & ScriptingGraphics1337 Programming Tips Building with Blocks----------------FreeBuild, LEGO, and Minecraft-- FreeBuild General-- Suggestions & Troubleshooting-- Content & Gallery-- Servers & Activities
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.