Hello all! I am relativly new to TI-Basic and I just finished a tic-tac-toe program today. I know for sure my coding is awful and long but it works. If anyone could give me pointers on how to make it better, that would be great.

The code:
Code:
:0→Xmin:94→Xmax:0→Ymin:62→Ymax:ClrDraw
:CoordOff:AxesOff:GridOff:
:Line(0,55,94,55
:Line(31,54,31,0
:Line(63,54,63,0
:Line(0,17,94,17
:Line(0,35,94,35
:1→T:1→E:1→F:1→G:1→J:1→M:1→L:1→O:1→P:1→Q
:Text(0,24,"PLAYER 1 TURN
:While 1
:If T=1:Then
:Text(0,49,"1"
:getKey→K
:While K=0
:getKey→K
:End
:If K=72 and E≠5 and E≠6:Then
:Line(4,50,26,40
:Line(26,50,4,40
:5→E:2→T
:End
:If K=73 and F≠5 and F≠6:Then
:Line(36,50,58,40
:Line(36,40,58,50
:5→F:2→T
:End
:If K=74 and G≠5 and G≠6:Then
:Line(68,50,90,40
:Line(68,40,90,50
:5→G:2→T
:End
:If K=82 and J≠5 and J≠6:Then
:Line(4,30,26,22
:Line(4,22,26,30
:5→J:2→T
:End
:If K=83 and M≠5 and M≠6:Then
:Line(36,30,58,22
:Line(36,22,58,30
:5→M:2→T
:End
:If K=84 and L≠5 and L≠6:Then
:Line(68,30,90,22
:Line(68,22,90,30
:5→L:2→T
:End
:If K=92 and O≠5 and O≠6:Then
:Line(4,12,26,4
:Line(4,4,26,12
:5→O:2→T
:End
:If K=93 and P≠5 and P≠6:Then
:Line(36,12,58,4
:Line(36,4,58,12
:5→P:2→T
:End
:If K=94 and Q≠5 and Q≠6:Then
:Line(68,12,90,4
:Line(68,4,90,12
:5→Q:2→T
:End
:If E=5 and F=5 and G=5:Then
:Line(4,45,90,45
:Goto W
:End
:If J=5 and M=5 and L=5:Then
:Line(4,26,90,26
:Goto W
:End
:If O=5 and P=5 and Q=5:Then
:Line(4,8,90,8
:Goto W
:End
:If E=5 and J=5 and O=5:Then
:Line(15,50,15,4
:Goto W
:End
:If F=5 and M=5 and P=5:Then
:Line(47,50,47,4
:Goto W
:End
:If G=5 and L=5 and Q=5:Then
:Line(79,4,79,50
:Goto W
:End
:If E=5 and M=5 and Q=5:Then
:Line(2,52,92,2
:Goto W
:End
:If O=5 and M=5 and G=5:Then
:Line(92,52,2,2
:Goto W
:End
:End
:If T=2:Then
:Text(0,49,"2"
:getKey→K
:While K=0:getKey→K:End
:If K=72 and E≠5 and E≠6:Then
:Circle(15,45,6
:6→E:1→T
:End
:If K=73 and F≠5 and F≠6:Then
:Circle(47,45,6
:6→F:1→T
:End
:If K=74 and G≠5 and G≠6:Then
:Circle(79,45,6
:6→G:1→T
:End
:If K=82 and J≠5 and J≠6:Then
:Circle(15,26,6
:6→J:1→T
:End
:If K=83 and M≠5 and M≠6:Then
:Circle(47,26,6
:6→M:1→T
:End
:If K=84 and L≠5 and L≠6:Then
:Circle(79,26,6
:6→L:1→T
:End
:If K=92 and O≠5 and O≠6:Then
:Circle(15,8,6
:6→O:1→T
:End
:If K=93 and P≠5 and P≠6:Then
:Circle(47,8,6
:6→P:1→T
:End
:If K=94 and Q≠5 and Q≠6:Then
:Circle(79,8,6
:6→Q:1→T
:End
:If E=6 and F=6 and G=6:Then
:Line(4,45,90,45
:Goto L
:End
:If J=6 and M=6 and L=6:Then
:Line(4,26,90,26
:Goto L
:End
:If O=6 and P=6 and Q=6:Then
:Line(4,8,90,8
:Goto L
:End
:If E=6 and J=6 and O=6:Then
:Line(15,50,15,4
:Goto L
:End
:If F=6 and M=6 and P=6:Then
:Line(47,50,47,4
:Goto L
:End
:If G=6 and L=6 and Q=6:Then
:Line(79,4,79,50
:Goto L
:End
:If E=6 and M=6 and Q=6:Then
:Line(2,52,92,2
:Goto L
:End
:If O=6 and M=6 and G=6:Then
:Line(92,52,2,2
:Goto L
:End
:End
:End
:End
:End
:End
:Lbl W
:Text(0,49,"1 WINS
:Pause
:ClrDraw:ZStandard:CoordOn:AxesOn:ClrHome:Stop
:Lbl L
:Text(0,49,"2 WINS
:Pause
:ClrDraw:ZStandard:CoordOn:AxesOn:ClrHome


Sorry if this is in the wrong place or I did something wrong. I am new to this website.
I'd love to see that with tabs shown via SourceCoder to make sure all those Ends match properly, unless you've already checked. Your code is not actually that bad, looking at it line-by-line. From a a higher-level perspective, though, there are plenty of things you could. For one thing, you can collapse all that X and O drawing into a loop and a conditional. As Iambian requested on SAX, can you post what the variables do?
If an X or an O is put in a spot, the variable for that spot changes to a 5 or a 6, respectivly. Ex. E is for the top left. If an X is put there E is changed to a 5. Just did that to keep track of all the places that have a mark on them already.

And no, the ends do not match up. I will fix that shortly.
  
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