well I was bored and it was science class, so I made a game.
you can download it here if you want.
this is the code, any optimizations that I could make?

Code:
:1→D
:ClrHome
:Output(1,6,"HUNT
:Output(2,4,"By: Eeems
:For(A,3,5)
:Output(A,1,"T--------------π
:End
:Output(6,4,"Dificulty
:DelVar KWhile K≠105
:Output(7,5,sub(" EASY  MED   HARD INSANE",6D-5,6
:0:Repeat Ans:getKey:End:Ans→K
:If K=25:D+1→D
:If K=34:D-1→D
:If D=0:4→D
:If D=5:1→D
:End
:If D=3:5→D
:If D=4:8→D
:If D=5:16→D
:randInt(1,16→S:randInt(1,8→T
:S→N:T→O
:randInt(1,16→X:randInt(1,8→Y
:DelVar EDelVar HDelVar GDelVar KClrHome:99→F
:For(A,1,5)
:randInt(1,8)→L1(A
:randInt(1,16)→L2(A
:End
:While K≠105 and F
:E+1→E
:If E=60:Then
:G+1→G
:DelVar E
:End
:If G=60:Then
:H+1→H
:DelVar G
:End
:Output(1,15,F
:S→N:T→O
:If randInt(0,1
:Then
:S+randInt(‾D,D→S
:Else
:T+randInt(‾D,D→T
:End
:If S<1
:1→S:If T>7:8→T
:If T<1
:1→T:If S>16:16→S
:For(A,1,5
:Output(L1(A),L2(A),"*
:If S=L2(A) and L1(A)=T:Then
:N→S:O→T
:End:End
:If S≠N xor T≠O
:Output(O,N,"
:Output(T,S,"π
:getKey→K
:If K:Then
:Output(Y,X,"
:X-(K=24)+(K=26
:Ans+not(Ans)-(Ans=17→X
:Y-(K=25)+(K=24
:Ans+not(Ans)-(Ans=9→Y
:End
:Output(Y,X,"T
:If S=X and T=Y:Then
:F-1→F
:If F=9:Output(1,16,"
:End
:If K=21:Then
:ClrHome:Pause
:End:End
:ClrHome:Disp "Time:",H,G,E,"Score:",10000-(2(70H)D+70GD+ED)+99-F
:Output(2,1,"Hours:
:Output(3,1,"Mintes:
:Output(4,1,"Loops:
You have some quite-nicely optimized code there, although after working with more advanced languages so much lately TI-BASIC looks quite awkward. Here's one optimization that I can see:
Code:
:If S<1
:1→S:If T>7:8→T
:If T<1
:1→T:If S>16:16→S
to
Code:
:(S<1)+16(S>16)+S(S>0)(S<17→S
:(T<1)+8(T>7)+T(T>0)(T<8→T
ok, I'll change the code as soon as I wrap my head around that change. Thanks by the way, somebody on Omnimagna gave me this optimization though

Code:
:X-(K=24)+(K=26
:Ans+not(Ans)-(Ans=17→X
:Y-(K=25)+(K=24
:Ans+not(Ans)-(Ans=9→Y

otherwise you might have caught it. I hate Booleans, they mess with my mind
Eeems wrote:
otherwise you might have caught it. I hate Booleans, they mess with my mind


Yeah, stupid "true" or "false" is so freaking complicated. Why couldn't it be simpler? Two possible values are way too many Rolling Eyes
Kllrnohj wrote:
Eeems wrote:
otherwise you might have caught it. I hate Booleans, they mess with my mind


Yeah, stupid "true" or "false" is so freaking complicated. Why couldn't it be simpler? Two possible values are way too many Rolling Eyes


It's not that there are too many possible answers, but too many possible questions and ways to get that answer Razz
what UD said, and then there is mixing them together, and such
booleans aren't so bad, TI-BASIC just isn't a good way to learn them.

Now for your optimizations:
always use if:then, even with just one line, because it's faster. always leave parenthesis open whenever possible [except on For( loops]
also, If you have a chain of mutually exclusive if:then statements, consider using a bunch of nested if:then:else.
I don't know if there are any situations where you might use this, because I only checked the syntax for optimizations, not the logic.
also, if you need to generate several (probably at least 3 to be effective) random integers at the same time, randInt( takes a third argument of how many and returns a list. (probably not useful in this situation)
right, forgot about the if then part, but I remembered the ')' at the end of a for loop! I think.
EDIT: hey I caught that edit, hmm, I think I could use the list and generate it at the start and then just call up the vars later on, thanks
For the If...Then tip, keep in mind that you should only use that if you are going for speed over size. If it's an even optimization or weighted towards small size, omit the then/end for single-statement Ifs.
Well I'm going for speed on this one, because displaying the "trees" slows it down a bit, so I'm going to try and speed it up as much as I can. I did some more work on it, but I'm at school right now, so I'll update the code as soon as I get home.
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement