` 0 GOSUB 10000`

1 INPUT "DO YOU WANT INSTRUCTIONS (Y OR N)?",A$: IF A$#"Y" AND A$#"N" THEN 1: IF A$="Y" THEN GOSUB 30000

2 REF=5: CALL -936

3 INPUT "COMPUTER TO PLAY WHITE(0) OR BLACK(1)",WHO

4 IST=0

5 DIM WC(99),BC(99)

6 DIM V(6),P(26),C(3)

7 DIM KING(16)

8 DIM A(70)

10 DIM M(120),W(120),B(120),I(6)

11 DIM G(100)

12 FOR X=1 TO 120:M(X)=0: NEXT X

14 FOR X=1 TO 99:W(X)=0:B(X)=0: NEXT X

15 FOR X=2 TO 9:X1=10*X:X2=X1+1:M(X1)=7:M(X2)=7: NEXT X

16 DIM STR$(10),FILE$(8),RANK$(8)

17 FILE$(1)="A":FILE$(2)="B":FILE$(3)="C":FILE$(4)="D":FILE$(5)="E":FILE$(6)="F":FILE$(7)="G":FILE$(8)="H"

18 RANK$="12345678"

20 FOR K=1 TO 21:K2=K+99:M(K)=7:M(K2)=7: NEXT K

22 FOR K=32 TO 39:K2=K+50:M(K)=1:M(K2)=-1: NEXT K

23 M(22)=4:M(23)=2:M(24)=3:M(25)=5:M(26)=6:M(27)=3:M(28)=2:M(29)=4

25 FOR K=22 TO 29:K2=K+70:M(K2)=-M(K): NEXT K

30 I(1)=12:I(2)=15:I(3)=10:I(4)=1:I(5)=6:I(6)=6

35 V(1)=1:V(2)=3:V(3)=3:V(4)=5:V(5)=9:V(6)=10

40 P(1)=-1:P(2)=1:P(3)=10:P(4)=-10:P(5)=0:P(6)=1:P(7)=-1

45 P(8)=10:P(9)=-10:P(10)=-9:P(11)=-11:P(12)=9:P(13)=11:P(14)=0

50 P(15)=8:P(16)=-8:P(17)=12:P(18)=-12:P(19)=19:P(20)=-19

55 P(21)=21:P(22)=-21:P(23)=0:P(24)=10:P(25)=20:P(26)=0

60 C(1)=8:C(2)=0:C(3)=3

80 IF WHO=1 THEN 90

85 M(25)=6:M(26)=5:M(95)=-6:M(96)=-5

90 GOSUB 5000

93 FOR II=1 TO 120:W(II)=0:B(II)=0: NEXT II

95 IF WHO=1 THEN 100:T2=0: GOTO 1000

100 REM MAKE MOVE

101 GOSUB 4000

105 Z9=0

110 GOSUB 4200

115 GOSUB 5000: IF WHO=0 THEN 1000

116 M9=M9+1: IF M9>REF THEN 120

117 IF T2>4 THEN 120: IF IST=1 THEN GOTO 120

118 F2=9-F2:T2=9-T2: GOSUB 4200: GOSUB 5000: GOTO 100

120 REM FILL CONTROL ARRAYS

122 N8=0:IST=1

125 FOR X1=22 TO 99:WC(X1)=0:BC(X1)=0: IF M(X1)=6 THEN BKING=X1: IF M(X1)=-6 THEN WKING=X1: NEXT X1

130 FOR X=22 TO 99: IF M(X)<1 THEN 170: IF M(X)=7 THEN 170: GOSUB 8000: IF N9=0 THEN 170

150 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100: IF M(TO)>0 THEN 168

164 N8=N8+1:A(N8)=G(X1)

168 BC(TO)=BC(TO)+1

169 NEXT X1

170 NEXT X

172 FOR X=22 TO 99: IF M(X)>-1 THEN 180: GOSUB 8000

173 IF N9=0 THEN 180

174 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100:WC(TO)=WC(TO)+1

176 NEXT X1

