Compucolor.org – Virtual Media

Listing of file='3DTIC.BAS;01' on disk='vmedia/chip_8-sector.ccvf'

5 REM XY 5 REM 3-D TIC-TAC-TOE. (C) A.W.GROGONO. MAY 1979
10 CLEAR 100:RESTORE 1000
12 DIM SQUARES(64),LINES(75,3),AXES(64,7)
14 DIM COUNT(2),SUM(7),WEIGHT(64,2),RANK(64),F(2,2)
16 S= PEEK (33209):FOR I= 0TO S:R= RND (1):NEXT I:REM RANDOMIZE
20 PLOT 29,27,24,15,14,6,38,12,6,1,3,15,7:REM CLEAR PAGE
22 PRINT "  3 - D - T I C - T A C - T O E  "
24 FOR I= 5TO 8STEP 3:PLOT 3,15,I:PRINT SPC( 33):PRINT :NEXT I
40 PLOT 6,38,3,8,10:PRINT "INSTRUCTIONS:":PRINT
41 PRINT ,"THE OBJECT IS TO GET LINES OF FOUR,":PRINT
42 PRINT ,"AND STOP YOUR OPPONENT DOING THE SAME.":PRINT
43 PRINT ,"LINES CAN BE HORIZONTAL, VERTICAL,":PRINT
44 PRINT ,,,"DIAGONAL OR OBLIQUE.":PRINT
45 PRINT ,"TWO PEOPLE CAN PLAY EACH OTHER, OR":PRINT
46 PRINT ,"ONE PERSON CAN PLAY THE COMPUTER, OR":PRINT
47 PRINT ,"THE COMPUTER CAN PLAY ITSELF.":PRINT
48 PRINT ,"WAIT WHILE THE GAME IS PREPARED.":PLOT 14,3,19,29
50 REM READ DATA FOR LINES, AXES, COLORS
52 FOR L= 0TO 75:FOR I= 0TO 3:READ LINE(L,I):NEXT I:NEXT L
54 FOR SQ= 1TO 64:FOR A= 0TO 7:READ AXIS(SQ,A):NEXT A:NEXT SQ
56 FOR I= 0TO 3:READ CB(I),CL(I):NEXT I:REM COL BKD & NUMBERS
60 RESTORE 1300:REM RETURN POINT FOR REPEAT GAMES
62 FOR I= 1TO 64:READ WE(I,1):WE(I,2)= WE(I,1):NEXT I:REM WTS
64 READ X0,XM,XL,XR,Y0,YI,ZI:REM SHELF ORIGINS
66 FOR I= 1TO 2:PLAYER$(I)= "COMPUTER":NEXT I:REM PLAYER NAMES
68 INPUT "PRESS RETURN TO CONTINUE:";Z$
70 PLOT 6,6,14,12,3,8,5:REM SELECT NUMBER OF PLAYERS
72 PRINT "ENTER NUMBER OF PLAYERS:":PRINT
74 PRINT ,"0.  COMPUTER PLAYS ITSELF.":PRINT
75 PRINT ,"1.  YOU PLAY THE COMPUTER.":PRINT
76 PRINT ,:INPUT "2.  TWO PEOPLE PLAY EACH OTHER: ";PEOPLE
78 IF PEOPLE< 0OR PEOPLE> 2THEN PLOT 28,11:GOTO 76
80 R= 0:ON - (PEOPLE= 0)GOTO 100:ON - (PEOPLE= 2)GOTO 90
82 PLOT 6,1,12,3,8,7:PRINT "SELECT WHO GOES FIRST:":REM ORDER
84 PRINT :PRINT ,"1.  PLAYER.":PRINT ,"2.  COMPUTER."
86 PRINT ,"3.  RANDOMIZED ORDER.":PRINT
87 PRINT ,,:INPUT "";R:IF R< 1OR R> 3THEN PLOT 28,11:GOTO 87
88 R= R- 1:IF R= 2THEN R= INT (2* RND (1)):REM RANDOM ORDER
90 PLOT 6,3,12,3,8,5:PRINT "ENTER NAME:":PRINT
92 PRINT :PRINT ,"PLAYER ";:IF PEOPLE= 2THEN PRINT "# 1";
94 INPUT ": ";PLAYER$(1+ R):IF PEOPLE= 1THEN 100
96 PRINT :PRINT ,:INPUT "PLAYER # 2: ";PLAYER$(2- R)
98 B= 1:GOTO 250:REM SKIP BECAUSE NO COMPUTER PLAYER
100 REM SELECT COMPUTER CHARACTERISTICS
110 PLOT 6,6,12,3,8,3:PRINT "SELECT COMPUTER TACTICS:":PRINT
120 PRINT ,"1.  ATTACK ONLY":PRINT ,"2.  STRONGER ATTACK"
130 PRINT ,"3.  BALANCED ATTACK AND DEFENCE"
140 PRINT ,"4.  STRONGER DEFENCE":PRINT ,"5.  DEFENDS ONLY"
150 PRINT :FOR PL= 1TO 2:IF PL$(PL)< > "COMPUTER"THEN 200
160 PLOT 6,PL,9:PRINT PL$(PL);:INPUT " ";F
170 IF F< 1OR F> 5THEN PLOT 28,11:GOTO 160
180 F(PL,PL)= 1+ .5* (F= 4)+ (F= 5)
190 F(3- PL,PL)= 1+ .5* (F= 2)+ (F= 1)
200 NEXT PL
210 PLOT 6,5,12,3,8,5:PRINT "SELECT COMPUTER ABILITY:":PRINT
220 PRINT ,"1. LONG RANGE PLANNING"
225 PRINT ,"2. TAKES LINES QUICKLY":PRINT
230 PRINT ,,:INPUT "ENTER 1 OR 2: ";B
240 IF B< 1OR B> 2THEN PLOT 28,11:GOTO 230
250 BASE= 2.5* B* B:REM BASE = 2.5 OR 10. TO CALC WEIGHTS
300 PLOT 15,6,6,12,3,31,0:PRINT "3-D-TIC-TAC-TOE":REM TITLE
310 FOR I= 1TO 2:PLOT 6,I,3,1+ (I- 1)* 53,0:PRINT PL$(I):NEXT I
320 FOR I= 0TO 3:PLOT 6,CB(I),2:FOR J= 0TO YI:REM SHELVES
330 PLOT 250,X0+ J* XL,Y0+ I* ZI+ J,XM+ J* XR:NEXT J:PLOT 255
340 NEXT I:PLOT 6,27,2,246,Y0,X0- 1,Y0+ 3* ZI:REM LEFT LEG
350 PLOT 246,Y0+ YI+ 1,XM+ YI* XR+ 2,Y0+ 3* ZI+ J+ 1:REM RIGHT
360 PLOT 246,Y0,XM+ 2,Y0+ 3* ZI+ 1:REM R CENTER LEG
370 FOR I= 0TO 3:PLOT 246,Y0+ I* ZI+ YI+ 1:REM L CENTER LEG
380 PLOT X0+ XL* YI- 1,Y0+ I* ZI+ YI+ 3:NEXT I:PLOT 255
400 READ X0,XI,Y0,YI,Y1,ZI:REM NUMBER SPACING
410 FOR N= 1TO 64:GOSUB 2220:NEXT N:REM PUT #S ON SHELVES
420 REM GOSUB 2000 TO TEST THE 75 LINES
430 REM GOSUB 2100 TO TEST THE AXES THROUGH ALL 64 SQUARES
500 FOR TURN= 0TO 31:FOR PLAYER= 1TO 2:REM PLAY GAME
510 XC= 2+ (PL- 1)* 53:YC= TURN:REM CURSOR POSITIONS
520 PLOT 6,PL,3,26,0:PRINT SPC( 26):REM CLEAR INSTRUCTION AREA
530 IF TURN= 0THEN PLOT 3,XC- 2,YC:PRINT "           ":REM WIPE
540 PLOT 3,27,0:PRINT PLAYER$(PL);
550 ON 1- (PLAYER$(PL)= "COMPUTER")GOSUB 800,900:REM PLAYER
555 N= SQ:GOSUB 2230:REM dd IN SQUARE
560 FOR A= 1TO AXIS(SQ,0):L= AXIS(SQ,A):REM 4 OR 7 TEST LINES
570 S= 0:FOR I= 0TO 3:N= LINE(L,I):S= S+ SQ(N):NEXT I:REM SUM
580 D= S/ (1- 4* (S> 4)):REM D = LENGTH OF LINE SO FAR
590 IF D< > INT (D)THEN 700:REM SKIP IF A MIXED LINE ALREADY
600 PP= 1- (S> 4):REM PLAYER WITH PARTIAL LINE, = 1 OR 2
610 IF D= 0THEN PP= PL:REM NO LENGTH, PP=PL
620 WEIGHT= - INT (BASE^ (D- 1)):REM -0,1,10,100
630 IF PP= PLTHEN WE= INT (WE+ BASE^ D+ .1):REM +1,10,100,1000
640 FOR I= 0TO 3:N= LINE(L,I):REM ADJUST WEIGHT OF SQUARES N
650 IF SQUARE(N)= 0THEN WEIGHT(N,PP)= WE(N,PP)+ WE:REM INC WT
660 NEXT I
700 IF D< > 3OR PP< > PLTHEN 710:REM SKIP IF NO LINE
702 COUNT(PLAYER)= COUNT(PLAYER)+ 1:REM INCREASE SCORE
704 FOR I= 0TO 3:N= LINE(L,I):GOSUB 2230:NEXT I:REM dd ON LINE
706 FOR I= 0TO 500:NEXT I:REM PAUSE
708 FOR I= 0TO 3:N= LINE(L,I):GOSUB 2240:NEXT I:REM dd IN SQ
710 NEXT A:WEIGHT(SQ,1)= 0:WEIGHT(SQ,2)= 0:REM ZERO WT OF SQ
720 SQUARE(SQ)= PL* 4- 3:REM SQUARE(SQ) = 1 OR 5
730 N= SQ:GOSUB 2240:REM dd IN SQUARE
740 PLOT 3,XC+ 4,YC:PRINT COUNT(PLAYER):REM SCORE
750 NEXT PLAYER:NEXT TURN
760 PLOT 3,26,0:PRINT SPC( 26):PLOT 3,27,0,6,3
770 WIN= 1- (CO(1)< CO(2))+ (CO(1)= CO(2)):REM WINNER
772 IF WIN= 0THEN INPUT "ITS A TIE, PRESS RETURN";Z$:GOTO 780
774 PRINT "THE WINNER IS ";:PLOT 6,WIN:PRINT PLAYER$(WIN)
776 PLOT 3,14,9:PRINT "PRESS":PLOT 3,13,10:INPUT "RETURN";Z$
780 PLOT 3,27,0:INPUT "MENU, OR RETURN TO PLAY:";Z$
790 IF Z$= "M"THEN LOAD "MENU":RUN
792 PLOT 3,27,0,6,6:PRINT "WAIT WHILE DATA IS READ: "
794 FOR PLAYER= 1TO 2:COUNT(PL)= 0:NEXT PL:REM ZERO COUNT
796 FOR SQUARE= 1TO 64:SQUARE(SQ)= 0:NEXT SQ:REM ZERO SQUARES
798 PLOT 3,27,0,6,3:GOTO 60:REM NEW START
800 PRINT ", ENTER #":REM HUMAN TURN
810 PLOT 6,PL,3,XC,YC:PRINT SPC( 9):PLOT 3,XC,YC:INPUT " ";SQ
820 IF SQUARE> 0AND SQUARE< 65THEN 840:REM IN RANGE
830 PLOT 3,27,0:PRINT "BETWEEN 1 AND 64 !!!   ":GOTO 810
840 IF SQUARE(SQ)= 0THEN RETURN :REM OK. NOT YET TAKEN
850 PLOT 3,27,0:PRINT "ITS TAKEN !  TRY AGAIN.":GOTO 810
900 REM COMPUTER TURN
910 MAXIMUM= WEIGHT(1,1)* F(1,PL)+ WEIGHT(1,2)* F(2,PL):REM MAX
920 I= 0:FOR N= 1TO 64:IF SQUARE(N)< > 0THEN 970:REM TAKEN:SKIP
930 W= WEIGHT(N,1)* F(1,PL)+ WEIGHT(N,2)* F(2,PL):REM W=SUM WTS
940 IF W< MAXIMUMTHEN 970:REM SKIP IF WT < MAX
950 IF W> MAXIMUMTHEN MAXIMUM= W:I= 0:REM NEW MAXIMUM
960 I= I+ 1:RANK(I)= N:REM INC I AND REMEMBER SQUARE
970 NEXT N:R= 1+ INT (I* RND (1)):REM RANDOM CHOICE
980 SQUARE= RANK(R):PLOT 3,XC,YC:PRINT SQUARE:REM SELECT SQ
990 RETURN
1000 REM DATA FOR 76 POSSIBLE LINES
1002 DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
1004 DATA 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
1006 DATA 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48
1008 DATA 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64
1010 DATA 1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16
1012 DATA 17,21,25,29,18,22,26,30,19,23,27,31,20,24,28,32
1014 DATA 33,37,41,45,34,38,42,46,35,39,43,47,36,40,44,48
1016 DATA 49,53,57,61,50,54,58,62,51,55,59,63,52,56,60,64
1020 DATA 1,17,33,49,2,18,34,50,3,19,35,51,4,20,36,52
1022 DATA 5,21,37,53,6,22,38,54,7,23,39,55,8,24,40,56
1024 DATA 9,25,41,57,10,26,42,58,11,27,43,59,12,28,44,60
1026 DATA 13,29,45,61,14,30,46,62,15,31,47,63,16,32,48,64
1030 DATA 1,21,41,61,2,22,42,62,3,23,43,63,4,24,44,64
1032 DATA 13,25,37,49,14,26,38,50,15,27,39,51,16,28,40,52
1034 DATA 1,18,35,52,5,22,39,56,9,26,43,60,13,30,47,64
1036 DATA 4,19,34,49,8,23,38,53,12,27,42,57,16,31,46,61
1038 DATA 1,6,11,16,17,22,27,32,33,38,43,48,49,54,59,64
1040 DATA 4,7,10,13,20,23,26,29,36,39,42,45,52,55,58,61
1042 DATA 1,22,43,64,4,23,42,61,16,27,38,49,13,26,39,52
1100 REM DATA FOR AXES THROUGH EACH SQUARE
1101 DATA 7,0,16,32,48,56,64,72
1102 DATA 4,0,17,33,49,0,0,0
1103 DATA 4,0,18,34,50,0,0,0
1104 DATA 7,0,19,35,51,60,68,73
1105 DATA 4,1,16,36,57,0,0,0
1106 DATA 4,1,17,37,64,0,0,0
1107 DATA 4,1,18,38,68,0,0,0
1108 DATA 4,1,19,39,61,0,0,0
1109 DATA 4,2,16,40,58,0,0,0
1110 DATA 4,2,17,41,68,0,0,0
1111 DATA 4,2,18,42,64,0,0,0
1112 DATA 4,2,19,43,62,0,0,0
1113 DATA 7,3,16,44,52,59,68,75
1114 DATA 4,3,17,45,53,0,0,0
1115 DATA 4,3,18,46,54,0,0,0
1116 DATA 7,3,19,47,55,63,64,74
1117 DATA 4,4,20,32,65,0,0,0
1118 DATA 4,4,21,33,56,0,0,0
1119 DATA 4,4,22,34,60,0,0,0
1120 DATA 4,4,23,35,69,0,0,0
1121 DATA 4,5,20,36,48,0,0,0
1122 DATA 7,5,21,37,49,57,65,72
1123 DATA 7,5,22,38,50,61,69,73
1124 DATA 4,5,23,39,51,0,0,0
1125 DATA 4,6,20,40,52,0,0,0
1126 DATA 7,6,21,41,53,58,69,75
1127 DATA 7,6,22,42,54,62,65,74
1128 DATA 4,6,23,43,55,0,0,0
1129 DATA 4,7,20,44,69,0,0,0
1130 DATA 4,7,21,45,59,0,0,0
1131 DATA 4,7,22,46,63,0,0,0
1132 DATA 4,7,23,47,65,0,0,0
1133 DATA 4,8,24,32,66,0,0,0
1134 DATA 4,8,25,33,60,0,0,0
1135 DATA 4,8,26,34,56,0,0,0
1136 DATA 4,8,27,35,70,0,0,0
1137 DATA 4,9,24,36,52,0,0,0
1138 DATA 7,9,25,37,53,61,66,74
1139 DATA 7,9,26,38,54,57,70,75
1140 DATA 4,9,27,39,55,0,0,0
1141 DATA 4,10,24,40,48,0,0,0
1142 DATA 7,10,25,41,49,62,70,73
1143 DATA 7,10,26,42,50,58,66,72
1144 DATA 4,10,27,43,51,0,0,0
1145 DATA 4,11,24,44,70,0,0,0
1146 DATA 4,11,25,45,63,0,0,0
1147 DATA 4,11,26,46,59,0,0,0
1148 DATA 4,11,27,47,66,0,0,0
1149 DATA 7,12,28,32,52,60,67,74
1150 DATA 4,12,29,33,53,0,0,0
1151 DATA 4,12,30,34,54,0,0,0
1152 DATA 7,12,31,35,55,56,71,75
1153 DATA 4,13,28,36,61,0,0,0
1154 DATA 4,13,29,37,67,0,0,0
1155 DATA 4,13,30,38,71,0,0,0
1156 DATA 4,13,31,39,57,0,0,0
1157 DATA 4,14,28,40,62,0,0,0
1158 DATA 4,14,29,41,71,0,0,0
1159 DATA 4,14,30,42,67,0,0,0
1160 DATA 4,14,31,43,58,0,0,0
1161 DATA 7,15,28,44,48,63,71,73
1162 DATA 4,15,29,45,49,0,0,0
1163 DATA 4,15,30,46,50,0,0,0
1164 DATA 7,15,31,47,51,59,67,72
1200 DATA 2,11,5,38,4,47,1,20:REM COLORS FOR SHELVES
1300 DATA .5,0,0,.5,0,0,0,0,0,0,0,0,.5,0,0,.5:REM WEIGHTS
1310 DATA 0,0,0,0,0,.5,.5,0,0,.5,.5,0,0,0,0,0
1320 DATA 0,0,0,0,0,.5,.5,0,0,.5,.5,0,0,0,0,0
1330 DATA .5,0,0,.5,0,0,0,0,0,0,0,0,.5,0,0,.5
1400 DATA 24,97,1,.25,0,27,32,21,6,1,2,5,8:REM SPACING DATA
2000 REM TEST SQUARES IN EACH LINE
2010 FOR L= 0TO 75:FOR I= 0TO 3:REM TEST EACH LINE
2020 N= LINE(L,I):GOSUB 2210:NEXT I:INPUT "";Z$:REM dd IN SQR
2030 FOR I= 0TO 3:N= LINE(L,I):GOSUB 2220:NEXT I:NEXT L:RETURN
2100 REM TEST LINES IN DIFFERENT AXES THROUGH EACH SQUARE
2110 FOR SQ= 1TO 64:FOR A= 1TO AXIS(SQ,0):L= AXIS(SQ,A)
2120 FOR I= 0TO 3:N= LINE(L,I):GOSUB 2210:NEXT I:NEXT A:REM dd
2130 INPUT "";Z$:FOR A= 1TO AXIS(SQ,0):L= AXIS(SQ,A)
2150 FOR I= 0TO 3:N= LINE(L,I):GOSUB 2220:NEXT I:NEXT A:REM #
2160 NEXT SQ:RETURN
2200 O= N- 1:Z= INT (O/ 16):REM X Y Z  FROM NUMBER
2202 Y= INT ((O- 16* Z)/ 4):X= O- 16* Z- 4* Y+ 1
2204 PLOT 3,X0- Y* Y1+ X* (XI+ Y),Y0+ Z* ZI+ Y* YI:RETURN
2210 GOSUB 2200:PLOT 6,CL(Z),32:PRINT "dd":RETURN :REM dd IN SQ
2220 GOSUB 2200:PLOT 6,CL(Z),- 32* (N< 10):REM PRINT # IN SQR
2222 PRINT N:RETURN
2230 GOSUB 2200:PLOT 25:PRINT "dd":RETURN :REM dd IN SQUARE
2240 GOSUB 2200:PLOT 25,6,PL:PRINT "dd":RETURN :REM dd IN SQ