return to Geek-fun,-Software

3-Dimensional Tic Tac Toe game
in BASIC

from Warren Ring
wring (at) wowway (dot) com
September 20, 2009

Sept 20, 2009 -Van Snyder's MAT expansion and apparently running code below.

Ed,

I have a demo program for you that I believe will knock the socks off anyone who thinks old computers couldn’t do serious computation. It’s a 3-dimensional Tic Tac Toe game. Parker Brothers sold it under the name “Qubic” many years ago. You can buy a game board for about $12 on eBay. See the attached photos. (Long ago, I put Dymo labeling tape on each square.)

If you’re interested, I can send you the source code (in BASIC). One of your programmers could convert it to Autocoder, and guests could play against the 1401. They could enter their moves via the 1401’s sense switches, and the 1401 could respond by printing its move on the printer. The program is very fast, and almost unbeatable. Virtually everyone who plays will come away saying “I got beat at 3D tic tac toe by a 40-year-old computer.”

Where I got the program:

Back around 1969, my brother, David Ring, was a computer lab assistant at the University of Illinois in Urbana. They had a room-sized computer called the Illiac II. The university had an engineering open house, and my brother invited me to town, and that night took me to a room full of teletypes, logged me on, and showed me how I could play 3-dimensional tic tac toe.

I played a few games, and got beat every time. When he walked away, being the nerd that I was, I turned on the paper tape punch, typed “LIST”, and out came the source code in BASIC, which I took home. Years later, I converted it to Turbo C under Windows 98, and studied how it worked. It appears to have been originally written in assembler on a computer called the “TX0”.

So if you would like, I can send you the source code for the program, along with notes I’ve made for converting it from BASIC to Autocoder. I scanned the three pages of BASIC source code listing into PDF files. Let me know what you guys think. And thanks again for your on-line journal. I’ve read the entire history. (I used to program SPS-2 on a 1401.)

Warren Ring
wring@wowway.com

===================================================

Ed,

Attached are the files containing the source code for 3D tic-tac-toe, 4 in a row (which the 1401 could play as a demo game) in BASIC. It’s only 3 pages of source code.

Each about 300 K bytes

ttt3d-1-.jpg lines 100 through 490
ttt3d-2-.jpg lines 500 through 1090
ttt3d-3-.jpg lines 1100 through 1370, and start of user interaction

and 2 pages of TTY user interaction

ttt3d-4-.jpg user interaction
ttt3d-5-.jpg user interaction

Ed Thelen has made an unverified text file of the code and data here

While it’s unsuitable to scan with OCR, if you zoom in, you can clearly see the original characters, and observe a number of things:

I believe I found the author. I was once poking around at a computer history site, and came across a reference to an early computer called the TX-0 having a 3-dimensional tic tac toe game. You can search Wikipedia, entering “TX-0” (the last character is a zero) as the subject, scroll down to the External Links, click on “TX-0 Documentation”, click on “Daly Thesis Feb61 Cubic”, and “mastersthesis.pdf”, you’ll find that there was a William George Daly Jr. who analyzed the game in 1953 as his masters thesis project at MIT! Other peer links show some source code in TX-0 assembler. (Google shows that someone by the same name in Duluth, GA was later named in six patent filings involving electronic circuits.)

If so, someone along the way translated the program from TX-0 assembler to BASIC.

I started translating the program from BASIC to Autocoder a while back, but ran into some issues:

You could rig the program so that when the player decides on a move, he enters it via the sense switches (B through G). B and C would be the level, D and E would be the row, and F and G would be the column. So, for example, B and C down would be level 1, only C up would be level 2, only B up would be level 3, and both up would be level 4. If the user makes a mistake and wants to back up, he turns on the A switch (with the 1402 hopper empty) and the program backs out the previous move.

On each move, the printer could print a list of all moves ( a maximum of 32) by the player and the 1401 each, then execute an “F1”, kicking the printer up to the top of the next page (printing one page per move), and execute a Halt to allow the player to enter his next move.