180 NEXT X

181 GOTO 3000: REM CASTLE LOGIC

182 REM FILL KING CONTROL ARRAY

184 KING(1)=BKING+1:KING(2)=BKING-1:KING(3)=BKING+10:KING(4)=BKING-10

185 KING(5)=BKING+11:KING(6)=BKING-11:KING(7)=BKING+9:KING(8)=BKING-9

186 KING(9)=WKING+1:KING(10)=WKING-1:KING(11)=WKING+10:KING(12)=WKING-10

187 KING(13)=WKING+11:KING(14)=WKING-11:KING(15)=WKING+9:KING(16)=WKING-9

190 V9=-10000:I9=0: FOR X4=1 TO N8:N4=0:F4=A(X4)/100

210 T4=A(X4)-F4*100:F5=M(F4):T5=M(T4)

212 REM FIND MOVES OFPIECE IN PRESENT POSTION.

214 X=F4: GOSUB 8000

225 M(T4)=M(F4):M(F4)=0

235 GOSUB 9000: IF N4<=V9 THEN 255

245 V9=N4:F9=F4:T9=T4

255 M(F4)=F5:M(T4)=T5:

256 Z9=Z9+1: IF Z9>20 THEN Z9=1: TAB 26: VTAB Z9: PRINT F4;" : ";T4;" V= ";N4

259 NEXT X4

270 F1=F9:T1=T9:M(T1)=M(F1):M(F1)=0:F6=F1-F1/10*10-1:F7=10-F1/10:T6=T1-T1/10*10-1:T7=10-T1/10

280 IF WHO=1 AND F1=22 THEN QROOK=1

281 IF WHO=1 AND F1=29 THEN KROOK=1

282 IF M(T1)=6 THEN MKING=1

283 IF WHO=0 AND F1=22 THEN QROOK=1

284 IF WHO=0 AND F1=29 THEN KROOK=1

310 PRINT "FROM ";F6;F7;" TO ";T6;T7

311 GOSUB 5000

312 PRINT

320 GOTO 100

1000 IF T2>4 THEN 120

1005 M9=M9+1: IF M9>5 THEN 120

1010 IF M9#1 THEN 1020

1015 F1=5:F2=7:T1=5:T2=5: GOTO 1500

1020 IF M9#2 THEN 1030

1025 F1=2:F2=8:T1=3:T2=6: GOTO 1500

1030 IF M9#3 THEN 1040

1035 F1=4:F2=7:T1=4:T2=6: GOTO 1500

1040 IF M9#4 THEN 1050

1045 F1=3:F2=8:T1=4:T2=7: GOTO 1500

1050 IF M9#5 THEN 1060

1055 REM CASTLE KING SIDE

1056 F1=4:F2=8:T1=2:T2=8: GOSUB 4200

1057 F1=1:T1=3: GOSUB 4200: GOSUB 5000: GOTO 100

1060 GOTO 100

1500 GOSUB 4200: GOSUB 5000: GOTO 100

3000 REM CASTLE

3002 IF MKING=1 OR M9>22 THEN GOTO 3400

3003 IQ=10

3005 FOR II=22 TO 99:ITYPE=M(II): IF ITYPE=6 THEN IK=II: IF ITYPE=5 THEN IQ=II: NEXT II

3010 IF WC(IK)>0 THEN 3400

3015 IF WC(IQ)>0 THEN 3400

3018 IF WHO=0 THEN 3200: REM WHITE LOGIC

3020 REM CHECK FOR KING SIDE CASTLE

3025 IF KROOK=1 THEN 3100

3027 IF M(27)#0 OR M(28)#0 THEN 3100

3030 IF WC(27)>0 OR WC(28)>0 THEN 3400

3035 M(28)=6:M(27)=4:M(29)=0:M(26)=0

3036 MKING=1

3040 GOSUB 5000: PRINT " OO": GOTO 100

3090 REM CHECK FOR QUEEN SIDE CASTLE

3100 IF WC(25)>0 OR WC(24)>0 THEN 3400

3105 IF QROOK=1 THEN 3400

3107 IF M(23)#0 OR M(24)#0 OR M(25)#0 THEN 3400

3108 MKING=1

3110 M(24)=6:M(25)=4:M(26)=0:M(22)=0: GOSUB 5000: PRINT " OOO": GOTO 100

3200 IF QROOK=1 THEN 3300

3205 IF WC(24)>0 OR WC(23)>0 THEN 3400

3208 IF M(24)#0 OR M(23)#0 THEN 3300

3209 MKING=1

3210 M(23)=6:M(24)=4:M(22)=0:M(25)=0: GOSUB 5000: PRINT " OO": GOTO 100

3300 IF KROOK=1 THEN 3400

3305 IF WC(26)>0 OR WC(27)>0 THEN 3400

3308 IF M(26)#0 OR M(27)#0 THEN 3400

3309 MKING=9

3310 M(27)=6:M(26)=4:M(25)=0:M(29)=0: GOSUB 5000: PRINT " OOO": GOTO 100

3400 IF KROOK=1 AND QROOK=1 THEN MKING=1: GOTO 182

3599 REM SOUND BUZZER

3600 FOR XXX=1 TO 30

3605 XX= PEEK (-16336)+ PEEK (-16336)+ PEEK (-16336)+ PEEK (-16336)

3610 NEXT XXX: RETURN

3800 INPUT F1,F2,T1,T2

3805 IF F1=0 OR F2=0 THEN GOTO 4050

3810 GOSUB 4200: GOSUB 5000: GOTO 3800

4000 REM INPUT MOVE IN ALGEBRAIC NOTATION

4005 PRINT "YOUR MOVE": PRINT "XX-XX"

4006 INPUT STR$

4010 IF LEN(STR$)=0 THEN 4006

4011 IF LEN(STR$)<3 THEN 4012: IF STR$(1,3)="OOO" THEN 4150

4012 IF LEN(STR$)<2 THEN 4005: IF STR$(1,2)="OO" THEN 4100

4013 F1=0:F2=0:T1=0:T2=0

4014 IF LEN(STR$)<5 THEN 4005

4015 FOR II=1 TO 8

4020 IF STR$(1,1)=FILE$(II,II) THEN F1=II

4025 IF STR$(2,2)=RANK$(II,II) THEN F2=II

4030 IF STR$(4,4)=FILE$(II,II) THEN T1=II

4035 IF STR$(5,5)=RANK$(II,II) THEN T2=II

4036 NEXT II

4040 IF F1=0 OR F2=0 OR T1=0 OR T2=0 THEN 3800

4050 RETURN

4100 IF WHO=0 THEN 4120

4105 M(96)=0:M(99)=0:M(98)=-6:M(97)=-4

4108 RETURN

4120 M(92)=0:M(95)=0:M(94)=-4:M(93)=-6

4125 RETURN

4150 IF WHO=0 THEN 4170

4155 M(96)=0:M(92)=0:M(95)=-4:M(94)=-6

4157 RETURN

4170 M(95)=0:M(99)=0:M(96)=-4:M(97)=-6

4172 RETURN

4200 F9=1+F1+(10-F2)*10

4210 T9=1+T1+(10-T2)*10

4220 M(T9)=M(F9)

4230 M(F9)=0

4240 RETURN

5000 REM PRINT BOARD

5002 CALL -936

5005 FOR IB=2 TO 9

5010 PRINT : PRINT : PRINT 10-IB;

5015 FOR JB=10*IB+2 TO 10*IB+9

5018 IF M(JB)#O THEN 5022

5019 IF IB/2*2=IB THEN 5021

5020 IF JB/2*2=JB THEN PRINT " X ";: IF JB/2*2#JB THEN PRINT " . ";: GOTO 5034

5021 IF JB/2*2#JB THEN PRINT " X ";: IF JB/2*2=JB THEN PRINT " . ";: GOTO 5034

5022 IF WHO=0 THEN 5024

5023 IF M(JB)<0 THEN PRINT " W";: IF M(JB)>0 THEN PRINT " B";: GOTO 5025

5024 IF M(JB)<0 THEN PRINT " B";: IF M(JB)>0 THEN PRINT " W";

5025 TYPE= ABS (M(JB))

5026 IF TYPE=1 THEN PRINT "P";

5027 IF TYPE=2 THEN PRINT "N";

5028 IF TYPE=3 THEN PRINT "B";

5029 IF TYPE=4 THEN PRINT "R";

5030 IF TYPE=5 THEN PRINT "Q";

5031 IF TYPE=6 THEN PRINT "K";

5034 NEXT JB,IB

5035 PRINT : PRINT

5036 PRINT " A B C D E F G H"

5037 PRINT : PRINT

5040 RETURN

6988 REM UPDATE ARRAYS W AND B FOR

6990 REM TRIAL MOVES.

6999 REM UPDATE ARRAYS W+B FOR TRIAL

7000 FOR INDEX=-1 TO 1 STEP 2

7100 I8=I(5):K8=P(I8)

7110 IF INDEX=-1 THEN TEMP=F4: IF INDEX=1 THEN TEMP=T4

7200 B8=TEMP

7201 B8=B8+K8: IF B8<22 THEN 7350: IF M(B8)=7 THEN 7350

7220 IF M(B8)=0 THEN 7201

7222 IT= ABS (M(B8)): IF IT=5 THEN 7224: IF I8<10 AND IT=4 THEN 7224

7223 IF I8>9 AND IT=3 THEN 7224: GOTO 7350

7224 ITYPE=M(B8)/IT:OPOS=-K8:B7=TEMP

7226 B7=B7+OPOS: IF M(B7)=7 THEN 7350

7228 IF ITYPE=1 THEN 7230:W(B7)=W(B7)-INDEX: IF M(B7)=0 THEN 7226: GOTO 7350

7230 B(B7)=B(B7)-INDEX: IF M(B7)=0 THEN 7226

7350 I8=I8+1:K8=P(I8): IF P(I8)#0 THEN 7200

7400 NEXT INDEX

7500 RETURN

8000 IF M(X)=0 THEN RETURN : IF M(X)=7 THEN RETURN :N9=0:T1= ABS (M(X)):I8=I(T1):K8=P(I8)

8030 IF T1#1 THEN 8200:I6=M(X)/T1:I1=X+I6*11

8050 IF M(I1)>-1 OR M(I1)<1 THEN 8060

8054 GOTO 8090

8060 IF M(I1)<1 OR M(I1)=7 OR M(X)>-1 THEN 8100

8090 N9=N9+1:G(N9)=X*100+X+I6*11

8100 I1=X+I6*9

8105 IF M(I1)>-2 OR M(X)<1 THEN 8150

8112 GOTO 8130

8120 IF M(I1)<1 OR M(I1)=7 THEN 8150

8130 N9=N9+1:G(N9)=X*100+I1

8150 I1=X+I6*10: IF M(I1)#0 THEN 8180:N9=N9+1:G(N9)=X*100+I1:I1=X+I6*20

8170 IF M(I1)#0 OR X/10#C(I6+2) THEN 8180

8174 N9=N9+1:G(N9)=X*100+I1

8180 RETURN

8200 B8=X

8201 B8=B8+K8: IF M(B8)=7 THEN 8350

8220 IF B8>99 OR B8<22 OR M(B8)=7 THEN 8350

8235 N9=N9+1:G(N9)=100*X+B8

8242 IF M(B8)#0 OR T1=2 OR T1=6 OR T1=1 THEN 8350

8250 GOTO 8201

8350 I8=I8+1:K8=P(I8): IF P(I8)#0 THEN 8200

8500 RETURN

8999 REM EVALUATION SECTION

9000 FOR X1=22 TO 99:W(X1)=WC(X1):B(X1)=BC(X1): NEXT X1

9015 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100:B(TO)=B(TO)-1: NEXT X1

9020 X=T4: GOSUB 8000

9025 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100:B(TO)=B(TO)+1: NEXT X1

