home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpmug
/
cpmug026.ark
/
CHESS.ASC
< prev
next >
Wrap
Text File
|
1984-04-29
|
12KB
|
497 lines
100 REM--CHESS BY RANDY MILLER, JAN, 1976
110 DEFINT A-Z:DEFSNG E:DEFSNG M:DEFSNG P
120 DIM PS(70,3),MV(35,2),V(32)
130 DIM B(8,8),TM(8,8)
140 DEF FNL(X)=X\10
150 DEF FNM(X)=X MOD(10)
160 TM(1,1)=0
170 FOR X=1 TO 32
180 READ V(X)
190 NEXT
200 FOR Y=1 TO 8
210 FOR X=1 TO 8
220 READ B(X,Y)
230 NEXT X:NEXT Y
240 DATA -2,1,-1,2,1,2,2,1,2,-1,1,-2,-1,-2,-2,-1
250 DATA 8,12,19,21,-8,-12,-19,-21
260 DATA 1,9,10,11,-1,-9,-10,-11
270 DATA 4,2,3,6,5,3,2,4,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
280 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1
290 DATA -1,-1,-1,-1,-4,-2,-3,-6,-5,-3,-2,-4
300 CB=3:CW=3
310 PRINT:PRINT:PRINT:PRINT TAB(10);"**** CHESS ****"
320 INPUT "DO YOU WANT TO BE WHITE OR BLACK";C$
330 IF LEFT$(C$,1)="B" THEN 370
340 B(4,1)=5:B(4,8)=-5
350 B(5,1)=6:B(5,8)=-6
360 GOTO 380
370 PRINT "THANK YOU, THAT MEANS I GET TO GO FIRST":PRINT
380 FOR Y=1 TO 8
390 FOR X=1 TO 8
400 TM(X,Y)=B(X,Y)
410 NEXT X:NEXT Y
420 IF LEFT$(C$,1)<>"B" THEN 840
430 NB=1
440 REM -- COMPILE LIST OF POSSIBLE MOVES --
450 FOR X=1 TO 8
460 FOR Y=1 TO 8
470 IF SGN(B(X,Y))<>1 THEN 550
480 GOSUB 1870
490 FOR D=1 TO N
500 IF MV(D,1)=0 THEN 540
510 PS(NB,1)=MV(D,1)
520 PS(NB,2)=MV(D,2)
530 NB=NB+1
540 NEXT D
550 NEXT Y
560 NEXT X
570 PRINT:PRINT "NUMBER OF POSSIBLE MOVES FOR COMPUTER";NB-1:PRINT
580 IF NB>1 THEN PRINT "FROM TO BOARD VALUE":GOTO 620
590 PRINT "I DON'T BELIEVE IT! - YOU WON!!!"
600 END
610 REM -- EVALUATE EACH POSSIBLE MOVE --
620 FOR D=1 TO NB-1
630 D1=FNL(PS(D,1))
640 D2=FNM(PS(D,1))
650 D3=FNL(PS(D,2))
660 D4=FNM(PS(D,2))
670 D5=B(D3,D4)
680 TM(D3,D4)=TM(D1,D2)
690 TM(D1,D2)=0
700 GOSUB 1530
710 PS(D,3)=EV
720 TM(D1,D2)=TM(D3,D4)
730 TM(D3,D4)=D5
740 PRINT PS(D,1);PS(D,2);TAB(12);PS(D,3)
750 NEXT D
760 REM
770 MZ=PS(1,3):MX=1
780 IF NB=2 THEN 830
790 FOR D=2 TO NB-1
800 IF PS(D,3)<=MZ THEN 820
810 MX=D:MZ=PS(D,3)
820 NEXT D
830 GOSUB 1290
840 GOSUB 870
850 PRINT
860 GOTO 430
870 REM -- INPUT ROUTINE --
880 GOTO 910
890 INPUT "YOUR MOVE";M,N
900 IF M<>0 THEN 930
910 FOR P=1 TO 8:FOR P1=1 TO 8:PRINT B(P1,P);:NEXT P1:PRINT:NEXT P
920 GOTO 890
930 X1=FNL(M):Y1=FNM(M):X2=FNL(N):Y2=FNM(N)
940 IF X1>8 OR X1<1 OR Y1>8 OR Y1<1 THEN 970
950 IF X2>8 OR X2<1 OR Y2>8 OR Y2<1 THEN 970
960 IF SGN(B(X1,Y1))=-1 THEN 990
970 PRINT "YOU CAN'T DO THAT."
980 GOTO 890
990 REM
1000 FOR P=1 TO 8
1010 FOR P1=1 TO 8
1020 TM(P,P1)=B(P,P1)
1030 NEXT P1
1040 NEXT P
1050 GOSUB 3690
1060 IF LG=0 THEN 970
1070 TM(X2,Y2)=TM(X1,Y1)
1080 TM(X1,Y1)=0
1090 B(X2,Y2)=B(X1,Y1)
1100 B(X1,Y1)=0
1110 PRINT "ACCEPTED."
1120 IF Y2<>1 OR B(X2,Y2)<>-1 THEN 1180
1130 PRINT "TO PROMOTE YOUR PAWN TO A KNIGHT, TYPE 2; FOR A BISHOP,"
1140 PRINT "TYPE 3; FOR A ROOK, TYPE 4; FOR A QUEEN, TYPE 5";
1150 INPUT P
1160 IF P>5 OR P<2 THEN 1130
1170 B(X2,Y2)=-P:TM(X2,Y2)=-P
1180 IF B(X2,Y2)<>-6 OR ABS(X1-X2)<>2 THEN 1240
1190 IF X1-X2=2 THEN 1250
1200 B(8,8)=0:TM(8,8)=0
1210 B(X2-1,8)=-4:TM(X2-1,8)=-4
1220 CB=(CB AND -3)
1230 PRINT "IT'S ABOUT TIME YOU CASTLED!":PRINT
1240 RETURN
1250 B(1,8)=0:TM(1,8)=0
1260 B(X2+1,8)=-4:TM(X2+1,8)=-4
1270 CB=(CB AND -3)
1280 GOTO 1230
1290 REM -- OUTPUT ROUTINE --
1300 IF PS(MX,3)<200 THEN 1350
1310 PRINT "HA - LET'S SEE YOU GET OUT OF THIS -"
1320 PRINT "I MOVE";PS(MX,1);"TO";PS(MX,2)
1330 PRINT "THANKS FOR THE GOOD GAME..."
1340 END
1350 ON INT(RND(1)*4)+1 GOTO 1360,1370,1380,1390
1360 PRINT "I RECKON I'LL MOVE ";:GOTO 1400
1370 PRINT "I GUESS I'LL TAKE";:GOTO 1400
1380 PRINT "MY MOVE IS";:GOTO 1400
1390 PRINT "I LIKE";
1400 PRINT PS(MX,1);"TO";PS(MX,2):PRINT
1410 D1=FNL(PS(MX,1))
1420 D2=FNM(PS(MX,1))
1430 D3=FNL(PS(MX,2))
1440 D4=FNM(PS(MX,2))
1450 B(D3,D4)=B(D1,D2)
1460 B(D1,D2)=0
1470 IF D4<>8 OR B(D3,D4)<>1 THEN 1500
1480 PRINT "I PROMOTE MY PAWN TO A QUEEN!"
1490 B(D3,D4)=5
1500 RETURN
1510 REM
1520 EV=RND(1):RETURN
1530 EV=RND(1)/2:US=0
1540 EV=EV+D4/7
1550 FOR PJ=1 TO 8
1560 IF TM(PJ,8)<>1 THEN 1590
1570 TM(PJ,8)=5
1580 GOTO 1610
1590 NEXT PJ
1600 IF SGN(D5)=-1 THEN EV=EV-D5
1610 FOR X=1 TO 8
1620 FOR Y=1 TO 8
1630 CX=TM(X,Y):CS=SGN(CX)
1640 IF CS<>-1 THEN 1750
1650 EV=EV+CX
1660 GOSUB 1840
1670 IF N=0 THEN 1750
1680 US=US+N:EV=EV-.166666
1690 FOR UX=1 TO N
1700 U1=MV(UX,1):U2=MV(UX,2)
1710 IF SGN(TM(FNL(U2),FNM(U2)))<>1 THEN 1740
1720 IF SGN(TM(FNL(U1),FNM(U1)))<>-1 THEN 1740
1730 EV=EV-2*TM(FNL(U2),FNM(U2))
1740 NEXT UX
1750 NEXT Y
1760 NEXT X
1770 IF US>0 THEN 1800
1780 EV=EV+1000
1790 GOTO 1810
1800 FOR X=3 TO 6:FOR Y=3 TO 6:EV=EV+TM(X,Y)/3:NEXTY:NEXTX
1810 IF PJ>8 THEN 1830
1820 TM(PJ,8)=1
1830 RETURN
1840 REM
1850 R=0
1860 GOTO 1880
1870 R=1
1880 MV(1,1)=0
1890 S1=SGN(TM(X,Y))
1900 AA=X*10+Y
1910 N=1
1920 ON ABS(TM(X,Y)) GOSUB 2330,2770,2880,3140,3400,3440
1930 IF N=1 THEN 1950
1940 IF R=1 THEN 1970
1950 N=N-1
1960 RETURN
1970 REM -- IF RESTRICTED --
1980 N1=N-1
1990 N=N1
2000 FOR K=1 TO N1
2010 C1=FNL(MV(K,1))
2020 C2=FNM(MV(K,1))
2030 C3=FNL(MV(K,2))
2040 C4=FNM(MV(K,2))
2050 IF ABS(TM(C3,C4))=6 THEN 2070
2060 IF SGN(TM(C3,C4))<>S1 THEN 2080
2070 MV(K,1)=0:MV(K,2)=0:GOTO 2290
2080 C5=TM(C3,C4)
2090 TM(C3,C4)=TM(C1,C2)
2100 TM(C1,C2)=0
2110 REM -- FIND KING --
2120 FOR Y2=1 TO 8
2130 FOR X2=1 TO 8
2140 IF TM(X2,Y2)=6*S1 THEN 2170
2150 NEXT X2
2160 NEXT Y2
2170 REM
2180 FOR Y1=1 TO 8
2190 FOR X1=1 TO 8
2200 IF SGN(TM(X1,Y1))<>-S1 THEN 2250
2210 IF TM(X1,Y1)<>-S1 THEN 2230
2220 IF X1=X2 AND ABS(Y2-Y1)>2 THEN 2250
2230 GOSUB 3660
2240 IF LG=1 THEN 2310
2250 NEXT X1
2260 NEXT Y1
2270 TM(C1,C2)=TM(C3,C4)
2280 TM(C3,C4)=C5
2290 NEXT K
2300 RETURN
2310 MV(K,1)=0:MV(K,2)=0
2320 GOTO 2250
2330 REM -- RAW PAWN MOVE --
2340 IF S1=-1 THEN 2560
2350 IF Y+1>8 THEN 2550
2360 IF TM(X,Y+1)<>0 THEN 2450
2370 MV(N,1)=AA
2380 MV(N,2)=X*10+Y+1
2390 N=N+1
2400 IF Y>2 THEN 2450
2410 IF TM(X,Y+2)<>0 THEN 2450
2420 MV(N,1)=AA
2430 MV(N,2)=X*10+Y+2
2440 N=N+1
2450 IF X=1 THEN 2500
2460 IF SGN(TM(X-1,Y+1))<>-S1 THEN 2500
2470 MV(N,1)=AA
2480 MV(N,2)=(X-1)*10+Y+1
2490 N=N+1
2500 IF X=8 THEN 2550
2510 IF SGN(TM(X+1,Y+1))<>-S1 THEN 2550
2520 MV(N,1)=AA
2530 MV(N,2)=(X+1)*10+Y+1
2540 N=N+1
2550 RETURN
2560 IF Y-1<1 THEN 2760
2570 IF TM(X,Y-1)<>0 THEN 2660
2580 MV(N,1)=AA
2590 MV(N,2)=X*10+Y-1
2600 N=N+1
2610 IF Y<7 THEN 2660
2620 IF TM(X,Y-2)<>0 THEN 2660
2630 MV(N,1)=AA
2640 MV(N,2)=X*10+Y-2
2650 N=N+1
2660 IF X=1 THEN 2710
2670 IF SGN(TM(X-1,Y-1))<>-S1 THEN 2710
2680 MV(N,1)=AA
2690 MV(N,2)=(X-1)*10+Y-1
2700 N=N+1
2710 IF X=8 THEN 2760
2720 IF SGN(TM(X+1,Y-1))<>-S1 THEN 2760
2730 MV(N,1)=AA
2740 MV(N,2)=(X+1)*10+Y-1
2750 N=N+1
2760 RETURN
2770 REM -- RAW KNIGHT MOVE --
2780 FOR C6=1 TO 15 STEP 2
2790 KL=V(C6):KM=V(C6+1)
2800 XT=X+KL
2810 YT=Y+KM
2820 IF XT>8 OR XT<1 OR YT>8 OR YT<1 THEN 2860
2830 MV(N,1)=AA
2840 MV(N,2)=XT*10+YT
2850 N=N+1
2860 NEXT C6
2870 RETURN
2880 REM -- RAW BISHOP MOVE --
2890 EL=(8-Y)*-(8-Y<=8-X)+(8-X)*-(8-X < 8-Y)
2900 IF EL=0 THEN 2930
2910 C6=11
2920 GOSUB 3060
2930 EL=(8-Y)*-(8-Y <= X-1)+(X-1)*-(X-1 < 8-Y)
2940 IF EL=0 THEN 2970
2950 C6=-9
2960 GOSUB 3060
2970 EL=(8-X)*-(8-X <= Y-1)+(Y-1)*-(Y-1 < 8-X)
2980 IF EL=0 THEN 3010
2990 C6=9
3000 GOSUB 3060
3010 EL=(Y-1)*-(Y-1 <= X-1)+(X-1)*-(X-1 < Y-1)
3020 IF EL=0 THEN 3050
3030 C6=-11
3040 GOSUB 3060
3050 RETURN
3060 FOR E=1 TO EL
3070 F=C6*E
3080 MV(N,1)=AA
3090 MV(N,2)=AA+F
3100 N=N+1
3110 IF TM(FNL(AA+F),FNM(AA+F))<>0 THEN 3130
3120 NEXT E
3130 RETURN
3140 REM -- RAW ROOK MOVE --
3150 EL=8-Y
3160 IF EL=0 THEN 3190
3170 C6=1
3180 GOSUB 3320
3190 EL=Y-1
3200 IF EL=0 THEN 3230
3210 C6=-1
3220 GOSUB 3320
3230 EL=8-X
3240 IF EL=0 THEN 3270
3250 C6=10
3260 GOSUB 3320
3270 EL=X-1
3280 IF EL=0 THEN 3310
3290 C6=-10
3300 GOSUB 3320
3310 RETURN
3320 FOR E=1 TO EL
3330 F=C6*E
3340 MV(N,1)=AA
3350 MV(N,2)=AA+F
3360 N=N+1
3370 IF TM(FNL(AA+F),FNM(AA+F))<>0 THEN 3390
3380 NEXT E
3390 RETURN
3400 REM -- RAW QUEEN MOVE --
3410 GOSUB 2880
3420 GOSUB 3140
3430 RETURN
3440 REM -- RAW KING MOVE --
3450 IF X=8 THEN 3510
3460 C6=10:GOSUB 3620
3470 IF Y=1 THEN 3500
3480 C6=9:GOSUB 3620
3490 IF Y=8 THEN 3520
3500 C6=11:GOSUB 3620
3510 IF X=1 THEN 3570
3520 C6=-10:GOSUB 3620
3530 IF Y=8 THEN 3570
3540 C6=-9:GOSUB 3620
3550 IF Y=1 THEN 3570
3560 C6=-11:GOSUB 3620
3570 IF Y=1 THEN 3590
3580 C6=-1:GOSUB 3620
3590 IF Y=8 THEN 3610
3600 C6=1:GOSUB 3620
3610 RETURN
3620 MV(N,1)=AA
3630 MV(N,2)=AA+C6
3640 N=N+1
3650 RETURN
3660 REM
3670 RR=0
3680 GOTO 3700
3690 RR=1
3700 IF TM(X1,Y1)<>0 THEN 3720
3710 LG=0:RETURN
3720 S=SGN(TM(X1,Y1))
3730 A=X1*10+Y1
3740 B=X2*10+Y2
3750 ON ABS(TM(X1,Y1)) GOSUB 4070,4270,4340,4510,4630,4680
3760 IF LG=0 THEN RETURN
3770 IF RR=1 THEN 3790
3780 LG=1:RETURN
3790 REM -- IF RESTRICTED --
3800 IF S=SGN(TM(X2,Y2)) THEN 3710
3810 T1=X1:T2=Y1:T3=X2:T4=Y2:T=TM(X2,Y2)
3820 TM(X2,Y2)=TM(X1,Y1):TM(X1,Y1)=0
3830 SV=S
3840 REM -- FIND KING --
3850 FOR Y2=1 TO 8
3860 FOR X2=1 TO 8
3870 IF TM(X2,Y2)=6*S THEN 3910
3880 NEXT X2
3890 NEXT Y2
3900 END
3910 REM
3920 FOR Y1=1 TO 8
3930 FOR X1=1 TO 8
3940 P=TM(X1,Y1):IF SGN(P)=S OR P=0 OR ABS(P)=6 THEN 3980
3950 GOSUB 3660
3960 S=SV
3970 IF LG=1 THEN 4050
3980 NEXT X1
3990 NEXT Y1
4000 LG=1
4010 TM(T1,T2)=TM(T3,T4)
4020 TM(T3,T4)=T
4030 X1=T1:Y1=T2:X2=T3:Y2=T4
4040 RETURN
4050 LG=0
4060 GOTO 4010
4070 REM -- RAW PAWN MOVE --
4080 IF SGN(Y2-Y1)=S THEN 4110
4090 LG=0:RETURN
4100 LG=1:RETURN
4110 IF S=-1 THEN 4190
4120 IF B-A=1 OR B-A=2 THEN 4160
4130 IF TM(X2,Y2)=0 THEN 4090
4140 IF B-A=-9 OR B-A=11 THEN 4100
4150 GOTO 4090
4160 IF Y2=2 THEN 4100
4170 IF B-A=1 THEN 4100
4180 GOTO 4090
4190 IF A-B=1 OR A-B=2 THEN 4230
4200 IF TM(X2,Y2)=0 THEN 4090
4210 IF A-B=-9 OR A-B=11 THEN 4100
4220 GOTO 4090
4230 IF Y2=7 THEN 4100
4240 IF A-B=1 THEN 4100
4250 IF Y1=7 AND A-B=2 THEN 4100
4260 GOTO 4090
4270 REM -- RAW KNIGHT MOVE --
4280 FOR P=17 TO 24
4290 P1=V(P)
4300 IF A+P1<>B THEN 4320
4310 LG=1:RETURN
4320 NEXT P
4330 LG=0:RETURN
4340 REM -- RAW BISHOP MOVE --
4350 IF Y2=Y1 OR X2=X1 THEN 4420
4360 SP=-9
4370 IF X2<X1 THEN 4470
4380 IF Y1<Y2 THEN 4430
4390 SP=9
4400 P=INT(ABS(A-B)/9)
4410 IF ABS(A-B)/9=P THEN 4490
4420 LG=0:RETURN
4430 SP=11
4440 P=INT(ABS(A-B)/11)
4450 IF ABS(A-B)/11<>P THEN 4420
4460 GOTO 4490
4470 IF Y1<Y2 THEN 4400
4480 SP=-11:GOTO 4440
4490 GOSUB 4950
4500 RETURN
4510 REM -- RAW ROOK MOVES --
4520 IF Y2=Y1 THEN 4590
4530 IF X1=X2 THEN 4550
4540 LG=0:RETURN
4550 P=ABS(B-A)
4560 SP=SGN(B-A)
4570 GOSUB 4950
4580 RETURN
4590 P=ABS(INT((B-A)/10))
4600 SP=SGN(B-A)*10
4610 GOSUB 4950
4620 RETURN
4630 REM -- RAW QUEEN MOVE --
4640 GOSUB 4340
4650 IF LG=1 THEN RETURN
4660 GOSUB 4510
4670 RETURN
4680 REM -- KING MOVE --
4690 IF ABS(A-B)<>20 THEN 4890
4700 IF A-B=20 THEN 4730
4710 IF CB<>1 AND CB<>3 THEN 4880
4720 GOTO 4740
4730 IF CB=0 OR CB=1 THEN 4880
4740 PS=SGN(A-B):FORP2=28+50*((PS=-1)*-1)TOA+10-20*((PS=-1)+1)STEP10*P
4750 IF TM(FNL(P2),FNM(P2))<>0 THEN 4880
4760 NEXT P2:T1=X1:T2=Y1:T3=X2:T4=Y2
4770 FOR P2=A TO 18+70*((PS=-1)*-1) STEP 10*-PS
4780 X2=FNL(P2):Y2=FNM(P2)
4790 FOR X1=1 TO 8
4800 FOR Y1=1 TO 8
4810 IF SGN(TM(X1,Y1))<>1 THEN 4840
4820 GOSUB 3690
4830 IF LG=1 THEN 4880
4840 NEXT Y1:NEXT X1:NEXT P2
4850 LG=1
4860 X1=T1:Y1=T2:X2=T3:Y2=T4
4870 RETURN
4880 LG=0:GOTO 4860
4890 FOR P=25 TO 32
4900 P1=V(P)
4910 IF B=A+P1 THEN 4940
4920 NEXT P
4930 LG=0:RETURN
4940 LG=1:RETURN
4950 REM
4960 LG=0
4970 IF P=0 THEN STOP
4980 IF P>1 THEN 5000
4990 LG=1:RETURN
5000 FOR P1=1 TO P-1
5010 P2=A+SP*P1
5020 IF TM(FNL(P2),FNM(P2))<>0 THEN RETURN
5030 NEXT P1
5040 LG=1:RETURN
5050 END