mirror of
https://github.com/rfivet/BCG101.git
synced 2024-12-20 17:16:23 -05:00
226 lines
4.4 KiB
QBasic
226 lines
4.4 KiB
QBasic
120 PRINT"YOU HAVE THE OPPORTUNITY OF TRYING TO BEAT THE COMPUTER"
|
|
130 PRINT"AT TIC-TAC-TOE. ENTER YOUR MOVES AS FOLLOWS:"
|
|
140 PRINT
|
|
150 DIM C(11)
|
|
160 DIM D(11)
|
|
170 FOR K=1 TO 11
|
|
180 READ C(K), D(K)
|
|
190 NEXT K
|
|
200 PRINT "...ROW NUMBER...COMMA...COLUMN NUMBER..."
|
|
210 PRINT
|
|
220 PRINT"ROWS ARE HORIZONTAL(ACROSS)...COLUMNS ARE VERTICAL(UP + DOWN)"
|
|
230 DIM B(9)
|
|
240 DIM A(3,3)
|
|
250 PRINT
|
|
260 PRINT "NEW GAME STARTED NOW..........................."
|
|
270 FOR J=1 TO 3
|
|
280 FOR I=1 TO 3
|
|
290 LET A(I,J)=0
|
|
300 NEXT I
|
|
301 LET I=I-1
|
|
310 NEXT J
|
|
311 LET J=J-1
|
|
320 LET Z= 0
|
|
330 PRINT "YOUR MOVE",
|
|
340 INPUT R,C
|
|
350 PRINT
|
|
360 IF R>3 THEN 620
|
|
370 IF C>3 THEN 620
|
|
380 IF A(R,C) <> 0 THEN 620
|
|
390 LET A(R,C)=-1
|
|
400 GOSUB 1660
|
|
410 IF Z =1 THEN 2070
|
|
420 REM MACHINE MOVE...
|
|
430 GOSUB 1100
|
|
440 REM TEST FOR GAME WIN...
|
|
450 GOSUB 1660
|
|
460 IF Z=0 THEN 650
|
|
470 REM PRINT GAME BOARD..
|
|
480 GO TO 490
|
|
490 PRINT
|
|
500 FOR K=1 TO 3
|
|
510 LET B=A(K,1)
|
|
520 LET D=A(K,2)
|
|
530 LET F=A(K,3)
|
|
540 GOSUB 840
|
|
550 IF K>2 THEN 570
|
|
560 PRINT "***************"
|
|
570 NEXT K
|
|
571 LET K=K-1
|
|
580 PRINT
|
|
590 IF Z <>0 THEN 2070
|
|
600 GO TO 330
|
|
610 STOP
|
|
620 PRINT "---- ILLEGAL MOVE -- TRY AGAIN ----"
|
|
630 PRINT
|
|
640 GO TO 330
|
|
650LET T2=0
|
|
660 FOR J=1 TO 3
|
|
670 FOR I=1 TO 3
|
|
680 IF A(I,J)<>0 THEN 700
|
|
690 LET T2=T2+1
|
|
700 NEXT I
|
|
701 LET I=I-1
|
|
710 NEXT J
|
|
711 LET J=J-1
|
|
720 IF T2>0 THEN 750
|
|
730 GOSUB 1340
|
|
740 GO TO 480
|
|
750 IF T2>1 THEN 480
|
|
760 FOR J=1 TO 8
|
|
770 IF B(J)=-2 THEN 800
|
|
780 NEXT J
|
|
781 LET J=J-1
|
|
790 GO TO 730
|
|
800 GOSUB 2000
|
|
810 GO TO 480
|
|
820 REM PRINT TIC-TAC-TOE BOARD ROW.....
|
|
830 REM
|
|
840 IF B<>0 THEN 910
|
|
850 PRINT " * ";
|
|
860 IF D<>0 THEN 940
|
|
870 PRINT " * ";
|
|
880 IF F<>0 THEN 970
|
|
890 PRINT " "
|
|
900 GO TO 1070
|
|
910 IF B>0 THEN 1000
|
|
920 PRINT "YOU * ";
|
|
930 GO TO 860
|
|
940 IF D>0 THEN 1020
|
|
950 PRINT "YOU * ";
|
|
960 GO TO 880
|
|
970 IF F>0 THEN 1040
|
|
980 PRINT "YOU"
|
|
990 GO TO 900
|
|
1000 PRINT"PDP * ";
|
|
1010 GO TO 860
|
|
1020 PRINT "PDP * ";
|
|
1030 GO TO 880
|
|
1040 PRINT "PDP"
|
|
1050 GO TO900
|
|
1060 REM PRINT LEGENDS..
|
|
1070 PRINT " * * "
|
|
1080 RETURN
|
|
1090 REM PROGRAM TO MAKE MOVE FOR THE MACHINE....
|
|
1100 LET M=INT(3.33*RND(M))
|
|
1110 LET N=INT(3.33333*RND(N))
|
|
1120 IF M=0 THEN 1100
|
|
1130 IF M>3 THEN 1100
|
|
1140 IF N=0 THEN 1110
|
|
1150 IF N>3 THEN 1110
|
|
1160 LET C(2)=M
|
|
1170 LET D(2)=N
|
|
1180 LET C(3)=N
|
|
1190 LET D(3)=M
|
|
1200 FOR I=1 TO 8
|
|
1210 IF B(I)>1 THEN 1370
|
|
1220 NEXT I
|
|
1221 LET I=I-1
|
|
1230 FOR I=1 TO 8
|
|
1240 IF B(I)<-1 THEN 1370
|
|
1250 NEXT I
|
|
1251 LET I=I-1
|
|
1260 IF R+C=0 THEN 1550
|
|
1270 FOR K=1 TO 11
|
|
1280 LET I=C(K)
|
|
1290 LET J=D(K)
|
|
1300 IF A(I,J)<>0 THEN 1330
|
|
1310 LET A(I,J)=1
|
|
1320 GO TO 1360
|
|
1330 NEXT K
|
|
1331 LET K=K-1
|
|
1340 PRINT " ... TIE GAME ... "
|
|
1350 LET Z=3
|
|
1360 RETURN
|
|
1370 IF I>3 THEN 1440
|
|
1380 FOR J=1 TO 3
|
|
1390 IF A(I,J)=0 THEN 1420
|
|
1400 NEXT J
|
|
1401 LET J=J-1
|
|
1410 GO TO 1360
|
|
1420 LET A(I,J)=1
|
|
1430 GO TO 1360
|
|
1440 IF I>6 THEN 1510
|
|
1450 FOR J=1 TO 3
|
|
1460 IF A(J,I-3)=0 THEN 1490
|
|
1470 NEXT J
|
|
1471 LET J=J-1
|
|
1480 GO TO 1360
|
|
1490 LET A(J,I-3)=1
|
|
1500 GO TO 1360
|
|
1510 IF I>7 THEN 1550
|
|
1520 FOR J=1 TO 3
|
|
1530 IF A(J,J)=0 THEN 1590
|
|
1540 NEXT J
|
|
1541 LET J=J-1
|
|
1550 IF A(1,3)=0 THEN 1610
|
|
1560 IF A(3,1)=0 THEN 1630
|
|
1570 LET A(2,2)=1
|
|
1580 GO TO 1360
|
|
1590 LET A(J,J)=1
|
|
1600 GO TO 1360
|
|
1610 LET A(1,3)=1
|
|
1620 GO TO 1360
|
|
1630 LET A(3,1)=1
|
|
1640 GO TO 1360
|
|
1650 REM PROGRAM TO TEST FOR GAME WINNER....
|
|
1660 LET T1=0
|
|
1670 FOR J=1 TO 9
|
|
1680 LET B(J)=0
|
|
1690 NEXT J
|
|
1691 LET J=J-1
|
|
1700 FOR J=1 TO 3
|
|
1710 FOR I=1 TO 3
|
|
1720 IF A(J,1)<>A(J,I) THEN 1750
|
|
1730 NEXT I
|
|
1731 LET I=I-1
|
|
1740 LET T1=A(J,I)
|
|
1750 NEXT J
|
|
1751 LET J=J-1
|
|
1760 FOR J=1 TO 3
|
|
1770 FOR I=1 TO 3
|
|
1780 IF A(1,J)<>A(I,J) THEN 1810
|
|
1790 NEXT I
|
|
1791 LET I=I-1
|
|
1800 LET T1=A(I,J)
|
|
1810 NEXT J
|
|
1811 LET J=J-1
|
|
1820 IF A(1,1)=A(3,3) THEN 1930
|
|
1830 IF A(3,1)=A(1,3) THEN 1970
|
|
1840 IF T1<>0 THEN 1990
|
|
1850 FOR J=1 TO 3
|
|
1860 FOR I=1 TO 3
|
|
1870 LET B(J)=B(J)+A(J,I)
|
|
1880 LET B(J+3)=B(J+3)+A(I,J)
|
|
1890 NEXT I
|
|
1891 LET I=I-1
|
|
1900 NEXT J
|
|
1901 LET J=J-1
|
|
1910 LET B(7)=A(1,1)+A(2,2)+A(3,3)
|
|
1920 RETURN
|
|
1930 IF A(2,2)=A(3,3) THEN 1950
|
|
1940 GO TO 1830
|
|
1950 LET T1=A(2,2)
|
|
1960 GO TO 1840
|
|
1970 IF A(2,2)=A(1,3) THEN 1950
|
|
1980 GO TO 1840
|
|
1990 IF T1>0 THEN 2030
|
|
2000 PRINT " ...YOU WIN THIS TIME..."
|
|
2010 LET Z=1
|
|
2020 GO TO 1850
|
|
2030 PRINT " ... THE PDP-8 WINS THIS TIME ..."
|
|
2040 LET Z=2
|
|
2050 GO TO 1850
|
|
2060 REM END OF TEST WINNER PROGRAM.......
|
|
2070 PRINT "DO YOU WANT TO PLAY ANOTHER GAME: YES(1), NO(0)",
|
|
2080 INPUT X1
|
|
2090 IF X1 = 1 THEN 250
|
|
2100 IF X1 = 0 THEN 2130
|
|
2110 PRINT "I SAID ONE OR ZERO: TRY AGAIN",
|
|
2120 GO TO 2080
|
|
2130 PRINT"IT'S BEEN FUN, COME AGAIN SOMETIME"
|
|
2140 GO TO 2160
|
|
2150 DATA 2,2,0,0,0,0,1,1,3,3,1,3,3,1,1,2,3,2,2,3,2,1
|
|
2160 CHAIN "DEMON "
|
|
2170 END
|