OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [basic/] [3D-Tic-Tak-Toe.bas] - Rev 106

Compare with Previous | Blame | View Log

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

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.