This is my version of Frogger that I wrote for my TI 84 plus CE:

Code:

"Frogger"->Str1
10->Z
prgmZTITLE
Lbl T
10->Y
13->X
"O"->Str2
randInt(3,13)->B
randInt(15,26)->C
randInt(3,13)->D
randInt(15,26)->E
randInt(3,13)->F
randInt(15,26)->G
2->H
15->I
randInt(2,26)->J
0->K
0->L
0->M
0->N
0->O
0->P
Output(1,1,"++_++++_++++_++++_++++_+++")
Output(2,1,"--------------------------")
Output(3,1,"--------------------------")
Output(4,1,"--------------------------")
Output(5,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")
Output(6,1,"--------------------------")
Output(7,1,"--------------------------")
Output(8,1,"--------------------------")
Output(9,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")
Output(10,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")
Repeat L=1 and M=1 and N=1 and O=1 and P=1
   Output(Y,X,"X")
   Output(6,B,"-")
   If B=26
   Then
      1->B
   Else
      B+1->B
   End
   Output(6,B,"D")
   Output(6,C,"-")
   If C=26
   Then
      1->C
   Else
      C+1->C
   End
   Output(6,C,"D")
   Output(7,D,"-")
   If D=1
   Then
      26->D
   Else
      D-1->D
   End
   Output(7,D,"D")
   Output(7,E,"-")
   If E=1
   Then
      26->E
   Else
      E-1->E
   End
   Output(7,E,"D")
   Output(8,F,"-")
   If F=26
   Then
      1->F
   Else
      F+1->F
   End
   Output(8,F,"D")
   Output(8,G,"-")
   If G=26
   Then
      1->G
   Else
      G+1->G
   End
   Output(8,G,"D")
   Output(2,H-1,"--")
   If H=26
   Then
      2->H
   Else
      H+1->H
   End
   Output(2,H-1,"==")
   Output(3,round(I-1,0),"--")
   If I=2
   Then
      26->I
   Else
      I-0.5->I
   End
   Output(3,round(I-1,0),"==")
   Output(4,J-1,"--")
   If J=26
   Then
      2->J
   Else
      J+1->J
   End
   Output(4,J-1,"==")
   If Str2="=" and (Y=2 or Y=4)
   Then
      If X=26
      Then
         "-"->Str2
      Else
         X+1->X
      End
   Else
      If Str2="=" and Y=3
      Then
         If X=1
         Then
            "-"->Str2
         Else
            If I=int(I)
            X-1->X
         End
      End
   End
   If (Y=2 or Y=3 or Y=4) and not(Str2="=")
   Then
      "You Drowned!"->Str1
      8->Z
      Goto A
   End
   If (Y=6 and (X=B or X=C)) or (Y=7 and (X=D or X=E)) or (Y=8 and (X=F or X=G))
   Then
      "You Got Squished!"->Str1
      6->Z
      Goto A
   End
   getKey->K
   If not(K=0)
   Then
      Output(Y,X,Str2)
      If K=25 and (not(Y=2) or (X=3 or X=8 or X=13 or X=18 or X=23))
      Then
         Y-1->Y
         If Y=1
         Then
            If X=3
            1->L
            If X=8
            1->M
            If X=13
            1->N
            If X=18
            1->O
            If X=23
            1->P
            Output(Y,X,"X")
            10->Y
            13->X
         End
      End
      If K=34 and not(Y=10)
      Y+1->Y
      If K=26 and not(X=26)
      X+1->X
      If K=24 and not(X=1)
      X-1->X
      If K=23
      Then
         ClrHome
         Stop
      End
      If Y=5 or Y=9 or Y=10
      Then
         "O"->Str2
      Else
         If (Y=2 and (H=X or H-1=X)) or (Y=3 and (round(I,0)=X or round(I-1,0)=X)) or (Y=4 and (J=X or J-1=X))
         Then
            "="->Str2
         Else
            "-"->Str2
         End
      End
   End
End
"You Win!"->Str1
Lbl A
prgmZTITLE
Goto T

And this is the ZTITLE program that I reference a couple times in there:

Code:

ClrHome
Output(1,1,"**************************")
1->A
Repeat A=9
   A+1->A
   Output(A,1,"*")
   Output(A,26,"*")
End
Output(10,1,"**************************")
Output(4,Z,Str1)
Pause "",1
ClrHome

Use the arrow keys to move and press del to quit. Let me know what you guys think! Smile
Very cool!

I like what you've done here.

There are some very simple things that you can do to make your program a lot smaller and faster. Here are some improvements that stood out to me.

TI-BASIC is kind of a weird language in that you don't need to include closing parenthesis or quotes at the end of a line or before a store arrow.

Stuff like Output(A,1,"*") can be changed to Output(A,1,"* with no problems- this saves you two bytes and there are a bunch of these in your program.

You can also optimize your clearing of variables- there's a funny command called DelVar. In this case, it sets a variable to zero and doesn't require a newline after it (unless the next line is a loop like While, For, or Repeat). You can chain them as follows.


Code:
0->K
0->L
0->M
0->N
0->O
0->P

can be turned into

Code:
DelVar KDelVar LDelVar MDelVar NDelVar ODelVar P

which easily saves several bytes.

Edit:
You have a memory leak. The TI-Basic interpreter sets aside a little bit of ram every time it encounters a statement requiring an End. If you use Lbl/Goto to exit these loops, this memory will not be given back until the program ends. The usage of these commands is generally looked down upon for these reasons.

Here's another simple optimization, just for fun:

Code:
Repeat L=1 and M=1 and N=1 and O=1 and P=1

can be

Code:
Repeat LMNOP

(If any of them are zero, L*M*N*O*P will be zero, but if all of them are 1, the whole result will be 1, and every number besides zero is treated as a "true" value in TI-BASIC)

There are a bunch of other algorithm improvements, but I'll let you and others find and point these out. Check out this page, it has a bunch of useful tips and tricks you can use to improve your program.

Happy optimizing!
There are a few low hanging fruits in your code when it comes to optimization. Here are a few small modifications that could be worth putting in.

Code:
If K=25 and (not(Y=2) or (X=3 or X=8 or X=13 or X=18 or X=23))

could be

Code:
If K=25 and (Y≠2 or max(X={3,8,13,18,23



Code:
If B=26
Then
1->B
Else
B+1->B
End

could be

Code:
1+remainder(B,26->B

Same goes for F and G of course.


Code:
If K=34 and not(Y=10)
Y+1->Y
If K=26 and not(X=26)
X+1->X
If K=24 and not(X=1)
X-1->X

could be

Code:
Y+(K=34 and Y≠10->Y
X+(K=26 and X≠26)-(K=24 and X≠1->X



Code:

Output(2,1,"--------------------------")
Output(3,1,"--------------------------")
Output(4,1,"--------------------------")
Output(5,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")
Output(6,1,"--------------------------")
Output(7,1,"--------------------------")
Output(8,1,"--------------------------")
Output(9,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")
Output(10,1,"OOOOOOOOOOOOOOOOOOOOOOOOOO")

Here you could start by using Ans to save over 200 bytes...

Code:
"-------------
Ans+Ans
Output(2,1,Ans
Output(3,1,Ans
Output(4,1,Ans
Output(6,1,Ans
Output(7,1,Ans
Output(8,1,Ans
"OOOOOOOOOOOOO
Ans+Ans
Output(5,1,Ans
Output(9,1,Ans
Output(10,1,Ans
Thanks for all the help guys! I'm obviously new to this and these are all very helpful Smile
  
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