I experimented with having the 1401 print a bunch of Xs and Os to represent the board on each move, but it looked like it couldn’t be done with a program that fit into 4000 characters of RAM. I could be wrong.

You would need to buy a Qubic board on eBay and label the squares. I suggest you remove the references to “strategy” from the game text.

Anyway, you can forward this to the others and see what they think. I wish I lived in your area. I’d be a regular there.

By the way, we used to play 3D tic tac toe on paper at the back of the classroom at DeVry like you did [in the Army]. Great minds think alike J. Don’t hesitate to send me correspondence.

Warren

======================================

Sept 20, 2009 -Van Snyder's MAT expansion and apparently running code.



On Sun, 2009-09-20 at 18:04 -0700, Ed Thelen wrote:
>  I have added Warren Ring's 3D-TicTacToe info to the web site
>      easy to find near the top of 
>            http://www.ed-thelen.org/1401Project/new.html
>  
> I have played with the TTY images,
>     they seem suitable at about 300 K bytes each  ;-))
>  
> Ed Thelen

I transcribed the listing and tried to run it using Vintage Basic on
Linux http://www.vintage-basic.net/download.html.

There were several things it didn't like.

Lines beginning without a line number.

MAT READ

MAT PRINT

After responding to vintbas's complaints, it appears to work.

Let me know if there are typos in it.

It's attached.

Van

 

