This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
SJH


Newbie


Joined: 12 Jun 2004
Posts: 8

Posted: 12 Jun 2004 10:17:28 pm    Post subject:

I have created a Pong program, but I am not very good at optimizing, so I was wondering if anyone here would be willing to help me optimize my program. Any optimizations are appreciated. The code is listed below.


Code:
Lbl 1
ClrHome
Output(1,3,"CLASSIC PONG
Output(3,3,">1-PLAY WALL
Output(4,4,"1-PLAY W/AI
Output(5,4,"1-P VS. 2-P
Output(6,4,"AI  VS.  AI
Output(8,3,"(C)2004  SJH
3->W:1->B:70->C
1->dim(L1
If not(L1(1
10->L1(1
Repeat K=105
Repeat Ans
getKey->K
C-1->C
If not(C
Then
not(B->B
70->C
End
If B
Then
Output(8,3,"(C)2004  SJH
Else
Output(8,3,"HIGHSCORE:
Output(8,13,L1(1
End
End
Output(W,3,"one space
W+(K=34 and W<6)-(K=25 and W>3->W
Output(W,3,">
End
3->A:3->B:9->C
9->D:0->E:1->S
1->T:3->Y:3->X
If W=3:0->C
Repeat K=45 or E
ClrHome
Output(A,16,"]
Output(8,15,C
If W(not equal to)3
Then
Output(B,1,"[
Output(8,2,D
End
Output(Y,X,"O
T(Y>1 and Y<8)+(Y=1)-(Y=8->T
S(X>1 and X<16)+(X=1)-(X=16->S
Y+T->Y
X+S->X
If W=4 or W=6
Then
randInt(1,5->I
randInt(-1,1->J
If I=1:B+J->B
B+T->B
If B>8:8->B
If B<1:1->B
End
If W=6
Then
randInt(1,5->I
randInt(-1,1->J
If I=1:A+J->A
A+T->A
If A>8:8->A
If A<1:1->A
End
getKey->K
If W(not equal to)6
A+(K=34 and A<8)-(K=25 and A>1->A
If W(not equal to)6 and W(not equal to)4
B+(K=31 and B<8)-(K=21 and B>1->B
C+(X=16 and Y=A and W=3)-(X=16 and Y(not equal to)A and W(not equal to)3->C
D-(X=1 and Y(not equal to)B and W(not equal to)3->D
X=16 and Y(not equal to)A and W=3 or X=16 and C=0 or X=1 and D=0->E
End
Output(4,4,"GAME OVER!
If W=4 and D=0
Output(5,5,"1P Wins!
If W=4 and C=0
Output(5,5,"1AI Wins!
If W=5 and D=0
Output(5,5,"1P Wins!
If W=5 and C=0
Output(5,5,"2P Wins!
If W=6 and D=0
Output(5,5,"1AI Wins!
If W=6 and C=0
Output(5,5,"2AI Wins!
If W=3 and C>L1(1
Then
C->L1(1
Output(5,5,"New High!
End
Pause
For(X,3,6
Output(X,4,"eleven spaces
End
Output(3,6,"AGAIN?
Output(5,7,">YES
Output(6,8,"NO
5üW
Repeat K=105
Repeat Ans
getKey->K
End
Output(W,7,"one space
W+(K=34 and W<6)-(K=25 and W>5->W
Output(W,7,">
End
If W=5:Goto 1
ClrHome


Last edited by Guest on 15 Jun 2004 01:04:19 am; edited 1 time in total
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 13 Jun 2004 10:03:04 am    Post subject:

I typed in some of the program and noteced > kept blinking but you were using Repeat Ans. GetKey -> K needs to be at the bottom of the loop.

.....
Else
Output(8,3,"HIGHSCORE:
Output(8,13,L1(1
End END OF IF B
GetKey -> K ---- ADD THIS
End ---- END of RETURN ANS LOOP
Output(W,3,"one space
W+(K=34 and W<6)-(K=25 and W>3->W
Output(W,3,">
End
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 14 Jun 2004 11:47:13 am    Post subject:


Code:
Repeat W=5
ClrHome
Disp "  CLASSIC PONG
Output(3,3,">1-PLAY WALL
Output(4,4,"1-PLAY W/AI
Output(5,4,"1-P VS. 2-P
Output(6,4,"AI  VS.  AI
Output(8,3,"(C)2004  SJH
3->W:1->B:70->C
1->dim(L1
If not(L1(1
10->L1(1
Repeat K=105
Repeat K
getKey->K
C-1->C
If not(C
Then
not(B->B
70->C
End
If B
Then
Output(8,3,"(C)2004  SJH
Else
Output(8,3,"HIGHSCORE:
Output(8,13,L1(1
End
End
W+(K=34)-(K=25
Ans+4(Ans=2 or Ans=7
If Ans-W
Then
Output(W,3,"one space
Ans -> W
Output(W,3,">
End
End
3->A:3->B
9->D:DelVar E1->S
1->T:3->Y:3->X
9(W != 3 -> C
Repeat K=45 or E
ClrHome
Output(A,16,"]
Output(8,15,C
If W(not equal to)3
Then
Output(B,1,"[
Output(8,2,D
End
Output(Y,X,"O
T(Y>1 and Y<8)+(Y=1)-(Y=8->T
S(X>1 and X<16)+(X=1)-(X=16->S
Y+T->Y
X+S->X
If W=4 or W=6
Then
B+T+randInt(-1,1)(rand<.2->B
If B>8:8->B
If not(B
1->B
End
If W=6
Then
A+T+randInt(-1,1)(rand<.2->A
If A>8:8->A
If not(A
1->A
End
getKey->K
If W(not equal to)6
A+(K=34 and A<8)-(K=25 and A>1->A
If W(not equal to)6 and W(not equal to)4
B+(K=31 and B<8)-(K=21 and B>1->B
C+(X=16 and Y=A and W=3)-(X=16 and Y(not equal to)A and W(not equal to)3->C
D-(X=1 and Y(not equal to)B and W(not equal to)3->D
X=16 and Y(not equal to)A and W=3 or X=16 and C=0 or X=1 and D=0->E
End
Output(4,4,"GAME OVER!
If W=4 and not(D
Output(5,5,"1P Wins!
If W=4 and not(C
Output(5,5,"1AI Wins!
If W=5 and not(D
Output(5,5,"1P Wins!
If W=5 and not(C
Output(5,5,"2P Wins!
If W=6 and not(D
Output(5,5,"1AI Wins!
If W=6 and not(C
Output(5,5,"2AI Wins!
If W=3 and C>L1(1
Then
C->L1(1
Output(5,5,"New High!
End
Pause
For(X,3,6
Output(X,4,"eleven spaces
End
Output(3,6,"AGAIN?
Output(5,7,">YES
Output(6,8,"NO
5->W
Repeat K=105
Repeat Ans
getKey->K
End
If K=34 or K=25
11-W
If Ans != W
Then
Output(W,7,"one space
Ans -> W
Output(W,7,">
End
End
End
ClrHome
"
Back to top
SJH


Newbie


Joined: 12 Jun 2004
Posts: 8

Posted: 14 Jun 2004 06:42:15 pm    Post subject:

Thanks for the help with optimizing, Sir Robin and rebel.socom. I have further optimized my Pong program, adding your guys optimizations with my own. Now, my Pong program is under 1000 bytes. That was my goal with optimizing, so I am happy. Again, thanks to Sir Robin and rebel.socom.

Last edited by Guest on 15 Jun 2004 03:03:03 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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement