Tic Tac Toe (LISTing)

Developer(s): Paul Erickson
Date: 1990
Type: Program
Platform(s): TS 2068
Tags: Game

Tic-tac-toe against the computer, which plays X and always takes the first square. It looks for a winning move, then blocks, then plays its own pattern. It can be beaten.

RUN it and type a square number from 1 to 9 at the cursor, then ENTER: 1, 2, 3 across the top row, 4, 5, 6 in the middle and 7, 8, 9 along the bottom. The game ends with I win, You Win or Draw; RUN plays again. Two punctuation marks that did not print properly in the newsletter are corrected in this copy: the colon in line 15, and a semicolon in line 40 that could also be read as a comma.

Published in LISTing November 1990 (Tic Tac Toe).

Related Articles

Enter the number of the square when you see the cursor at the bottom.

Image Gallery

Source Code

  10 REM Tic tac toe
  13 GO SUB 1090
  15 LET w=0: LET z=0: LET o=0: LET y=0: LET t=0: DIM d(3): LET k=1000
  20 LET a$="X        "
  35 LET o=0: LET b$="X": PRINT AT 6,12;a$(1);AT 6,16;a$(2);AT 6,20;a$(3)
  40 PRINT AT 9,12;a$(4);AT 9,16;a$(5);AT 9,20;a$(6)
  50 PRINT AT 12,12;a$(7);AT 12,16;a$(8);AT 12,20;a$(9)
  51 FOR x=1 TO 9: IF a$(x)<>" " AND w=0 THEN NEXT x: PRINT "Draw": STOP
  55 IF w=1 THEN PRINT "I win": STOP
  57 IF z=1 THEN LET z=0: GO TO 82
  60 INPUT a
  70 IF a<1 OR a>9 THEN GO TO 60
  80 IF a$(a)<>" " THEN GO TO 60
  81 LET a$(a)="O": IF z=0 THEN LET z=1: GO TO 35
  85 IF t=1 AND a$(3)=" " THEN LET a$(3)="X": LET w=1: GO TO 30
  86 IF a$(2)="O" AND a$(5)="O" AND a$(8)="O" THEN PRINT "You Win": STOP
  87 FOR g=1 TO 20: IF g=10 THEN LET b$="O": LET k=1000
  88 LET k=k+10: GO SUB k-10
  90 FOR x=1 TO 3: IF a$(d(X))=b$ THEN LET o=o+1: NEXT x
  95 IF x>3 THEN GO TO 105
 100 LET s=d(x): NEXT x
 110 IF o=2 AND b$="X" AND a$(s)=" " THEN LET w=1: LET a$(s)="X": GO TO 30
 115 IF b$="O" AND o=2 AND a$(s)=" " THEN LET a$(s)="X": GO TO 30
 120 LET o=0: NEXT g
 130 IF a$(7)=" " THEN LET a$(7)="X": GO TO 30
 132 IF a$(9)=" " THEN LET a$(9)="X": GO TO 30
 135 IF a$(3)=" " THEN LET a$(3)="X": GO TO 30
 140 LET h=INT (RND*9)+1: IF a$(h)<>" " THEN LET a$(X)="X": GO TO 30
 150 GO TO 140
1000 LET d(1)=1: LET d(2)=2: LET d(3)=3: RETURN
1010 LET d(1)=4: LET d(2)=5: LET d(3)=6: RETURN
1020 LET d(1)=7: LET d(2)=8: LET d(3)=9: RETURN
1030 LET d(1)=1: LET d(2)=4: LET d(3)=7: RETURN
1040 LET d(1)=2: LET d(2)=5: LET d(3)=8: RETURN
1050 LET d(1)=3: LET d(2)=6: LET d(3)=9: RETURN
1060 LET d(1)=3: LET d(2)=5: LET d(3)=7: RETURN
1070 LET d(1)=1: LET d(2)=5: LET d(3)=9: RETURN
1075 LET d(1)=1: LET d(2)=5: LET d(3)=9: RETURN
1076 LET d(1)=3: LET d(2)=5: LET d(3)=7: RETURN
1080 LET k=1000: NEXT g: GO TO 125
1090 PRINT AT 2,11;"Tic tac toe"
1100 PLOT 87,111: DRAW 88,0
1110 PLOT 87,87: DRAW 88,0
1120 PLOT 116,64: DRAW 0,71
1125 PLOT 148,64: DRAW 0,71
1126 PRINT AT 16,8;"PAUL T. ERICKSON"
1130 RETURN

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