3-D Tic-Tac-Toe

THREE-DIMENSIONAL TIC-TAC-TOE is a variation of a very familiar game, but this arrangement has a different twist. In this version the program constructs three identical playing planes, numbered 1, 2, and 3, reading from left to right. Refer to the screen dump of Figure 1. By considering all three of these planes jointly, a player can win–or score points–when three of his marks are arrayed in a straight line, in any direction.

Figure 1. Screen dump of the three playing planes
Figure 1. Screen dump of the three playing planes

As in the conventional game, players take alternating turns to plot their marks, an “X” or an “O”, in any of the three planes. He (or she) does so by first touching a number key designating the plane, and then a letter from the group of keys in the lower-left corner of the keyboard, the keys QWE ASD ZXC. These nine keys correspond to the same nine positions in each plane. The player does not need to press the ENTER key for a selection to be received and recognized by the computer. Touching the ENTER key is reserved for the signal to the computer to clear the screen and start over on a new game. So avoid ENTER unless a new game is what you have in mind.

To be fair with the players, the program is designed to determine randomly, for each new game, whether the player on the left or the one on the right starts. But the starting player is not permitted to place his initial mark in the desirable center spot of the middle plane. And neither player is permitted to place their marker over one belonging to his opponent. The penalty for any of these illegal moves is forfeiture of that turn to play.

This routine contains several error traps which prevent the players from selecting an illegal number or letter. These traps are contained in lines 425, 445, and 590.

System address 23559, rather than INKEY$, was used to indicate which key was selected by the player. This approach simplifies the construction of the program, which requires a wide range of input values.

In a program of this type, the computer must make many time-consuming decisions in the principal loop that lays between lines 60 and 600. Some speed-up would ensue if lines like 500, 510, ect., contained an additional statement: GO TO 600. Such a statement would obviate the need to test any of the conditions that follow. But, the slight additional speed was not considered to be worth the effort here.

Have fun. Feel free to embellish the program further, if you so desire.

   2 REM ** THREE-DIMENSIONAL                TIC-TAC-TOE                         for                     SPECTRUM or TS 2068                 A version  by                   Warren Fricke
3 REM ** "A-22"
5 BORDER 1: PAPER 6: CLS
10 FOR j=USR CHR$ 144 TO USR CHR$ 144+15: READ a: POKE j,a: NEXT j
30 GO SUB 1000
40 GO SUB 2000
50 RANDOMIZE : LET p=1-(1 AND RND<.5): LET t=0
60 IF p=1 THEN PRINT AT 0,0;"RIGH";AT 0,30; INK 2;"O": LET m$=CHR$ 144: LET i=2: BEEP .08,0
70 IF p=0 THEN PRINT AT 0,0;" LEF";AT 0,30; INK 1;"+": LET m$=CHR$ 145: LET i=1: BEEP .08,12
400 REM **PRINT PLAYER'S PIECES
410 PAUSE 0
420 LET a=PEEK 23559: IF a=13 THEN CLS : GO TO 40
425 IF a<49 OR a>51 THEN GO TO 410
430 PAUSE 0
440 LET b=PEEK 23559: IF b=13 THEN CLS : GO TO 40
445 IF t=0 AND a=50 AND b=115 THEN GO TO 600
450 LET c=8*(a-49)
500 IF b=97 THEN PRINT AT 7,5+c; INK i;m$ AND SCREEN$ (7,5+c)=CHR$ 32
510 IF b=99 THEN PRINT AT 14,9+c; INK i;m$ AND SCREEN$ (14,9+c)=CHR$ 32
520 IF b=100 THEN PRINT AT 11,9+c; INK i;m$ AND SCREEN$ (11,9+c)=CHR$ 32
530 IF b=101 THEN PRINT AT 8,9+c; INK i;m$ AND SCREEN$ (8,9+c)=CHR$ 32
540 IF b=113 THEN PRINT AT 4,5+c; INK i;m$ AND SCREEN$ (4,5+c)=CHR$ 32
550 IF b=115 THEN PRINT AT 9,7+c; INK i;m$ AND SCREEN$ (9,7+c)=CHR$ 32
560 IF b=119 THEN PRINT AT 6,7+c; INK i;m$ AND SCREEN$ (6,7+c)=CHR$ 32
570 IF b=120 THEN PRINT AT 12,7+c; INK i;m$ AND SCREEN$ (12,7+c)=CHR$ 32
580 IF b=122 THEN PRINT AT 10,5+c; INK i;m$ AND SCREEN$ (10,5+c)=CHR$ 32
590 IF b<97 OR b=98 OR b=114 OR b=121 OR (b<119 AND b>115) OR (b<113 AND b>101) THEN GO TO 430
600 LET p=NOT p: LET t=1: GO TO 60
1000 REM **TITLE & INSTRUCTIONS
1010 PRINT AT 2,7;"THREE-DIMENSIONAL";AT 4,9;"TIC-TAC-TOE"
1020 PRINT AT 7,3;"This version does not keep score nor determine a winner. Players must do this themselves,as the rules may vary."
1030 PRINT AT 11,3;"The computer determines ran- domly whether LEFT or RIGHT starts the game."
1040 PRINT AT 14,3;"Computer will keep tract of whose turn it is. Players alter-nate."
1045 PRINT AT 17,3;"Use the ENTER key only to start a new game."
1050 PRINT AT 20,3;"Stand by."
1100 PLOT 56,150: DRAW 136,0
1110 PLOT 72,134: DRAW 88,0
1120 PAUSE 800: CLS
1130 RETURN
2000 REM ** 3-D BOARD
2010 FOR m=36 TO 164 STEP 64
2020 FOR n=160 TO 88 STEP -24
2030 PLOT m,n: DRAW 48,-48
2070 NEXT n: NEXT m
2200 LET m=124
2210 FOR n=36 TO 212 STEP 16
2215 PLOT n,m-n: DRAW 0,72
2220 IF n=84 THEN LET m=188
2230 IF n=148 THEN LET m=252
2240 NEXT n
2250 FOR n=20 TO 212 STEP 64
2260 PLOT n,88: DRAW 16,0
2270 NEXT n
2290 PRINT AT 0,4;"T-HAND PLAYER'S TURN. USE"
2300 PRINT AT 2,3;1;AT 2,11;2;AT 2,19;3;AT 16,11;1;AT 16,19;2;AT 16,27;3
2310 PRINT AT 18,0;"Just touch two keys: 1,2, or 3 & one letter key. Use the ENTER key only to start a new game. Gowhen ready."
2350 RETURN
3000 DATA 48,76,68,66,66,34,50,12,144,80,48,16,24,20,18,17

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