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

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [basic/] [3D-Tic-Tak-Toe.bas] - Blame information for rev 106

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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