Casio Calculator Program Library

Program name: Noughts and Crosses (Tic-tac-toe) (v. 1.0)  --(Back to Index)--

CTF file name: noughts.ctf
Author: Tom Lynn
Date: 1995-7
Models: 9700, 9800

Screenshot:

[screenshot]


Description:

   Text based noughts and crosses.
   Works best on 9700 calcs, needs slight editing for 9800s to cope with
   different screen width.  Better on 9700s, as it is based on a scrolling
   bug which was fixed for the 9800.
   
   The numbers on the keypad represent the squares.
   
   The screenshot was taken using Martin Poupe's excellent calculator emulator,
   freely available at http://pages.whowhere.com/computers/martin.poupe/.
   The .cas files needed to run noughts and crosses on this emulator are
   available in zipped form in noughts.zip.  Run the emulator on ~noughts.cas
   from whichever directory you extract the files into.
              
Program source code:
Program "~NOUGHTS+XS" [Main routine]

   #  Glossary
   #
   #    \*              asterisk '*'
   #    (-)             unary minus (as in -5)
   #    \r              r (as in r and theta)
   #    \th             theta (as in r and theta)
   
   6->Q
   Lbl 9
   " "
   Dsz Q
   Goto 9
   0->B~N
   1->P
   Lbl 0
   "\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_
   \*\*\*\*\* Os andXs \*\*\*\*"
   9F+3G+H->\r
   Prog "NXDRAW"
   9I+3J+K->\r
   Prog "NXDRAW"
   9L+3M+N->\r
   Prog "NXDRAW"
   Prog "NXCHK4WIN"
   \th=1=>Goto 1
   B=9=>Goto 2
   P=1=>"Player O (1(-)9)"?->\r
   P=2=>"Player X (1(-)9)"?->\r
   \r<1=>Goto 0
   \r>9=>Goto 0
   \r-1->\r
   Int (.5+3Frac (\r//3->E
   6-3Int (\r/3->D
   F[D+E]<>0=>Goto 0
   P->F[D+E]
   3-P->P
   Isz B
   Goto 0
   Lbl 1
   P=2=>"\*\* Player O wins! \*\*  "
   P=1=>"\*\* Player X wins! \*\*  "
   Goto 3
   Lbl 2
   "\*\*\* It's a draw! \*\*\*  "
   Lbl 3
   " "
              
Program "NXDRAW" [Draw rows of square]

   \r>9=>Prog "NXD2"
   \r>9=>Goto 0
   \r=1=>Goto 1
   \r=2=>Goto 2
   \r=3=>Goto 3
   \r=4=>Goto 4
   \r=5=>Goto 5
   \r=6=>Goto 6
   \r=7=>Goto 7
   \r=8=>Goto 8
   \r=9=>Goto 9
   "# # #"
   Goto 0
   Lbl 1
   "# # O"
   Goto 0
   Lbl 2
   "# # X"
   Goto 0
   Lbl 3
   "# O #"
   Goto 0
   Lbl 4
   "# O O"
   Goto 0
   Lbl 5
   "# O X"
   Goto 0
   Lbl 6
   "# X #"
   Goto 0
   Lbl 7
   "# X O"
   Goto 0
   Lbl 8
   "# X X"
   Goto 0
   Lbl 9
   "O # #"
   Lbl 0
              
Program "NXD2" [Draw other rows of square]

   \r>18=>Prog "NXD3"
   \r>18=>Goto 0
   \r=10=>Goto 1
   \r=11=>Goto 2
   \r=12=>Goto 3
   \r=13=>Goto 4
   \r=14=>Goto 5
   \r=15=>Goto 6
   \r=16=>Goto 7
   \r=17=>Goto 8
   \r=18=>Goto 9
   Lbl 1
   "O # O"
   Goto 0
   Lbl 2
   "O # X"
   Goto 0
   Lbl 3
   "O O #"
   Goto 0
   Lbl 4
   "O O O"
   Goto 0
   Lbl 5
   "O O X"
   Goto 0
   Lbl 6
   "O X #"
   Goto 0
   Lbl 7
   "O X O"
   Goto 0
   Lbl 8
   "O X X"
   Goto 0
   Lbl 9
   "X # #"
   Lbl 0
              
Program "NXD3" [Draw remaining rows of square]

   \r=19=>Goto 1
   \r=20=>Goto 2
   \r=21=>Goto 3
   \r=22=>Goto 4
   \r=23=>Goto 5
   \r=24=>Goto 6
   \r=25=>Goto 7
   \r=26=>Goto 8
   Lbl 1
   "X # O"
   Goto 0
   Lbl 2
   "X # X"
   Goto 0
   Lbl 3
   "X O #"
   Goto 0
   Lbl 4
   "X O O"
   Goto 0
   Lbl 5
   "X O X"
   Goto 0
   Lbl 6
   "X X #"
   Goto 0
   Lbl 7
   "X X O"
   Goto 0
   Lbl 8
   "X X X"
   Lbl 0
              
Program "NXCHK4WIN" [Check for a line of three]

   1->\th
   F>0=>F=G=>G=H=>Goto 0
   I>0=>I=J=>J=K=>Goto 0
   L>0=>L=M=>M=N=>Goto 0
   F>0=>F=I=>I=L=>Goto 0
   G>0=>G=J=>J=M=>Goto 0
   H>0=>H=K=>K=N=>Goto 0
   F>0=>F=J=>J=N=>Goto 0
   H>0=>H=J=>J=L=>Goto 0
   0->\th
   Lbl 0
              


This page was created by Tom Lynn (tom-calcs@mythic-beasts.com).
This page last updated: Friday, 30 April, 1999

Written in notepad and compiled with WTA, for clean, consistent HTML.
Part of the Casio Graphical Calculator Encyclopaedia.

Best Viewed With Any Browser