So here we have a little game of Tic Tac Toe I've made. It runs well on TI-83/84 calculators and it doesn't seem to have any problems. However, I'd like to eliminate some of the code that seems bulky and repetitive as well as possibly add some checks so you can't overwrite a square that's already been played and to finish the game when a row of 3 has been made. If anyone could help me I'd appreciate it!

:Horizontal 9
:Horizontal 3
:Horizontal -3
:Horizontal -9
:Vertical 9
:Vertical 3
:Vertical -3
:Vertical -9
:Input F
:Disp "USE 1 THROUGH 9"
:Lbl 1
:Input M
:If H=-2
:If M>3
:If M>6
:If F
:If I=9
:Goto 2
:Goto 1
:Lbl 2

Disclaimer: I only have a TI-85, whose commands are slightly different from the TI-83 and TI-84.

User Experience

  • At first, I was puzzled by the numbering of the squares. Then I realized that squares 1 to 9 corresponded nicely to the way the calculator number pad is laid out. Nice!
  • You could probably do without the lines at ±9, as a tic-tac-toe board is conventionally drawn as #, with no borders.
  • There's not much point in asking who goes first, in my opinion.
  • As you noted, you fail to check whether a square is already occupied. A nine-element list could easily be used to perform that check.


  • Variables X and O are defined but never used.
  • I don't know why you chose to name your variables F and M. I would have picked P for "player" and S for "square".
  • The two-argument form of the Input command can also display the prompt.
  • fPart(M/3)3-2→H didn't work for me. Due to the way precedence of operations works on the TI-85, it is evaluated at fPart((M/3)3)-2→H. Rewriting it as 3fPart(M/3)-2→H fixes it.
  • The code to map M to H and V is excessively complicated. Each assignment should be done in one line:

    6 int((M-4)/3)→V

    The TI-84 has remainder() instead of mod().
    The TI-83 has neither remainder() nor mod(), and must use 6(3fPart((M-1)/3)-1)→H.
    I believe the latter is works for all three models.

  • Your use of Goto is unjustified. I should be initialized, tested, and incremented using a For( loop.
  • To toggle F between 0 and 1, just do 1-F→F. You don't need an abs function.
  • I'm not sure that ClrDraw adequately resets the drawing context. On the TI-85, I need ClDrw, ZStd (to set the bounds to the standard zoom), and AxesOff (to hide the axes).

Rewrite for the TI-85 dialect

I've noted what I believe the equivalent TI-83 / TI-84 commands are, based on reading the Guidebooks.

:ClLCD                       Equivalent to ClrHome?
:ClDrw                       Equivalent to ClrDraw?
:ZStd                        Equivalent to ZStandard?
:DrawF -3                    Equivalent to Horizontal?
:DrawF 3
:Vert -3                     Equivalent to Vertical?
:Vert 3
:Input "Square (1-9)? ",S
:6(mod(S-1,3)-1)→H           See portability note above.
:6 int((S-4)/3)→V
:If P
:Circl(H,V,2)                Equivalent to Circle?
  • \$\begingroup\$ Hey, thanks for your answer. Since then I've moved on to For loops and proper one-liners. Just wanted to mention that the idea behind assigning X and O was that the user could input X or O as who goes first, and it would either evaluate to true (X) or false (O) in the If F line. \$\endgroup\$ – Timtech Aug 3 '17 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.