9030 GOSUB 7000

9100 FOR X1=22 TO 99:MM=M(X1): IF MM=7 THEN 9160

9102 IF M(X1)=3 OR M(X1)=5 THEN B(X1)=B(X1)-1

9105 C6=B(X1)-W(X1):N4=N4+C6

9108 IF MM=0 THEN 9160

9110 IF M(X1)<2 THEN 9120

9112 IF M(X1+11)=-1 THEN N4=N4-5*V(M(X1)): IF M(X1+9)=-1 THEN N4=N4-5*V(M(X1))

9120 IF C6>0 AND M(X1)<0 THEN N4=N4+4*V(-M(X1))

9125 IF C6<0 AND M(X1)>0 THEN N4=N4-8*V(M(X1))

9130 IF W(X1)<1 THEN 9160

9140 IF M(X1)=6 THEN N4=N4-5000: IF M(X1)=5 THEN N4=N4-50

9160 NEXT X1

9172 IF F5=1 THEN 9175: IF T5#0 THEN 9175

9174 IF M(T4+9)=-1 OR M(T4+11)=-1 THEN N4=N4-20

9175 N4=N4+8*V( ABS (T5))

9180 IF F5=5 THEN N4=N4-3

9182 IF F5=6 THEN N4=N4-10

9188 N4=N4+10

9200 REM EXTRA POINTS FOR CONTROLING SQUARES AROUND THE KINGS.

9205 FOR II=1 TO 16:INDEX=KING(II)

9210 N4=N4+B(INDEX)-W(INDEX): NEXT II

9220 REM POINTS FOR BOARD CENTER.

9225 N4=N4+B(55)+B(56)+B(65)+B(66)-W(55)-W(56)-W(65)-W(66)

9230 REM DEVELOPMENT!

9235 IF M(23)=2 THEN N4=N4-4

9240 IF M(24)=3 THEN N4=N4-2

9245 IF M(27)=3 THEN N4=N4-2

9250 IF M(28)=2 THEN N4=N4-4

9300 RETURN

9999 END

10000 CALL -936

10002 GOSUB 11111

10004 PRINT

10006 PRINT " <<<<< COMPUTER CHESS >>>>>"

10008 PRINT

10010 GOSUB 11111

10015 PRINT

10020 RETURN

11111 FOR J=1 TO 38: PRINT "*";: NEXT J: PRINT "*": RETURN

12000 REM SIMPLE-5 HEURISTIC CHESS BY MARK WATSON 714 271-8979

30000 CALL -936: GOSUB 11111: PRINT : PRINT "THIS IS SIMPLE-5 HEURISTIC CHESS BY"

30002 PRINT "MARK WATSON. THE RULES ARE SIMPLE."

30004 PRINT " 1) MOVES ARE ENTERED AS FILE THEN": PRINT " RANK OF THE STARTING POSITION,"

30006 PRINT " THEN FILE AND RANK OF THE ENDING": PRINT " POSITION. PUT A SPACE BETWEEN"

30008 PRINT " THE STARTING AND THE ENDING PO-": PRINT " SITIONS. FOR INSTANCE, 'B1 C3'"

30009 PRINT " MOVES THE KNIGHT IN FRONT OF THE": PRINT " BISHOP'S PAWN."

30010 PRINT " 2) TO CASTLE ON THE KING'S SIDE ALL": PRINT " YOU NEED DO IS TYPE 'OO' (NOT"

30020 PRINT " '00'); AND ON THE QUEEN'S SIDE,": PRINT " 'OOO'.": PRINT " 3) THE COMPUTER DOES NOT CHECK FOR"

30022 PRINT " ILLEGAL MOVES AND THEY MAY CAUSE": PRINT " CAUSE STRANGE THINGS TO HAPPEN."

30023 PRINT

30024 PRINT "PRESS ANY KEY TO CONTINUE.": PRINT : GOSUB 11111

30026 IF PEEK (-16384)<128 THEN 30026: POKE -16368,0: RETURN

32767 POP : END