100 REM THIS PROGRAM PLAYS 3D TIC-TAC-TOE
110 DIM S(76),R(304),W(20),T(3,14),M(64),L(4)
120 FOR I=89 TO 304: READ R(I): NEXT I
125 FOR I=1 TO 20: READ W(I): NEXT I
130 FOR I=1 TO 14: FOR J=1 TO 3: READ T(J,I): NEXT J: NEXT I
140 FOR I=1 TO 88: READ R(I): NEXT I
150 PRINT "THIS IS THE GAME OF THREE-DIMENSIONAL TIC-TAC-TOE.  MY";
155 PRINT "BOARD CONSISTS OF 4 LEVELS, 4 ROWS AND 4 COLUMNS."
160 INPUT "WOULD YOU LIKE INSTRUCTIONS";A$
170 IF A$="YES" THEN 200
180 IF A$="NO" THEN 240
190 PRINT "PLEASE ANSWER YES OR NO": GO TO 160
200 PRINT:PRINT "THE OBJECT OF THE GAME IS TO GET 4 SQUARES IN EITHER";
203 PRINT " A VERTICAL,        HORIZONTAL OR DIAGONAL LINE.  TO SELECT A ";
206 PRINT "SQUARE, GIVE ITS LOCATION."
210 PRINT "EXAMPLE-- 243 WOULD BE FOR THE SECOND LEVEL, 4TH ROW, 3RD ";
215 PRINT "COLUMN.  TO HAVE ME MOVE FIRST, TYPE 000 FOR YOUR FIRST MOVE."
220 PRINT "TO RESTART A GAME IN THE MIDDLE OF ANOTHER, TYPE A NEGATIVE";
225 PRINT " NUMBER IN   FOR YOUR MOVE.  TO GET OFF THE COMPUTER, TYPE 999."
230 REM K1 INDICATES THE WAIT LIST, INITIALIZE K1 = 1
240 K1=1
250 PRINT:INPUT "WHAT IS YOUR NAME";N$
260 REM CLEAR THE BOARD
270 FOR I=1 TO 64: M(I)=0: NEXT I
280 PRINT :PRINT "TYPE IN YOUR MOVE "N$;
290 INPUT N
300 PRINT "YOUR MOVE IS "N
310 IF N<0 THEN 500
320 IF N=0 THEN 420
330 IF N=999 THEN 510
340 REM CONVERT MOVE TO CODE (1-64) AND CHECK RANGE
350 K1=INT(N/100): K3=INT(N-100*K1): K2=INT(K3/10): K3=INT(K3-10*K2)
360 IF K1<=0 OR K1>4 OR K2<=0 OR K2>4 OR K3<=0 OR K3>4 THEN 550
370 N=16*(K1-1)+4*(K2-1)+K3: IF M(N) <= 0 THEN 390
380 PRINT "HEY, THAT SQUARE IS ALREADY TAKEN, JERK!": GO TO 280
390 M(N)=1
400 REM CALL SUB. FOR SITUATION ANALYSIS, M1=BEST MOVE, M2=ALTERNATE
410 REM M3 IS THE SITUATION LEVEL
420 GOSUB 700
430 IF M3>2 THEN 570
440 K3=4*(M1-1): FOR I=1 TO 4: K2=I+K3
450 A=R(K2): B=L(I): GOSUB 670: R(K2)=A: L(I)=B: NEXT I
460 IF M3>1 THEN 490
470 PRINT "YOU JUST WON ON ";: FOR I=1 TO 4: PRINT L(I): NEXT I
480 PRINT "YOU MUST HAVE CHEATED":GO TO 510
490 PRINT "YOU HAD TO TRY, DIDN'T YOU?  I JUST WON ON ";:
495 FOR I=1 TO 4: PRINT L(I): NEXT I: GO TO 510
500 PRINT "RESTARTING NEW GAME": GO TO 240
510 PRINT:INPUT"WOULD ANYONE ELSE TO PLAY";A$
520 IF A$="YES" THEN 240
530 IF A$="NO" THEN 1370
540 PRINT "PLEASE ANSWER YES OR NO": GO TO 510
550 PRINT "STOP TRYING TO CHEAT, PUT IN A LEGITIMATE MOVE!": GO TO 280
560 REM TEST FOR NO SITUATION LEVEL, IF SO USE A WAITING MOVE
570 IF M1>0 THEN 630
580 FOR I=K1 TO 20: M1=W(I)
590 IF M(M1)<=0 THEN 630
600 NEXT I
610 PRINT "TIE GAME, RESTARTING, ": GO TO 250
620 REM WE HAVE A SITUATION LEVEL, SO COMPUTER'S MOVE EQUALS 5
630 M(M1)=5: A=M1: B=M1: GOSUB 670: M1=B
640 A=M2: B=M2: GOSUB 670: M2=B
650 PRINT "MY MOVE IS ";M1;" ON STRATEGY ";M2;M3: GO TO 280
660 REM THIS SUBROUTINE CHANGES MOVE CODE TO THE EXTERNAL PLAYER CODE
670 IF A<=0 THEN B=A: RETURN
675 REM ENCODE (1-64) TO (111-444) A -> B
680 L1=INT((A-1)/16): L2=A-16*L1: L3=INT((L2-1)/4)
690 B=100*(L1+1)+10*(L3+1)+L2-4*L3: RETURN
700 FOR J1=1 TO 76: S(J1)=0: K2=4*J1: L2=K2-3
705 REM SUM BOARD
710 FOR J2=L2 TO K2: J3=R(J2): S(J1)=S(J1)+M(J3): NEXT J2: NEXT J1
720 REM THIS SUBROUTINE FINDS A BLANK SQUARE M1 ON A ROW OF SUM=TEST1,
730 REM SUCH THAT ANOTHER ROW OF SUM=TEST2 CONTAINS M1 AND ALSO
740 REM CONTAINS A SECOND BLANK SQUARE M2 WHICH IS ON A THIRD ROW OF
750 REM SUM=TEST3. NEGATIVE TESTS ARE SKIPPED. IF SITUATION IS 1 OR
760 REM 2, ANSWER IS A ROW SUBSCRIPT, ELSE ANSWER IS M1, M1 AND M2
770 REM MAY BE IDENTICAL. FIRST CALCULATE THE SUM VALUE FOR EACH ROW
780 FOR J1=1 TO 14: M3=J1: T1=T(1,J1)
790 IF T1<0 THEN 1120
800 T2=T(2,J1): T3=T(3,J1): FOR J2=1 TO 76
810 IF S(J2)<> T1 THEN 1110
820 IF J1<=2 THEN 1140
830 K3=4*J2: L3=K3-3
840 FOR J3=L3 TO K3
850 M1=R(J3)
860 IF M(M1)<>0 THEN 1100
870 IF T2<0 THEN 1150
880 FOR J4=1 TO 76
890 IF S(J4)<>T2 THEN 1090
900 IF J4=J2 THEN 1090
910 K5=4*J4: L5=K5-3
920 FOR J5=L5 TO K5
930 IF M1<>R(J5) THEN 1080
940 IF T3<0 THEN 1150
950 FOR J6=L5 TO K5
960 M2=R(J6)
970 IF M(M2)<>0 THEN 1070
980 FOR J7=1 TO 76
990 IF S(J7)<>T3 THEN 1060
1000 IF J7=J2 THEN 1060
1010 IF J7=J4 THEN 1060
1020 K8=4*J7: L8=K8-3
1030 FOR J8=L8 TO K8
1040 IF M2=R(J8) THEN 1160
1050 NEXT J8
1060 NEXT J7
1070 NEXT J6
1080 NEXT J5
1090 NEXT J4
1100 NEXT J3
1110 NEXT J2
1120 NEXT J1
1130 M1=0: GO TO 1150
1140 M1=J2
1150 M2=0
1160 RETURN
1170 DATA 38,39,40,37,42,43,44,41,38,42,46,34
1180 DATA 39,43,47,35,38,43,48,33,39,42,45,36,61,1,21,41,64,4,24,44
1190 DATA 49,4,19,34,61,16,31,46,49,13,25,37,52,16,28,40,52,1,18,35
1200 DATA 64,13,30,47,49,1,17,33,52,4,20,36,61,13,29,45,64,16,32
1210 DATA 48,4,1,2,3,16,13,14,15,13,1,5,9,16,4,8,12,16,1,6,11,13,4,7
1220 DATA 10,52,49,50,51
1230 DATA 64,61,62,63,61,49,53,57,64,52,56,60,64,49,54,59
1240 DATA 61,52,55,58,18,34,50,2,19,35,51,3,21,37,53,5,24,40,56,8
1250 DATA 25,41,57,9,28,44,60,12,30,46,62,14,31,47,63,15,6,7,8,5,10
1260 DATA 11,12,9,6,10,14,2,7,11,15,3,18,19,20,17,30,31,32,29,21,25
1270 DATA 29,17,24,28,32,20,34,35,36,33,46,47,48,45,37,41,45,33
1280 DATA 40,44,48,36,54,55,56,53,58,59,60,57,54,58,62,50,55,59,63,51
1290 DATA 22,43,23,42,26,39,27,38,1,64,13,52,4,61,16,49,22,43,23,42
1300 DATA 4,-1,-1,15,-1,-1,3,-1,-1,10,10,-1,10,5,10,2,2,-1,2,1,2,2,1,1
1310 DATA 2,0,2,5,5,10,5,5,5,5,0,10,5,0,5,-1,-1,-1
1320 DATA 22,43,64,1,23,42,61,4,26,39,52,13,27,38,49,16,22,42,62,2,23,43
1330 DATA 63,3,23,38,53,8,27,42,57,12,26,38,50,14,27,39,51,15,22,39,56
1340 DATA 5,26,43,60,9,22,38,54,6,23,39,55,7,26,42,58,10,27,43,59,11,22
1350 DATA 23,24,21,26,27,28,25,22,26,30,18,23,27,31,19,22,27,32,17
1360 DATA 23,26,29,20
1370 END