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 110 users online: 8 members, 78 guests and 24 bots.
Members: 16aroth6, flyingfisch, LuxenD, qazz42, Spyro543, tifreak8x, willwac.
Bots: MSN/Bing (1), Magpie Crawler (3), Googlebot (20).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    » Goto page 1, 2, 3  Next
» View previous topic :: View next topic  
Author Message
rcplanegy


Member


Joined: 23 Sep 2010
Posts: 174

Posted: 09 Oct 2010 03:59:17 pm    Post subject: Optimization Help: Moon Lander Game

here is a moon lander game. movement, crashing, fuel count, and gravity all work. i need 3-5 landing pads, a way to 'refuel' at those landing pads, a way to pause when you touch a landing pad so you dont fly right through it and crash, and a way to count scores... THE FIRST PERSON TO MAKE A FEASIBLE, WORKING OPTIMIZATION GETS THERE NAME IN THE CREDITS!!!!!!


Code:
:31→Z
:47→X
:1→W
:100→G
:Lbl 1
:If Z≤7 and Z≥0:Text(34,47,"CRASH!"
:If Z≤7 and Z≥0:Stop
:If G≤0:0→G
:W+.5→W
:Z-W→Z
:Horizontal(0
:Text(1,1,"FUEL:"
:Text(1,20,G
:Line(X-1,Z,X+1,Z
:Line(X-2,Z-1,X+2,Z-1
:Line(X-1,Z-2,X+1,Z-2
:Line(X-2,Z-3,X-2,Z-4
:Line(X+2,Z-3,X+2,Z-4
:Line(X,Z-3,X,Z-3
:If G≥1:Goto 2
:If G≤0:Goto 1
:Lbl 2
:If K=34:Line(X,Z-5,X,Z-6
:getKey→K
:If K=24:X+2→X:Z+.5→Z
:If K=34:Z+3→Z
:If K=34:W-1.25→W
:If K=26:X-2→X:Z+.5→Z
:If K=34:Line(X,Z-5,X,Z-6
:If K=34:G-1→G
:ClrDraw
:Goto 1

_________________
Learning consists of questions and answers
With every question we discover answers.
With those answers we uncover more questions.
So, are you answering your questions...
...Or questioning your answers?
Back to top
qazz42


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 04:03:55 pm    Post subject:

instead of using labels to loop why dont you use a for() or while/repeat loop?
_________________


Back to top
MufinMcFlufin


Advanced Member


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

Posted: 09 Oct 2010 04:04:46 pm    Post subject:

Repeat would probably be best in this situation.
_________________

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


Power User


Joined: 14 Jun 2010
Posts: 408

Posted: 09 Oct 2010 04:06:46 pm    Post subject:

^++ I second the notion of loops, etc. (not to mention that "If Condition1:Statement1:If Condition1:Statement2" can be condensed to "If Condition1:Then:Statement1:Statement2:End"). We can always help on that.
After that's done so it's more readable, I might help Smile
_________________
People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster.
-Adam Osborne
Back to top
MufinMcFlufin


Advanced Member


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

Posted: 09 Oct 2010 04:18:47 pm    Post subject:

rcplanegy, are you sure this program works as is? I put it on my calculator, and it doesn't seem to work almost at all.
_________________

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


Guru


Joined: 01 May 2006
Posts: 5106
Location: SFBA, California

Posted: 09 Oct 2010 04:22:54 pm    Post subject:

qazz42 wrote:
instead of using labels to loop why dont you use a for() or while/repeat loop?
His use of Labels is fine. There's nothing wrong with labels in a program this small and when they are used correctly.
_________________


-Alex
Back to top
MufinMcFlufin


Advanced Member


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

Posted: 09 Oct 2010 04:24:34 pm    Post subject:

comicIDIOT wrote:
qazz42 wrote:
instead of using labels to loop why dont you use a for() or while/repeat loop?
His use of Labels is fine. There's nothing wrong with labels in a program this small and when they are used correctly.

It's not whether or not they're correct, it's that he wants it optimized, and there are better ways than what he's doing here with labels.
_________________

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


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 05:09:54 pm    Post subject:

comicIDIOT wrote:
qazz42 wrote:
instead of using labels to loop why dont you use a for() or while/repeat loop?
His use of Labels is fine. There's nothing wrong with labels in a program this small and when they are used correctly.



yes, but he is asking for optimizations and frankly , loops are a bit faster....

(also, made the first optimization so credits Very Happy)
_________________


Back to top
comicIDIOT


Guru


Joined: 01 May 2006
Posts: 5106
Location: SFBA, California

Posted: 09 Oct 2010 05:13:16 pm    Post subject:

qazz42 wrote:
(also, made the first optimization so credits Very Happy)
Not so.

Quote:
THE FIRST PERSON TO MAKE A FEASIBLE, WORKING OPTIMIZATION GETS THERE NAME IN THE CREDITS!!!!!!
By working, he needs landing pads that pause the game (more than the Pause token), landing pads, a way to count scores, and a method to refuel while landed.

You did none of those Razz

Not to mention you didn't optimize anything. How would you get rid of the labels and add the loops? Share some optimized code with us, rather than suggesting.
_________________


-Alex
Back to top
MufinMcFlufin


Advanced Member


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

Posted: 09 Oct 2010 05:24:15 pm    Post subject:

qazz, you didn't actually change any code.

This is what an optimization looks like:

Code:

:0→Xmin
:1→ΔX
:0→Ymin
:1→ΔY
:E2→F
:31→D
:Ans→E
:47→O
:Ans→P
:DelVar HDelvar VClrDraw
:Repeat D≤.5
:Text(0,1,"FUEL: ",F,"   
:Pt-Off(P,E+1,3
:Pt-Off(P,E,2
:Pt-On(O,D+2
:Pt-On(O,D,2
:Pt-Off(O,D-1,3
:Horizontal(0
:getKey→G
:D→E
:O→P
:If F and max(G={24,25,26,34
:Then
:H-2(G=34)+2(G=25→H
:V+2(G=26)-2(G=24→V
:F-1→F
:End
:H-1→H
:D+HE‾2→D
:O+VE‾2→O
:End
:Pt-Off(O,2,2
:Pt-Off(O,3,2
:40≥√(H2+V2
:Pt-On(O,1,3-Ans
:Pt-On(O,2+Ans
:Text(6,1,sub("CRASHED!SAFE!",1+8Ans,8-3Ans
:Pause

Haven't added anything that wasn't already in the game, but it's smaller now, and has safe/crashed landing.
_________________

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


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 09 Oct 2010 05:39:26 pm    Post subject:

Why don't you use the SourceCoder optimizer?

http://sc.cemetech.net
_________________
CALCnet Tournament-38%


deviantArt
Back to top
calcdude84se


Power User


Joined: 14 Jun 2010
Posts: 408

Posted: 09 Oct 2010 05:46:54 pm    Post subject:

It's not that kind of optimizer Razz
To my knowledge it does little more than removing closing parentheses/etc. and using Delvar.
Correct me if I'm wrong Smile
_________________
People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster.
-Adam Osborne
Back to top
qazz42


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 05:54:38 pm    Post subject:

comicIDIOT wrote:
qazz42 wrote:
(also, made the first optimization so credits Very Happy)
Not so.

Quote:
THE FIRST PERSON TO MAKE A FEASIBLE, WORKING OPTIMIZATION GETS THERE NAME IN THE CREDITS!!!!!!
By working, he needs landing pads that pause the game (more than the Pause token), landing pads, a way to count scores, and a method to refuel while landed.

You did none of those Razz

Not to mention you didn't optimize anything. How would you get rid of the labels and add the loops? Share some optimized code with us, rather than suggesting.


hmm, bah, good point x.x

unfortunetly, the TI-Basic part of my brain is not functioning, but I will tell you what I come up with later if I get the time >.>
_________________


Back to top
KermMartian


Site Admin


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

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

calcdude84se wrote:
It's not that kind of optimizer Razz
To my knowledge it does little more than removing closing parentheses/etc. and using Delvar.
Correct me if I'm wrong Smile
That's correct. There is a topic in the SourceCoder subforum about why its optimizer works the way it does, actually, and a call for suggestions and code from people who want to make it smarter. At rcplanegy, I recommend you work through your program piece by piece, add functionality one thing at a time (ie, first the craft movement, then drawing the pads, etc etc), and present each of the pieces of code to us to optimize. Therefore, after we finish helping you with this, I recommend that you try to add your extra features that you suggested, and present that code to us, rather than asking us to write the extra features for you. Smile
_________________


Back to top
MufinMcFlufin


Advanced Member


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

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

KermMartian wrote:
calcdude84se wrote:
It's not that kind of optimizer :P
To my knowledge it does little more than removing closing parentheses/etc. and using Delvar.
Correct me if I'm wrong :)
That's correct. There is a topic in the SourceCoder subforum about why its optimizer works the way it does, actually, and a call for suggestions and code from people who want to make it smarter. At rcplanegy, I recommend you work through your program piece by piece, add functionality one thing at a time (ie, first the craft movement, then drawing the pads, etc etc), and present each of the pieces of code to us to optimize. Therefore, after we finish helping you with this, I recommend that you try to add your extra features that you suggested, and present that code to us, rather than asking us to write the extra features for you. :)

Kerm++

Huge reason why I didn't add any functionality to the optimized program I made.

Besides, most people aren't going to go through those sorts of hoops if you're rewarding them a spot in the credits for a game they made.
_________________

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


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 10:22:53 pm    Post subject:

also, one thing I would like to point out is not to use stop, it is considered bad programming style. Use return instead...

just to say that it can sometimes mess up a shell's parser
_________________


Back to top
KermMartian


Site Admin


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

Posted: 09 Oct 2010 10:41:31 pm    Post subject:

qazz42 wrote:
also, one thing I would like to point out is not to use stop, it is considered bad programming style. Use return instead...

just to say that it can sometimes mess up a shell's parser
An excellent point, qazz42. As of Doors CS 7, DCS successfully catches and mitigates the problems associated with Stop, but if you disable the library support, use a competitor shell, or use DCS 6.2 or earlier, Stop can cause problems.
_________________


Back to top
qazz42


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 10:44:38 pm    Post subject:

Yikes, the lib support option also combats the stop crappyness? Weird... I would think it to be the parser hook...

anywho, I remember I crashed many calcs a day using stop with mirageOS
_________________


Back to top
KermMartian


Site Admin


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

Posted: 09 Oct 2010 10:47:16 pm    Post subject:

qazz42 wrote:
Yikes, the lib support option also combats the stop crappyness? Weird... I would think it to be the parser hook...

anywho, I remember I crashed many calcs a day using stop with mirageOS
I understand your confusion, let me clarify. The Parser Hook, aka HomeRun, is one parser hook: it catches program executions at the homescreen. That's all. Enabling/disabling third-party hybrid library support makes a different parser hook be enabled while a program is actually executing; that hook looks for real(, sum(, det(, and identity. I made it also watch for Stop, and if it is about to run it, throw a special type of TI-OS error code that Doors CS then catches and handles as a clean exit instead of letting the OS deal with it.
_________________


Back to top
qazz42


Vampire Killer


Joined: 07 Apr 2010
Posts: 4177

Posted: 09 Oct 2010 10:49:16 pm    Post subject:

hmm, I get it, seems fair enough Very Happy

also, one more thing, the waiy you have

:If G≥1:Goto 2
:If G≤0:Goto 1

would be easier to read if it said

:If G≥1
:Goto 2
:If G≤0
:Goto 1

it just makes it a bit more understandable and easier on the eyes
_________________




Last edited by qazz42 on 09 Oct 2010 11:02:10 pm; edited 1 time in total
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 1, 2, 3  Next
» View previous topic :: View next topic  
Page 1 of 3 » 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.041040 seconds.