Tic Tac Toe (CATS)

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Game

A tic-tac-toe game against the computer. Before the match you enter the probability of winning you want the computer to play with (0 = never, 1 = always, or anything in between) and the number of games. The board is drawn with PLOT, the squares are numbered 1 to 9, and you choose a square by number. Each game ends with “COMPUTER WINS”, “YOU WIN” or “CATS GAME” (a draw), and the running score of player and computer games is shown.

It is on CATS Library Tape 1 of the Capital Area Timex Sinclair Users Group, and on the CATS library disks for the Zebra disk drive; both copies list the same. Its only REM is “TTT”; no author is named. It is a different program from the SINCUS Tic Tac Toe.

Program Analysis

Who moves first is chosen at random with INT (2*RND) and a computed GO TO (64+T*12). On each computer turn, IF RND<W decides whether the computer plays its strategic move (the routine at 600 and the move tables from line 90) or a weaker one, which is how the probability setting works. The board state is kept in D(9) as +1/−1 values, and NL/NLL hold the last two moves for the response tables.

Appears On

From Blackjack to Star Trek, Moon Lander to a first-person dungeon crawler — this tape packs 21 games and puzzles into one of CATS' earliest library volumes. Card sharks, arcade fans, and puzzle solvers alike will find something here.

Related Content

Source Code

   10 REM TTT
   40 LET NL=0
   42 DIM D(9)
   44 PRINT AT 2,11;"TIC TAC TOE"
   45 PRINT AT 19,4;"ENTER PROBABILITY OF WINNING YOU WANT (0=NEVER,1=ALWAYS--NUMBERS IN BETWEEN ARE ACCEPTABLE)" 
   46 INPUT W
   47 LET PS=0
   48 LET CS=0
   49 CLS 
   50 PRINT AT 19,4;"GIVE NUMBER OF GAMES                "
   51 INPUT GM
   52 PRINT AT 19,4;"                        "
   53 LET G=0
   54 LET G=G+1
   56 GO SUB 900
   57 GO SUB 400
   58 LET P=1
   60 LET T=INT (2*RND)
   62 GO TO 63
   63 GO TO (64+T*12)
   64 PRINT AT 19,4;"YOU PLAY,ENTER POSITION     NUMBER     "
   66 INPUT N
   67 PRINT AT 19,4;"                                   "
   70 GO TO 500
   76 PRINT AT 19,4;"I PLAY                              "
   77 PAUSE 60
   78 LET EN=0
   79 IF RND<W THEN GO TO 600
   80 IF P<=4 THEN GO TO 86
   82 GO TO 600
   86 GO TO (80+P*10)
   90 GO TO 700
  100 IF (NL=5) THEN GO TO 700
  102 IF (NL/2-INT (NL/2))<>0 THEN GO TO 106
  103 LET N=(4-ABS (5-NL))+NL
  104 GO TO 500
  106 LET N=5
  108 GO TO 500
  110 LET N=10-NLL
  112 IF NL=5 THEN GO TO 500
  114 LET N=NLL+6-12*INT (.2*NLL)
  116 IF D(N)<>0 THEN LET N=10-N
  118 GO TO 500
  120 LET N=5
  121 IF D(5)=0 THEN GO TO 500
  122 LET EN=2
  123 GO TO 600
  124 LET EN=0
  125 IF DA<>15 THEN GO TO 700
  126 LET N=2*INT (1+4*RND)
  127 IF DT=-5 THEN GO TO 500
  128 GO TO 700
  400 FOR J=1 TO 9
  410 LET D(J)=0
  420 NEXT J
  430 RETURN 
  500 LET D(N)=2*T-1
  502 LET EN=1
  503 GO SUB 800
  504 IF P>=4 THEN GO TO 600
  506 LET P=P+1
  508 LET NLL=NL
  510 LET NL=N
  512 IF (P>=10) THEN GO TO 520
  514 LET T=ABS (T-1)
  516 GO TO 62
  520 PRINT AT 19,4;"CATS GAME"
  524 GO TO 575
  560 PRINT AT 19,4;"COMPUTER WINS                    "
  562 LET CS=CS+1
  564 GO TO 575
  570 PRINT AT 19,4;"YOU WIN                           "
  572 LET PS=PS+1
  575 PAUSE 600
  576 CLS 
  590 IF G<GM THEN GO TO 54
  592 CLS 
  594 PRINT AT 18,4;"PLAYER WON ";PS
  596 PRINT AT 19,4;"COMPUTER WON ";CS
  597 PAUSE 600
  598 CLS 
  599 GO TO 40
  600 LET Q=0
  601 LET DT=0
  602 LET DA=0
  603 FOR I=1 TO 8
  604 LET DS=0
  606 FOR J=1 TO 3
  608 GO SUB (648+2*I)
  610 LET DS=DS+D(K)
  612 IF D(K)=0 THEN LET N=K
  613 NEXT J
  614 LET DA=DA+ABS (I*D(I))
  615 LET DT=DT+I*D(I)
  616 IF DS=-3 THEN GO TO 570
  618 IF DS=3 THEN GO TO 560
  620 IF EN=1 THEN GO TO 624
  621 IF EN=2 THEN GO TO 624
  622 IF DS=2 THEN GO TO 500
  623 IF DS=-2 THEN LET Q=N
  624 NEXT I
  626 IF Q=0 THEN GO TO 630
  627 LET N=Q
  628 GO TO 500
  630 LET DA=DA+ABS (9*D(9))
  632 LET DT=DT+9*D(9)
  634 IF EN=2 THEN GO TO 124
  640 IF EN=1 THEN GO TO 505
  642 GO TO 700
  650 LET K=J
  651 RETURN 
  652 LET K=3+J
  653 RETURN 
  654 LET K=6+J
  655 RETURN 
  656 LET K=1+3*(J-1)
  657 RETURN 
  658 LET K=2+3*(J-1)
  659 RETURN 
  660 LET K=3+3*(J-1)
  661 RETURN 
  662 LET K=1+4*(J-1)
  663 RETURN 
  664 LET K=3+2*(J-1)
  665 RETURN 
  700 LET RX=INT (RND*5)
  702 FOR M=1 TO 5
  704 LET N=1+2*RX
  706 IF N=5 THEN GO TO 710
  708 IF D(N)=0 THEN GO TO 500
  710 LET RX=RX+1
  712 IF RX>=5 THEN LET RX=0
  714 NEXT M
  716 FOR N=2 TO 8 STEP 2
  718 IF D(N)=0 THEN GO TO 500
  720 NEXT N
  722 LET N=5
  724 GO TO 500
  800 LET Y=(N+2)/3
  802 LET R=3+4*INT (Y)
  804 LET C=12*(1.01+Y-INT (Y))
  806 LET A$="X"
  808 IF T=1 THEN LET A$="O"
  810 PRINT AT R,C;A$
  812 RETURN 
  900 PRINT AT 7,12;"1   2   3"
  910 PRINT AT 11,12;"4   5   6"
  920 PRINT AT 15,12;"7   8   9"
  940 FOR j=40 TO 128
  950 PLOT 146,j
  960 PLOT 114,j
  970 NEXT J
  980 FOR j=80 TO 176
  982 PLOT j,100
  984 PLOT j,68
  986 NEXT J
  988 RETURN 
 9000 SAVE "ttt" LINE 40

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.