Found this on an old floppy - throwing it away!

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
Bill Rogers
Posts: 3562
Joined: Thu Mar 09, 2006 2:54 am
Location: San Jose, California

Re: Found this on an old floppy - throwing it away!

Post by Bill Rogers » Sun Aug 12, 2007 1:46 am

Hey Michael and others. I found a little bug in the program by just studing the code.
On line 52 the GOTO should read 9,80,9,65,59,9,54,9,49:
The last number is for the kings moves.
Bill

Michael Sherwin
Posts: 2819
Joined: Fri May 26, 2006 1:00 am
Location: OH, USA

Re: Found this on an old floppy - throwing it away!

Post by Michael Sherwin » Sun Aug 12, 2007 2:40 am

Bill Rogers wrote:Hey Michael and others. I found a little bug in the program by just studing the code.
On line 52 the GOTO should read 9,80,9,65,59,9,54,9,49:
The last number is for the kings moves.
Bill
Good catch Bill! It does not make much sense to have two '59's in the same on goto. I think that you will have this up and running soon! :D
Regards,
Mike

Michael Sherwin
Posts: 2819
Joined: Fri May 26, 2006 1:00 am
Location: OH, USA

Re: Found this on an old floppy - throwing it away!

Post by Michael Sherwin » Sun Aug 12, 2007 3:14 am

Hi Bill,

I took a closer look and there is not a bug on line 52. The final goto 50 handles the king move. The 59 is for bishop and queens. At the end of the bishop code it test to see if it was really a queen and if so, it jumps to the rook code to finish the queen moves.

This was just a clever plot to get me to study the code, wasn't it? :P

Best,
Mike
Regards,
Mike

YL84

Re: Found this on an old floppy - throwing it away!

Post by YL84 » Sun Aug 12, 2007 7:09 am

Thanks for the tips and advices. I think it is possible to make it
running, all the commands are still valids (hope peek and poke
are for displays, sound is not necessary, and print may be
replaced by a console.writeline). Maybe also changing the gosub
to sub. Well I'm just curious
how fast this little thing could be...

vb4
Posts: 147
Joined: Sat Mar 11, 2006 4:45 am
Location: NY

My attempt of parsing

Post by vb4 » Sun Aug 12, 2007 7:33 am

This should get you guys going: I have one line that contains asterisks at the bottom because I am not sure how to parse it.

1 '*******************
2 '* CHESSMASTER *
3 '* BY: *
4 '* HAROLD SNYDER *
5 '* P.O. BOX 3330 *
6 '* CHEYENNE, WY *
7 '* 82003 *
8 '*******************
9 CLS(3)
10 PRINT@128," * CHESSMASTER *"
11 PRINT@192," BY"
12 PRINT@256," HAROLD SNYDER"
13 FOR QZ = 1 TO 2999 : NEXT
14 A = 0 : B = 0 : X = 0 : Y = 0 : S = 0 : A0 = 0 : T=0 : A8 = 0 : A2 = 0 : A3 = 0 : A4 = 0 : B1 = 0 : B6 = 0 : H = 0 : M = 0 : N = 0 : P = 0 : A5 = 0 : I = 1 : DIM A(9,9),C(64) : POKE 248,&H32 : POKE 249,&H62 : POKE 250,&H1C : POKE 251,&HAF : POKE 252,&H7E : POKE 253,&HAD : POKE 254,&HA5 : POKE 410,&H7E : POKE 411,0 : POKE 412,&HF8
15 CLS : PRINT : PRINT" * CAN THIS COMPUTER USE THE HIGH SPEED POKE Y/N"
16 IN$ = INKEY$ : IF IN$ = "" THEN 16
17 IF IN$ <> "Y" AND IN$ <> "N" THEN 16
18 IF IN$ = "Y" THEN POKE 65495,0
19 CLS : PRINT : PRINT"DO YOU WANT INSTRUCTIONS Y/N"
20 IN$ = INKEY$ : IF IN$ <> "Y" AND IN$ <> "N" THEN 20
21 IF IN$ = "Y" THEN GOSUB 194
22 PRINT : PRINT"WHAT LEVEL OF PLAY 1-7"
23 IN$ = INKEY$ : IFIN$ = "" THEN 23
24 B8 = VAL(IN$)-1 : IF B8<0 OR B8>6 THEN 23
25 B7 = B8*2
26 IF B7 = 0 THEN B7 = 1
27 PRINT : PRINT"DO YOU WANT WHITE Y/N"
28 IN$ = INKEY$ : IF IN$ = "" THEN 28
29 IF IN$ <> "Y" AND IN$ <> "N" THEN 28
30 GOSUB 111
31 IF IN$ <> "N" THEN GOSUB 122 : GOTO 41
32 GOSUB 120
33 'COMPUTER MOVE
34 F = -99 : A0 = 0 : FOR J = 1 TO 8 : FOR K = 1 TO 8 : IF A(J,K) = 99 THEN A6 = J:A7 = K : GOTO 35 ELSE NEXT : NEXT
35 FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) < 0 THEN GOSUB 52 : IF F >= B7 THEN 37
36 NEXT : NEXT : IF F >= -9 THEN 37 ELSE 190
37 A(R,U) = A(E,Q) : A(E,Q) = 1 : IF A(R,U) = -2 AND U = 1 THEN A(R,U) = -9
38 X = R : Y = U : A0 = 4 : GOSUB 52 : SOUND 190 , 1 : SOUND 110 , 1 : SOUND 160 , 1 : SOUND 140 , 1 : PRINT@89 , "MY MOVE" ; : PRINT@121 , " WAS " ; : PRINT@155 , CHR$(E+64) ; CHR$(Q+48) ; CHR$(R+64) ; CHR$(U + 48);
39 GOSUB 124 : X = E : Y = Q : GOSUB 124 : IFC = 1 THEN PRINT@185 , " check " ; : C = 0 ELSE PRINT@185 , " "; :
40 'PLAYER MOVE
41 GOSUB 152 : D = 0 : B4 = A : B9 = B : B5 = 0
42 IF X$ = "K" OR X$ = "Q" THEN 34
43 A0 = 3 : GOSUB 48 : IF D = 0 THEN PRINT@25 , "illegal" ; : PRINT@57 , " move " ; : FOR J = 1 TO 1500 : NEXT : GOTO 41
44 PRINT@89 , " " ; : PRINT@121 , " " ; : PRINT@155 , " " ; : PRINT@217 , " " ; : PRINT@249 , " " ; : PRINT@315 , " " ; : A = B4 : B = B9 : A(A,B) = A(X,Y) : A(X,Y) = 1 : GOSUB 124 : X = A : Y = B : GOSUB 124
45 IF A(A,B) = 2 AND B = 8 THEN GOSUB 180 : GOSUB 124
46 IF B5 = 1 THEN A(A , B - 1) = 1 : X = A : Y = B - 1 : GOSUB 124 : GOTO 34 ELSE 34
47 'COMPUTER PIECE MOVE
48 PRINT@31 , CHR$(191) ; : ON A(X , Y) GOTO 9 , 74 , 9 , 65 , 59 , 9 , 54 , 9 , 59
49 'KING MOVE
50 FOR A = X - 1 TO X + 1 : FOR B = Y - 1 TO Y + 1 : IF A(A,B) <> 0 THEN GOSUB 94 : NEXT : NEXT : RETURN ELSE NEXT : NEXT : RETURN
51 'PLAYER PIECE MOVE
52 ON - A(X,Y) GOTO 9 , 80 , 9 , 65 , 59 , 9 , 54 , 9 , 59 : GOTO 50
53 'ROOK/QUEEN MOVE
54 B = Y : FOR A = X + 1 TO 8 : GOSUB 93 : IF S = 0 THEN NEXT
55 FOR A = X - 1 TO 1 STEP - 1 : GOSUB 93 : IF S = 0 THEN NEXT
56 A = X : FOR B = Y + 1 TO 8 : GOSUB 93 : IF S = 0 THEN NEXT
57 FOR B = Y - 1 TO 1 STEP - 1 : GOSUB 93 : IF S = 0 THEN NEXT : RETURN ELSE RETURN
58 'BISHOP/QUEEN MOVE
59 B = Y : FOR A = X + 1 TO 8 : B = B + 1 : GOSUB 93 : IF S = 0 THEN NEXT
60 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B - 1 : GOSUB 93 : IF S = 0 THEN NEXT
61 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B + 1 : GOSUB 93 : IF S = 0 THEN NEXT
62 B = Y : FOR A = X + 1 TO 8 : B = B - 1 : GOSUB 93 : IF S = 0 THEN NEXT
63 IF ABS(A(X,Y)) = 9 THEN 54 ELSE RETURN
64 'KNIGHT MOVE
65 A = X + 2 : B = Y + 1 : IF A < 9 AND B < 9 THEN GOSUB 94
66 B = B - 2 : IF B > 0 AND A < 9 THEN GOSUB 94
67 A = A - 4 : IF A > 0 AND B > 0 THEN GOSUB 94
68 B = B + 2 : IF B < 9 AND A > 0 THEN GOSUB 94
69 A = A + 1 : B = B + 1 : IF A > 0 AND A < 9 AND B < 9 THEN GOSUB 94
70 B = B - 4 : IF B > 0 AND A > 0 AND A < 9 THEN GOSUB 94
71 A = A + 2 : IF A > 0 AND A < 9 AND B > 0 THEN GOSUB 94
72 B = B + 4 : IF B < 9 AND A > 0 AND A < 9 THEN GOSUB 94 : RETURN ELSE RETURN
73 'PLAYER PAWN MOVE
74 A = X : IF Y > 2 THEN 76
75 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 95 : B = B + 1 : IF A(A,B) = 1 THEN GOSUB 95 : GOTO 77 ELSE 77 ELSE 77
76 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 95
77 A = X + 1 : B = Y + 1 : IF A(A,B) < 0 THEN GOSUB 95
78 A = A - 2 : IF A(A,B) < 0 THEN GOSUB 95 : RETURN ELSE RETURN
79 'COMPUTER PAWN MOVE
80 A = X : IF Y < 7 THEN 82
81 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 95 : B = B - 1 : IF A(A,B) = 1 THEN GOSUB 95 : GOTO 83 ELSE 83 ELSE 83
82 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 95
83 A = X - 1 : B = Y - 1 : IF A(A,B) > 1 THEN GOSUB 95
84 A = A + 2 : IF A(A,B) > 1 THEN GOSUB 95 : RETURN ELSE RETURN
85 'PROTECT ROUTINE
86 T = A(A,B) : IF T = -99 THEN B1 = T : RETURN
87 A5 = S : IF ABS(T) <= A(X,Y) THEN A(A,B) = A(X,Y) : A(X,Y) = 1 : GOTO 89
88 IF T < B1 THEN B1 = T : S = A5 : RETURN ELSE S = A5 : RETURN
89 A1 = X : A2 = Y : A3 = A : A4 = B : A8 = T : A0 = 2 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) <0 THEN GOSUB 52 : IF T = 0 THEN 91
90 NEXT : NEXT
91 X = A1 : Y = A2 : A = A3 : B = A4 : A0 = 5 : A(X,Y) = A(A,B) : A(A,B) = A8 : GOTO 88
92 'LEGAL MOVE CHECK
93 S = 0 : IF A(A,B) = 1 THEN 95 ELSEIF A(A,B) = 0 THEN S = 1 : RETURN ELSEIF SGN(A(A,B)) = SGN(A(X,Y)) THEN S = 1 : RETURN ELSE S = 1 : GOTO 95
94 IF A(A,B) <> 1 THEN IF SGN(A(A,B)) = SGN(A(X,Y))THEN RETURN
95 PRINT@31 , " " ; : ON A0 GOTO 96 , 97 , 98 , 99 , 100 : GOTO 102
96 IF A6 = A AND A7 = B THEN B1 = B1 + 1 : RETURN ELSE RETURN
97 IF A3 = A AND A4 = B THEN T = 0 : RETURN ELSE RETURN
98 IF B4 = A AND B9 = B THEN D = 1 : RETURN ELSE RETURN
99 IF A6 = A AND A7 = B THEN C = 1 : RETURN ELSE RETURN
100 IF A(A,B) < 0 THEN 86 ELSE RETURN
101 'LOOK-AHEAD ROUTINE
102 B3 = S : W = X : M = Y : N = A : H = B : P = A(A,B) : A(A,B) = A(X,Y) : A(X,Y) = 1 : B1 = 0
103 A0 = 5 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) > 1 THEN GOSUB 48
104 NEXT : NEXT : X = N : Y = H : A0 = 1 : GOSUB 52 : A0 = 0 : S = B3 : X = W : Y = M : A = N : B = H : A(X,Y) = A(A,B) : A(A,B) = P
105 'EVALUATE MOVE
106 B6 = 1/(ABS(4.5 - A) + ABS(4.5 - B) + 1) : IF A(X,Y) < -2 AND A(X,Y) > -9 THEN B6 = B6 + 1/(ABS(A6 - A) + ABS(A7 - B) + 5) + RND(0)/15
107 G = P + B1 + B6 : IF P = 99 THEN GOSUB 178 : PRINT@89 , " " ; : PRINT@121 , " mate! " ; : PRINT@153 , B$ ; : PRINT@185 , " " ; : GOTO 192
108 IF G <= F THEN RETURN
109 F = G : E = X : Q = Y : R = A : U = B : RETURN
110 'INITIALIZATION ROUTINE
111 CLS : FOR Y = 8 TO 1 STEP - 1 : FOR X = 1 TO 8 : READ A(X,Y) : NEXT : NEXT
112 FOR J = 1 TO 4 : SB$ = SB$ + STRING$(3 , CHR$(140)) + STRING$(3 , CHR$(131)) : SW$ = SW$ + STRING$(3 , CHR$(131)) + STRING$(3 , CHR$(140)) : NEXT
113 FOR J = 32 TO 416 STEP 128 : PRINT@J ,SB$ ; : PRINT@J + 64 , SW$ ; : NEXT : FOR J = 1 TO 7 STEP 2 : PRINT@477 + J * 3 , CHR$(128) ; CHR$(J + 96) ; CHR$(128) ; CHR$(140) ; CHR$(J + 65) ; CHR$(140) ; : NEXT : FOR J = 1 TO 8 : PRINT@J * 64 - 8 , CHR$(128) ; : PRINT@J*64 - 40 , CHR$(57-J) ; : NEXT : PRINT@504 , CHR$(128) ; : RETURN
114 DATA -7 , -4 , -5 , -9 , -99 , -5 , -4 , -7
115 DATA -2 , -2 , -2 , -2 , -2 , -2 , -2 ,-2
116 DATA 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
117 DATA 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2
118 DATA 7 , 4 , 5 , 9 , 99 , 5 , 4 , 7
119 'PLAYER REQUESTS BLACK
120 I = -I : A(4,1) = 99 : A(5,1) = 9 : A(4,8) = -99 : A(5,8) = -9
121 'GRAPHIC DRIVER-FULL SCREEN
122 FOR Y= 1 TO 8 : FOR X = 1 TO 8 : GOSUB 124 : NEXT : NEXT : RETURN
123 'GRAPHIC DRIVER-ONE PIECE
124 L = 509 + X*3 - Y*64 : IF X + Y - INT((X + Y)/2)*2 = 0 THEN 126
125 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 127 , 128 , 9 , 129 , 130 , 9 , 131 , 9 , 132 : PRINT@L , " K " ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 127 , 133 , 9 , 134 , 135 , 9 , 136 , 9 , 137 : PRINT@L , " k " ; : RETURN
126 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 138 , 139 , 9 , 140 , 141 , 9 , 142 , 9 , 143 : PRINT@L , CHR$(128) ; "K" ; CHR$(128) ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 138 , 144 , 9 , 145 , 146 , 9 , 147 , 9 , 148 : PRINT@L , CHR$(128) ; "k" ; CHR$(128) ; : RETURN
127 PRINT@L , " " ; : RETURN
128 PRINT@L , " P " ; : RETURN
129 PRINT@L , " N " ; : RETURN
130 PRINT@L , " B " ; : RETURN
131 PRINT@L , " R " ; : RETURN
132 PRINT@L , " Q " ; : RETURN
133 PRINT@L , " p " ; : RETURN
134 PRINT@L , " n " ; : RETURN
135 PRINT@L , " b " ; : RETURN
136 PRINT@L , " r " ; : RETURN
137 PRINT@L , " q " ; : RETURN
138 PRINT@L , STRING$(3 , CHR$(128)) ; : RETURN
139 PRINT@L , CHR$(128) ; "P" ; CHR$(128) ; : RETURN
140 PRINT@L , CHR$(128) ; "N" ; CHR$(128) ; : RETURN
141 PRINT@L , CHR$(128) ; "B" ; CHR$(128) ; : RETURN
142 PRINT@L , CHR$(128) ; "R" ; CHR$(128) ; : RETURN
143 PRINT@L , CHR$(128) ; "Q" ; CHR$(128) ; : RETURN
144 PRINT@L , CHR$(128) ; "p" ; CHR$(128) ; : RETURN
145 PRINT@L , CHR$(128) ; "n" ; CHR$(128) ; : RETURN
146 PRINT@L , CHR$(128) ; "b" ; CHR$(128) ; : RETURN
147 PRINT@L , CHR$(128) ; "r" ; CHR$(128) ; : RETURN
148 PRINT@L , CHR$(128) ; "q" ; CHR$(128) ; : RETURN
149 'INPUT ROUTINE
150 PRINT@25 , "cannot " ; : PRINT@57 , "castle " ; : FOR J = 1 TO 1500 : NEXT : GOTO 152
151 PRINT@25 , " entry " ; : PRINT@57 , " error " ; : FOR J = 1 TO 1500 : NEXT
152 GOSUB 175 : GOSUB 178 : PRINT@217 , " your " ; : PRINT@249 , " move ";
153 X$ = INKEY$ : IF X$ = "" THEN 153
154 PRINT@315 , X$;
155 SOUND 120,1
156 X1$ = INKEY$ : IF X1$ = "" THEN 156
157 PRINT@316 , X1$;
158 SOUND 120,1
159 X2$ = INKEY$ : IF X2$ = "" THEN 159
160 PRINT@317 , X2$;
161 SOUND 120,1
162 X3$ = INKEY$ : IF X3$ = "" THEN 162
163 PRINT@318 , X3$ ; : IN$ = X$ + X1$ + X2$ + X3$
164 SOUND 150,1
165 IF X$ >= "A" AND X$ <= "H" THEN 173
166 IF X$ = "K" THEN IF A(5,1) = 99 AND A(8,1) = 7 AND A(6,1) < 2 AND A(7,1) < 2 THEN A(5,1) = 1 : A(6,1) = 7 : A(7,1) = 99 : A(8,1) = 1 : GOTO 176
167 IF X$ = "Q" THEN IF A(5,1) = 99 AND A(1,1) = 7 AND A(4,1) < 2 AND A(3,1) < 2 THEN A(5,1) = 1 : A(4,1) = 7 : A(3,1) = 99 : A(1,1) = 1 : GOTO 176
168 IF X$ = "K" THEN IF A(4,1) = 99 AND A(1,1) = 7 AND A(3,1) < 2 AND A(2,1) < 2 THEN A(4,1) = 1 : A(3,1) = 7 : A(2,1) = 99 : A(1,1) = 1 : GOTO 176
169 IF X$ = "Q" THEN IF A(4,1) = 99 AND A(8,1) = 7 AND A(5,1) < 2 AND A(6,1) < 2 THEN A(4,1) = 1 : A(5,1) = 7 : A(6,1) = 99 : A(8,1) = 1 : GOTO 176
170 'DECODE INPUT
171 IF X$ = "I" THEN GOSUB 194 : GOSUB 113 : GOSUB 122 : GOTO 152
172 IF X$ = "P" THEN RUN ELSE 151
173 IF LEN(IN$) = 4 THEN X = ASC(X$) - 64 : Y = ASC(MID$(IN$ , 2 , 1)) - 48 : A = ASC(MID$(IN$ , 3 , 1)) - 64 : B = ASC(MID$(IN$ , 4 , 1)) - 48 ELSE 151
174 IF Y < 1 OR Y > 8 OR A < 1 OR A > 8 OR B < 1 OR B > 8 THEN 151 ELSE IF A(X,Y) < 2 OR A(A , B) > 1 THEN 151 ELSE GOSUB 175 : RETURN
175 PRINT@25 , " " ; : PRINT@57 , " " ; : RETURN
176 PRINT@313 , "CASTLE " ; : PRINT@345 , X$ ; "-SIDE " ; : GOSUB 175 : GOSUB 122 : RETURN
177 'BLANK MESSAGE AREA
178 FOR J = 217 TO 345 STEP 32 : PRINT@J , " " ; : NEXT : RETURN
179 'PROMOTE PLAYER PAWN
180 GOSUB 178 : PRINT@217 , " what " ; : PRINT@249 , " piece " ; : PRINT@281 , " PNBRQ " ; :
181 IN$ = INKEY$ : IF IN$ = "" THEN 181
182 IF IN$ <> "P" AND IN$ <> "N" AND IN$ <> "B" AND IN$ <> "R" AND IN$ <> "Q" THEN PRINT@315 , " " ; : GOTO 181
183 PRINT@316 , IN$ ;
184 IF IN$ = "P" THEN A(A,B) = 2 : RETURN
185 IF IN$ = "N" THEN A(A,B) = 4 : RETURN
186 IF IN$ = "B" THEN A(A,B) = 5 : RETURN
187 IF IN$ = "R" THEN A(A,B) = 7 : RETURN
188 IF IN$ = "Q" THEN A(A,B) = 9 : RETURN ELSE 181
189 'END OF GAME
190 GOSUB 178 : PRINT@89 , " " ; : PRINT@121 , " YOU " ; : PRINT@153 , " WIN! " ;
***********191 POKE65494,0
192 GOTO 192
193 'INSTRUCTIONS
194 CLS
195 PRINT" * INSTUCTIONS *"
196 PRINT"ENTER KKKK TO CASTLE KING SIDE"
197 PRINT" QQQQ TO CASTLE QUEEN SIDE"
198 PRINT" IIII TO GET INSTUCTIONS"
199 PRINT" PPPP TO START NEW GAME"
200 PRINT
201 PRINT" TO PROMOTE TO P, N, B, R OR Q"
202 PRINT" ENTER LETTER WHEN PROMPTED"
203 PRINT : PRINT" TO MOVE, CAPTURE OR CAPTURE"
204 PRINT" EN PASSANT, SPECIFY FROM/TO"
205 PRINT" (E.G. 'B1C3')"
206 PRINT : PRINT" LEVELS OF PLAY ARE 1 THRU 7"
207 PRINT
208 PRINT" (HIT ANY KEY)";
209 IN$ = INKEY$ : IF IN$ = "" THEN 209
210 CLS : RETURN


I hope this helps you guys, let me know how you make out.

Les

vb4
Posts: 147
Joined: Sat Mar 11, 2006 4:45 am
Location: NY

My 2nd attempt to parsing

Post by vb4 » Sun Aug 12, 2007 3:16 pm

HTH,

1 '*******************
2 '* CHESSMASTER *
3 '* BY: *
4 '* HAROLD SNYDER *
5 '* P.O. BOX 3330 *
6 '* CHEYENNE, WY *
7 '* 82003 *
8 '*******************
9 CLS(3)
10 PRINT@128 , " * CHESSMASTER *"
11 PRINT@192 , " BY"
12 PRINT@256 , " HAROLD SNYDER"
13 FOR QZ = 1 TO 2999 : NEXT
14 A = 0 : B = 0 : X = 0 : Y = 0 : S = 0 : A0 = 0 : T=0 : A8 = 0 : A2 = 0 : A3 = 0 : A4 = 0 : B1 = 0 : B6 = 0 : H = 0 : M = 0 : N = 0 : P = 0 : A5 = 0 : I = 1 : DIM A(9,9),C(64) : POKE 248,&H32 : POKE 249,&H62 : POKE 250,&H1C : POKE 251,&HAF : POKE 252,&H7E : POKE 253,&HAD : POKE 254,&HA5 : POKE 410,&H7E : POKE 411,0 : POKE 412,&HF8
15 CLS : PRINT : PRINT" * CAN THIS COMPUTER USE THE HIGH SPEED POKE Y/N"
16 IN$ = INKEY$ : IF IN$ = "" THEN 16
17 IF IN$ <> "Y" AND IN$ <> "N" THEN 16
18 IF IN$ = "Y" THEN POKE 65495,0
19 CLS : PRINT : PRINT"DO YOU WANT INSTRUCTIONS Y/N"
20 IN$ = INKEY$ : IF IN$ <> "Y" AND IN$ <> "N" THEN 20
21 IF IN$ = "Y" THEN GOSUB 194
22 PRINT : PRINT"WHAT LEVEL OF PLAY 1-7"
23 IN$ = INKEY$ : IFIN$ = "" THEN 23
24 B8 = VAL(IN$) - 1 : IF B8 < 0 OR B8 > 6 THEN 23
25 B7 = B8*2
26 IF B7 = 0 THEN B7 = 1
27 PRINT : PRINT"DO YOU WANT WHITE Y/N"
28 IN$ = INKEY$ : IF IN$ = "" THEN 28
29 IF IN$ <> "Y" AND IN$ <> "N" THEN 28
30 GOSUB 111
31 IF IN$ <> "N" THEN GOSUB 122 : GOTO 41
32 GOSUB 120
33 'COMPUTER MOVE
34 F = -99 : A0 = 0 : FOR J = 1 TO 8 : FOR K = 1 TO 8 : IF A(J,K) = 99 THEN A6 = J : A7 = K : GOTO 35 ELSE NEXT : NEXT
35 FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X , Y) < 0 THEN GOSUB 52 : IF F >= B7 THEN 37
36 NEXT : NEXT : IF F >= -9 THEN 37 ELSE 190
37 A(R , U) = A(E , Q) : A(E , Q) = 1 : IF A(R , U) = -2 AND U = 1 THEN A(R , U) = -9
38 X = R : Y = U : A0 = 4 : GOSUB 52 : SOUND 190 , 1 : SOUND 110 , 1 : SOUND 160 , 1 : SOUND 140 , 1 : PRINT@89 , "MY MOVE" ; : PRINT@121 , " WAS " ; : PRINT@155 , CHR$(E+64) ; CHR$(Q+48) ; CHR$(R+64) ; CHR$(U + 48);
39 GOSUB 124 : X = E : Y = Q : GOSUB 124 : IFC = 1 THEN PRINT@185 , " check " ; : C = 0 ELSE PRINT@185 , " "; :
40 'PLAYER MOVE
41 GOSUB 152 : D = 0 : B4 = A : B9 = B : B5 = 0
42 IF X$ = "K" OR X$ = "Q" THEN 34
43 A0 = 3 : GOSUB 48 : IF D = 0 THEN PRINT@25 , "illegal" ; : PRINT@57 , " move " ; : FOR J = 1 TO 1500 : NEXT : GOTO 41
44 PRINT@89 , " " ; : PRINT@121 , " " ; : PRINT@155 , " " ; : PRINT@217 , " " ; : PRINT@249 , " " ; : PRINT@315 , " " ; : A = B4 : B = B9 : A(A,B) = A(X,Y) : A(X,Y) = 1 : GOSUB 124 : X = A : Y = B : GOSUB 124
45 IF A(A , B) = 2 AND B = 8 THEN GOSUB 180 : GOSUB 124
46 IF B5 = 1 THEN A(A , B - 1) = 1 : X = A : Y = B - 1 : GOSUB 124 : GOTO 34 ELSE 34
47 'COMPUTER PIECE MOVE
48 PRINT@31 , CHR$(191) ; : ON A(X , Y) GOTO 9 , 74 , 9 , 65 , 59 , 9 , 54 , 9 , 59
49 'KING MOVE
50 FOR A = X - 1 TO X + 1 : FOR B = Y - 1 TO Y + 1 : IF A(A , B) <> 0 THEN GOSUB 94 : NEXT : NEXT : RETURN ELSE NEXT : NEXT : RETURN
51 'PLAYER PIECE MOVE
52 ON - A(X , Y) GOTO 9 , 80 , 9 , 65 , 59 , 9 , 54 , 9 , 59 : GOTO 50
53 'ROOK/QUEEN MOVE
54 B = Y : FOR A = X + 1 TO 8 : GOSUB 93 : IF S = 0 THEN NEXT
55 FOR A = X - 1 TO 1 STEP - 1 : GOSUB 93 : IF S = 0 THEN NEXT
56 A = X : FOR B = Y + 1 TO 8 : GOSUB 93 : IF S = 0 THEN NEXT
57 FOR B = Y - 1 TO 1 STEP - 1 : GOSUB 93 : IF S = 0 THEN NEXT : RETURN ELSE RETURN
58 'BISHOP/QUEEN MOVE
59 B = Y : FOR A = X + 1 TO 8 : B = B + 1 : GOSUB 93 : IF S = 0 THEN NEXT
60 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B - 1 : GOSUB 93 : IF S = 0 THEN NEXT
61 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B + 1 : GOSUB 93 : IF S = 0 THEN NEXT
62 B = Y : FOR A = X + 1 TO 8 : B = B - 1 : GOSUB 93 : IF S = 0 THEN NEXT
63 IF ABS(A(X , Y)) = 9 THEN 54 ELSE RETURN
64 'KNIGHT MOVE
65 A = X + 2 : B = Y + 1 : IF A < 9 AND B < 9 THEN GOSUB 94
66 B = B - 2 : IF B > 0 AND A < 9 THEN GOSUB 94
67 A = A - 4 : IF A > 0 AND B > 0 THEN GOSUB 94
68 B = B + 2 : IF B < 9 AND A > 0 THEN GOSUB 94
69 A = A + 1 : B = B + 1 : IF A > 0 AND A < 9 AND B < 9 THEN GOSUB 94
70 B = B - 4 : IF B > 0 AND A > 0 AND A < 9 THEN GOSUB 94
71 A = A + 2 : IF A > 0 AND A < 9 AND B > 0 THEN GOSUB 94
72 B = B + 4 : IF B < 9 AND A > 0 AND A < 9 THEN GOSUB 94 : RETURN ELSE RETURN
73 'PLAYER PAWN MOVE
74 A = X : IF Y > 2 THEN 76
75 B = Y + 1 : IF A(A , B) = 1 THEN GOSUB 95 : B = B + 1 : IF A(A , B) = 1 THEN GOSUB 95 : GOTO 77 ELSE 77 ELSE 77
76 B = Y + 1 : IF A(A , B) = 1 THEN GOSUB 95
77 A = X + 1 : B = Y + 1 : IF A(A , B) < 0 THEN GOSUB 95
78 A = A - 2 : IF A(A , B) < 0 THEN GOSUB 95 : RETURN ELSE RETURN
79 'COMPUTER PAWN MOVE
80 A = X : IF Y < 7 THEN 82
81 B = Y - 1 : IF A(A , B) = 1 THEN GOSUB 95 : B = B - 1 : IF A(A , B) = 1 THEN GOSUB 95 : GOTO 83 ELSE 83 ELSE 83
82 B = Y - 1 : IF A(A , B) = 1 THEN GOSUB 95
83 A = X - 1 : B = Y - 1 : IF A(A , B) > 1 THEN GOSUB 95
84 A = A + 2 : IF A(A , B) > 1 THEN GOSUB 95 : RETURN ELSE RETURN
85 'PROTECT ROUTINE
86 T = A(A , B) : IF T = -99 THEN B1 = T : RETURN
87 A5 = S : IF ABS(T) <= A(X , Y) THEN A(A , B) = A(X , Y) : A(X , Y) = 1 : GOTO 89
88 IF T < B1 THEN B1 = T : S = A5 : RETURN ELSE S = A5 : RETURN
89 A1 = X : A2 = Y : A3 = A : A4 = B : A8 = T : A0 = 2 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X , Y) <0 THEN GOSUB 52 : IF T = 0 THEN 91
90 NEXT : NEXT
91 X = A1 : Y = A2 : A = A3 : B = A4 : A0 = 5 : A(X , Y) = A(A , B) : A(A , B) = A8 : GOTO 88
92 'LEGAL MOVE CHECK
93 S = 0 : IF A(A , B) = 1 THEN 95 ELSEIF A(A , B) = 0 THEN S = 1 : RETURN ELSEIF SGN(A(A , B)) = SGN(A(X , Y)) THEN S = 1 : RETURN ELSE S = 1 : GOTO 95
94 IF A(A , B) <> 1 THEN IF SGN(A(A , B)) = SGN(A(X , Y))THEN RETURN
95 PRINT@31 , " " ; : ON A0 GOTO 96 , 97 , 98 , 99 , 100 : GOTO 102
96 IF A6 = A AND A7 = B THEN B1 = B1 + 1 : RETURN ELSE RETURN
97 IF A3 = A AND A4 = B THEN T = 0 : RETURN ELSE RETURN
98 IF B4 = A AND B9 = B THEN D = 1 : RETURN ELSE RETURN
99 IF A6 = A AND A7 = B THEN C = 1 : RETURN ELSE RETURN
100 IF A(A , B) < 0 THEN 86 ELSE RETURN
101 'LOOK-AHEAD ROUTINE
102 B3 = S : W = X : M = Y : N = A : H = B : P = A(A , B) : A(A , B) = A(X , Y) : A(X , Y) = 1 : B1 = 0
103 A0 = 5 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X , Y) > 1 THEN GOSUB 48
104 NEXT : NEXT : X = N : Y = H : A0 = 1 : GOSUB 52 : A0 = 0 : S = B3 : X = W : Y = M : A = N : B = H : A(X , Y) = A(A , B) : A(A , B) = P
105 'EVALUATE MOVE
106 B6 = 1/(ABS(4.5 - A) + ABS(4.5 - B) + 1) : IF A(X , Y) < -2 AND A(X , Y) > -9 THEN B6 = B6 + 1/(ABS(A6 - A) + ABS(A7 - B) + 5) + RND(0)/15
107 G = P + B1 + B6 : IF P = 99 THEN GOSUB 178 : PRINT@89 , " " ; : PRINT@121 , " mate! " ; : PRINT@153 , B$ ; : PRINT@185 , " " ; : GOTO 192
108 IF G <= F THEN RETURN
109 F = G : E = X : Q = Y : R = A : U = B : RETURN
110 'INITIALIZATION ROUTINE
111 CLS : FOR Y = 8 TO 1 STEP - 1 : FOR X = 1 TO 8 : READ A(X , Y) : NEXT : NEXT
112 FOR J = 1 TO 4 : SB$ = SB$ + STRING$(3 , CHR$(140)) + STRING$(3 , CHR$(131)) : SW$ = SW$ + STRING$(3 , CHR$(131)) + STRING$(3 , CHR$(140)) : NEXT
113 FOR J = 32 TO 416 STEP 128 : PRINT@J , SB$ ; : PRINT@J + 64 , SW$ ; : NEXT : FOR J = 1 TO 7 STEP 2 : PRINT@477 + J * 3 , CHR$(128) ; CHR$(J + 96) ; CHR$(128) ; CHR$(140) ; CHR$(J + 65) ; CHR$(140) ; : NEXT : FOR J = 1 TO 8 : PRINT@J * 64 - 8 , CHR$(128) ; : PRINT@J*64 - 40 , CHR$(57 - J) ; : NEXT : PRINT@504 , CHR$(128) ; : RETURN
114 DATA -7 , -4 , -5 , -9 , -99 , -5 , -4 , -7
115 DATA -2 , -2 , -2 , -2 , -2 , -2 , -2 ,-2
116 DATA 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
117 DATA 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2
118 DATA 7 , 4 , 5 , 9 , 99 , 5 , 4 , 7
119 'PLAYER REQUESTS BLACK
120 I = -I : A(4 , 1) = 99 : A(5 , 1) = 9 : A(4 , 8) = -99 : A(5 , 8) = -9
121 'GRAPHIC DRIVER-FULL SCREEN
122 FOR Y= 1 TO 8 : FOR X = 1 TO 8 : GOSUB 124 : NEXT : NEXT : RETURN
123 'GRAPHIC DRIVER-ONE PIECE
124 L = 509 + X*3 - Y*64 : IF X + Y - INT((X + Y)/2)*2 = 0 THEN 126
125 IF I*A(X , Y) >0 THEN ON ABS(A(X , Y)) GOTO 127 , 128 , 9 , 129 , 130 , 9 , 131 , 9 , 132 : PRINT@L , " K " ; : RETURN ELSE ON ABS(A(X , Y)) GOTO 127 , 133 , 9 , 134 , 135 , 9 , 136 , 9 , 137 : PRINT@L , " k " ; : RETURN
126 IF I*A(X , Y) >0 THEN ON ABS(A(X , Y)) GOTO 138 , 139 , 9 , 140 , 141 , 9 , 142 , 9 , 143 : PRINT@L , CHR$(128) ; "K" ; CHR$(128) ; : RETURN ELSE ON ABS(A(X , Y)) GOTO 138 , 144 , 9 , 145 , 146 , 9 , 147 , 9 , 148 : PRINT@L , CHR$(128) ; "k" ; CHR$(128) ; : RETURN
127 PRINT@L , " " ; : RETURN
128 PRINT@L , " P " ; : RETURN
129 PRINT@L , " N " ; : RETURN
130 PRINT@L , " B " ; : RETURN
131 PRINT@L , " R " ; : RETURN
132 PRINT@L , " Q " ; : RETURN
133 PRINT@L , " p " ; : RETURN
134 PRINT@L , " n " ; : RETURN
135 PRINT@L , " b " ; : RETURN
136 PRINT@L , " r " ; : RETURN
137 PRINT@L , " q " ; : RETURN
138 PRINT@L , STRING$(3 , CHR$(128)) ; : RETURN
139 PRINT@L , CHR$(128) ; "P" ; CHR$(128) ; : RETURN
140 PRINT@L , CHR$(128) ; "N" ; CHR$(128) ; : RETURN
141 PRINT@L , CHR$(128) ; "B" ; CHR$(128) ; : RETURN
142 PRINT@L , CHR$(128) ; "R" ; CHR$(128) ; : RETURN
143 PRINT@L , CHR$(128) ; "Q" ; CHR$(128) ; : RETURN
144 PRINT@L , CHR$(128) ; "p" ; CHR$(128) ; : RETURN
145 PRINT@L , CHR$(128) ; "n" ; CHR$(128) ; : RETURN
146 PRINT@L , CHR$(128) ; "b" ; CHR$(128) ; : RETURN
147 PRINT@L , CHR$(128) ; "r" ; CHR$(128) ; : RETURN
148 PRINT@L , CHR$(128) ; "q" ; CHR$(128) ; : RETURN
149 'INPUT ROUTINE
150 PRINT@25 , "cannot " ; : PRINT@57 , "castle " ; : FOR J = 1 TO 1500 : NEXT : GOTO 152
151 PRINT@25 , " entry " ; : PRINT@57 , " error " ; : FOR J = 1 TO 1500 : NEXT
152 GOSUB 175 : GOSUB 178 : PRINT@217 , " your " ; : PRINT@249 , " move ";
153 X$ = INKEY$ : IF X$ = "" THEN 153
154 PRINT@315 , X$;
155 SOUND 120,1
156 X1$ = INKEY$ : IF X1$ = "" THEN 156
157 PRINT@316 , X1$;
158 SOUND 120,1
159 X2$ = INKEY$ : IF X2$ = "" THEN 159
160 PRINT@317 , X2$;
161 SOUND 120,1
162 X3$ = INKEY$ : IF X3$ = "" THEN 162
163 PRINT@318 , X3$ ; : IN$ = X$ + X1$ + X2$ + X3$
164 SOUND 150,1
165 IF X$ >= "A" AND X$ <= "H" THEN 173
166 IF X$ = "K" THEN IF A(5 , 1) = 99 AND A(8 , 1) = 7 AND A(6 , 1) < 2 AND A(7 , 1) < 2 THEN A(5 , 1) = 1 : A(6 , 1) = 7 : A(7 , 1) = 99 : A(8 , 1) = 1 : GOTO 176
167 IF X$ = "Q" THEN IF A(5 , 1) = 99 AND A(1 , 1) = 7 AND A(4 , 1) < 2 AND A(3 , 1) < 2 THEN A(5 , 1) = 1 : A(4 , 1) = 7 : A(3 , 1) = 99 : A(1 , 1) = 1 : GOTO 176
168 IF X$ = "K" THEN IF A(4 , 1) = 99 AND A(1 , 1) = 7 AND A(3 , 1) < 2 AND A(2 , 1) < 2 THEN A(4 , 1) = 1 : A(3 , 1) = 7 : A(2 , 1) = 99 : A(1 , 1) = 1 : GOTO 176
169 IF X$ = "Q" THEN IF A(4 , 1) = 99 AND A(8 , 1) = 7 AND A(5 , 1) < 2 AND A(6 , 1) < 2 THEN A(4 , 1) = 1 : A(5 , 1) = 7 : A(6 , 1) = 99 : A(8 , 1) = 1 : GOTO 176
170 'DECODE INPUT
171 IF X$ = "I" THEN GOSUB 194 : GOSUB 113 : GOSUB 122 : GOTO 152
172 IF X$ = "P" THEN RUN ELSE 151
173 IF LEN(IN$) = 4 THEN X = ASC(X$) - 64 : Y = ASC(MID$(IN$ , 2 , 1)) - 48 : A = ASC(MID$(IN$ , 3 , 1)) - 64 : B = ASC(MID$(IN$ , 4 , 1)) - 48 ELSE 151
174 IF Y < 1 OR Y > 8 OR A < 1 OR A > 8 OR B < 1 OR B > 8 THEN 151 ELSE IF A(X , Y) < 2 OR A(A , B) > 1 THEN 151 ELSE GOSUB 175 : RETURN
175 PRINT@25 , " " ; : PRINT@57 , " " ; : RETURN
176 PRINT@313 , "CASTLE " ; : PRINT@345 , X$ ; "-SIDE " ; : GOSUB 175 : GOSUB 122 : RETURN
177 'BLANK MESSAGE AREA
178 FOR J = 217 TO 345 STEP 32 : PRINT@J , " " ; : NEXT : RETURN
179 'PROMOTE PLAYER PAWN
180 GOSUB 178 : PRINT@217 , " what " ; : PRINT@249 , " piece " ; : PRINT@281 , " PNBRQ " ; :
181 IN$ = INKEY$ : IF IN$ = "" THEN 181
182 IF IN$ <> "P" AND IN$ <> "N" AND IN$ <> "B" AND IN$ <> "R" AND IN$ <> "Q" THEN PRINT@315 , " " ; : GOTO 181
183 PRINT@316 , IN$ ;
184 IF IN$ = "P" THEN A(A , B) = 2 : RETURN
185 IF IN$ = "N" THEN A(A , B) = 4 : RETURN
186 IF IN$ = "B" THEN A(A , B) = 5 : RETURN
187 IF IN$ = "R" THEN A(A , B) = 7 : RETURN
188 IF IN$ = "Q" THEN A(A , B) = 9 : RETURN ELSE 181
189 'END OF GAME
190 GOSUB 178 : PRINT@89 , " " ; : PRINT@121 , " YOU " ; : PRINT@153 , " WIN! " ;
191 POKE 65494 , 0
192 GOTO 192
193 'INSTRUCTIONS
194 CLS
195 PRINT" * INSTUCTIONS *"
196 PRINT"ENTER KKKK TO CASTLE KING SIDE"
197 PRINT" QQQQ TO CASTLE QUEEN SIDE"
198 PRINT" IIII TO GET INSTUCTIONS"
199 PRINT" PPPP TO START NEW GAME"
200 PRINT
201 PRINT" TO PROMOTE TO P, N, B, R OR Q"
202 PRINT" ENTER LETTER WHEN PROMPTED"
203 PRINT : PRINT" TO MOVE, CAPTURE OR CAPTURE"
204 PRINT" EN PASSANT, SPECIFY FROM/TO"
205 PRINT" (E.G. 'B1C3')"
206 PRINT : PRINT" LEVELS OF PLAY ARE 1 THRU 7"
207 PRINT
208 PRINT" (HIT ANY KEY)";
209 IN$ = INKEY$ : IF IN$ = "" THEN 209
210 CLS : RETURN

Let me know how you make out,

Les

Michael Sherwin
Posts: 2819
Joined: Fri May 26, 2006 1:00 am
Location: OH, USA

Re: Found this on an old floppy - throwing it away!

Post by Michael Sherwin » Sun Aug 12, 2007 4:50 pm

YL84 wrote:Thanks for the tips and advices. I think it is possible to make it
running, all the commands are still valids (hope peek and poke
are for displays, sound is not necessary, and print may be
replaced by a console.writeline). Maybe also changing the gosub
to sub. Well I'm just curious
how fast this little thing could be...
If you think that the peeks and pokes are really important to the chess algorithm then just affix a 'v' to the address to make them variables and then translate the peeks and pokes to code that will read and store variables. Just a thought.

Edit: But, I have not noticed any peeks or pokes in the chess algorithm!
Regards,
Mike

Michael Sherwin
Posts: 2819
Joined: Fri May 26, 2006 1:00 am
Location: OH, USA

Re: My 2nd attempt to parsing

Post by Michael Sherwin » Sun Aug 12, 2007 4:55 pm

Thanks Les, This makes it much easier to read.
Regards,
Mike

Rob

Re: Found this on an old floppy - throwing it away!

Post by Rob » Sun Aug 12, 2007 10:42 pm

I got it working on gwbasic :lol:
You can download gwbasic freely. I downloaded it from

http://www.madisoncounty.net/~kj5tf/Downloads.html

but I can not guarantee that it's safe.
Start gwbasic and do LOAD "chessmaster.txt",then F2 or 'run' and it goes.

It seems the original hardware had a build in boundary checker, I had to code it in on lines 590-620. Also it gets more memory on line 90.

The board display is not working but the moves are shown separately.


10 '*******************
20 '* CHESSMASTER *
30 '* BY: *
40 '* HAROLD SNYDER *
50 '* P.O. BOX 3330 *
60 '* CHEYENNE, WY *
70 '* 82003 *
80 '*******************
90 CLS : CLEAR ,32768,6000 'INCREASE AVAILABLE MEMORY
100 PRINT," * CHESSMASTER *"
110 PRINT," BY"
120 PRINT," HAROLD SNYDER"
130 FOR QZ = 1 TO 2999 : NEXT
140 A = 0 : B = 0 : X = 0 : Y = 0 : S = 0 : A0 = 0 : T=0 : A8 = 0 : A2 = 0 : A3 = 0 : A4 = 0 : B1 = 0 : B6 = 0 : H = 0 : M = 0 : N = 0 : P = 0 : A5 = 0 : I = 1 : DIM A(9,9),C(64)
142 POKE 248,&H32 : POKE 249,&H62 : POKE 250,&H1C : POKE 251,&HAF : POKE 252,&H7E : POKE 253,&HAD : POKE 254,&HA5 : POKE 410,&H7E : POKE 411,0 : POKE 412,&HF8
150 CLS : PRINT : PRINT" * CAN THIS COMPUTER USE THE HIGH SPEED POKE Y/N"
160 IN$ = INKEY$ : IF IN$ = "" THEN 160
170 IF IN$ <> "Y" AND IN$ <> "N" THEN 160
180 IF IN$ = "Y" THEN POKE 65495,0
190 CLS : PRINT : PRINT"DO YOU WANT INSTRUCTIONS Y/N"
200 IN$ = INKEY$ : IF IN$ <> "Y" AND IN$ <> "N" THEN 200
210 IF IN$ = "Y" THEN GOSUB 1940
220 PRINT : PRINT"WHAT LEVEL OF PLAY 1-7"
230 IN$ = INKEY$ : IF IN$ = "" THEN 230
240 B8 = VAL(IN$)-1 : IF B8<0 OR B8>6 THEN 230
250 B7 = B8*2
260 IF B7 = 0 THEN B7 = 1
270 PRINT : PRINT"DO YOU WANT WHITE Y/N"
280 IN$ = INKEY$ : IF IN$ = "" THEN 280
290 IF IN$ <> "Y" AND IN$ <> "N" THEN 280
300 GOSUB 1110 'INIT
310 IF IN$ <> "N" THEN GOSUB 1220 : GOTO 410
320 GOSUB 1200 'PLAYER WANTS BLACK
330 'COMPUTER MOVE
340 F = -99 : A0 = 0 : FOR J = 1 TO 8 : FOR K = 1 TO 8 : IF A(J,K) = 99 THEN A6 = J:A7 = K : GOTO 350 ELSE NEXT : NEXT
350 FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) < 0 THEN GOSUB 520 : IF F >= B7 THEN 370
360 NEXT : NEXT : IF F >= -9 THEN 370 ELSE 190
370 A(R,U) = A(E,Q) : A(E,Q) = 1 : IF A(R,U) = -2 AND U = 1 THEN A(R,U) = -9
380 X = R : Y = U : A0 = 4 : GOSUB 520 : SOUND 190 , 1 : SOUND 110 , 1 : SOUND 160 , 1 : SOUND 140 , 1 : PRINT, "MY MOVE" ; : PRINT, " WAS " ; :
382 PRINT CHR$(E+64) ; CHR$(Q+48) ; CHR$(R+64) ; CHR$(U + 48);
390 GOSUB 1240 : X = E : Y = Q : GOSUB 1240 : IF C = 1 THEN PRINT , " check " ; : C = 0 ELSE PRINT , " "; :
400 'PLAYER MOVE
410 GOSUB 1520 : D = 0 : B4 = A : B9 = B : B5 = 0
420 IF X$ = "K" OR X$ = "Q" THEN 340
430 A0 = 3 : GOSUB 480 : IF D = 0 THEN PRINT , "illegal" ; : PRINT , " move " ; : FOR J = 1 TO 1500 : NEXT : GOTO 410
440 PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : A = B4 : B = B9 :
442 A(A,B) = A(X,Y) : A(X,Y) = 1 : GOSUB 1240 : X = A : Y = B : GOSUB 1240
450 IF A(A,B) = 2 AND B = 8 THEN GOSUB 1800 : GOSUB 1240
460 IF B5 = 1 THEN A(A , B - 1) = 1 : X = A : Y = B - 1 : GOSUB 1240 : GOTO 340 ELSE 340
470 'COMPUTER PIECE MOVE
480 PRINT CHR$(191) ; :ON A(X , Y) GOTO 90 , 740 , 90 , 650 , 590 , 90 , 540 , 90 , 590
490 'KING MOVE
500 FOR A = X - 1 TO X + 1
505 FOR B = Y - 1 TO Y + 1
510 IF A(A,B) <> 0 THEN GOSUB 940
515 NEXT : NEXT : RETURN
520 ELSE NEXT : NEXT : RETURN
510 'PLAYER PIECE MOVE
520 ON (-A(X,Y)) GOTO 90 , 800 , 90 , 650 , 590 , 90 , 540 , 90 , 590 : GOTO 500
530 'ROOK/QUEEN MOVE
540 B = Y : FOR A = X + 1 TO 8 : GOSUB 930 : IF S = 0 THEN NEXT 'RIGHT
550 FOR A = X - 1 TO 1 STEP - 1 : GOSUB 930 : IF S = 0 THEN NEXT 'LEFT
560 A = X : FOR B = Y + 1 TO 8 : GOSUB 930 : IF S = 0 THEN NEXT 'UP
570 FOR B = Y - 1 TO 1 STEP - 1 : GOSUB 930 : IF S = 0 THEN NEXT : RETURN ELSE RETURN 'DOWN
580 'BISHOP/QUEEN MOVE
590 B = Y : FOR A = X + 1 TO 8 : B = B + 1 : IF B >9 THEN 600 ELSE GOSUB 930 : IF S = 0 THEN NEXT
600 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B - 1 : IF B <0 THEN 610 ELSE GOSUB 930 : IF S = 0 THEN NEXT
610 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B + 1 : IF B >9 THEN 620 ELSE GOSUB 930 : IF S = 0 THEN NEXT
620 B = Y : FOR A = X + 1 TO 8 : B = B - 1 : IF B <0 THEN 630 ELSE GOSUB 930 : IF S = 0 THEN NEXT
630 IF ABS(A(X,Y)) = 9 THEN 540 ELSE RETURN 'IF QUEEN TRY ROOK MOVES
640 'KNIGHT MOVE
650 A = X + 2 : B = Y + 1 : IF A < 9 AND B < 9 THEN GOSUB 940
660 B = B - 2 : IF B > 0 AND A < 9 THEN GOSUB 940
670 A = A - 4 : IF A > 0 AND B > 0 THEN GOSUB 940
680 B = B + 2 : IF B < 9 AND A > 0 THEN GOSUB 940
690 A = A + 1 : B = B + 1 : IF A > 0 AND A < 9 AND B < 9 THEN GOSUB 940
700 B = B - 4 : IF B > 0 AND A > 0 AND A < 9 THEN GOSUB 940
710 A = A + 2 : IF A > 0 AND A < 9 AND B > 0 THEN GOSUB 940
720 B = B + 4 : IF B < 9 AND A > 0 AND A < 9 THEN GOSUB 940 : RETURN ELSE RETURN
730 'PLAYER PAWN MOVE
740 A = X : IF Y > 2 THEN 760
750 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 950 : B = B + 1 : IF A(A,B) = 1 THEN GOSUB 950 : GOTO 770 ELSE 770 ELSE 770
760 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 950
770 A = X + 1 : B = Y + 1 : IF A(A,B) < 0 THEN GOSUB 950
780 A = A - 2 : IF A(A,B) < 0 THEN GOSUB 950 : RETURN ELSE RETURN
790 'COMPUTER PAWN MOVE
800 A = X : IF Y < 7 THEN 820
810 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 950 : B = B - 1 : IF A(A,B) = 1 THEN GOSUB 950 : GOTO 830 ELSE 830 ELSE 830
820 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 950
830 A = X - 1 : B = Y - 1 : IF A(A,B) > 1 THEN GOSUB 950
840 A = A + 2 : IF A(A,B) > 1 THEN GOSUB 950 : RETURN ELSE RETURN
850 'PROTECT ROUTINE
860 T = A(A,B) : IF T = -99 THEN B1 = T : RETURN
870 A5 = S : IF ABS(T) <= A(X,Y) THEN A(A,B) = A(X,Y) : A(X,Y) = 1 : GOTO 890
880 IF T < B1 THEN B1 = T : S = A5 : RETURN ELSE S = A5 : RETURN
890 A1 = X : A2 = Y : A3 = A : A4 = B : A8 = T : A0 = 2 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) <0 THEN GOSUB 520 : IF T = 0 THEN 910
900 NEXT : NEXT
910 X = A1 : Y = A2 : A = A3 : B = A4 : A0 = 5 : A(X,Y) = A(A,B) : A(A,B) = A8 : GOTO 880
920 'LEGAL MOVE CHECK
930 S = 0 'RESET LEGAL
932 IF A(A,B) = 1 THEN 950 ELSE IF A(A,B) = 0 THEN S = 1 : RETURN ELSE IF (SGN(A(A,B))) = (SGN(A(X,Y))) THEN S = 1 : RETURN ELSE S = 1 : GOTO 950 'EMPTY,OFFBOARD,FRIENDLY,OK
940 IF A(A,B) <> 1 THEN IF SGN(A(A,B)) = SGN(A(X,Y)) THEN RETURN
950 PRINT " " ; : ON A0 GOTO 960 , 970 , 980 , 990 , 1000 : GOTO 1020
960 IF A6 = A AND A7 = B THEN B1 = B1 + 1 : RETURN ELSE RETURN
970 IF A3 = A AND A4 = B THEN T = 0 : RETURN ELSE RETURN
980 IF B4 = A AND B9 = B THEN D = 1 : RETURN ELSE RETURN
990 IF A6 = A AND A7 = B THEN C = 1 : RETURN ELSE RETURN
1000 IF A(A,B) < 0 THEN 860 ELSE RETURN
1010 'LOOK-AHEAD ROUTINE
1020 B3 = S : W = X : M = Y : N = A : H = B : P = A(A,B) : A(A,B) = A(X,Y) : A(X,Y) = 1 : B1 = 0
1030 A0 = 5 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) > 1 THEN GOSUB 480
1040 NEXT : NEXT : X = N : Y = H : A0 = 1 : GOSUB 520 : A0 = 0 : S = B3 : X = W : Y = M : A = N : B = H : A(X,Y) = A(A,B) : A(A,B) = P
1050 'EVALUATE MOVE
1060 B6 = 1/(ABS(4.5 - A) + ABS(4.5 - B) + 1) : IF A(X,Y) < -2 AND A(X,Y) > -9 THEN B6 = B6 + 1/(ABS(A6 - A) + ABS(A7 - B) + 5) + RND(0)/15
1070 G = P + B1 + B6 : IF P = 99 THEN GOSUB 1780 : PRINT , " " ; : PRINT , " mate! " ; : PRINT , B$ ; : PRINT , " " ; : GOTO 1920
1080 IF G <= F THEN RETURN
1090 F = G : E = X : Q = Y : R = A : U = B : RETURN
1100 'INITIALIZATION ROUTINE
1110 CLS : FOR Y = 8 TO 1 STEP - 1 : FOR X = 1 TO 8 : READ A(X,Y) : NEXT : NEXT
1120 FOR J = 1 TO 4 : SB$ = SB$ + STRING$(3 , CHR$(140)) + STRING$(3 , CHR$(131)) : SW$ = SW$ + STRING$(3 , CHR$(131)) + STRING$(3 , CHR$(140)) : NEXT
1130 FOR J = 32 TO 416 STEP 128 : PRINT SB$ ; : PRINT SW$ ; : NEXT : FOR J = 1 TO 7 STEP 2 :
1132 PRINT CHR$(128) ; CHR$(J + 96) ; CHR$(128) ; CHR$(140) ; CHR$(J + 65) ; CHR$(140) ; : NEXT :
1134 FOR J = 1 TO 8 : PRINT CHR$(128) ; : PRINT CHR$(57-J) ; : NEXT : PRINT CHR$(128) ; : RETURN
1140 DATA -7 , -4 , -5 , -9 , -99 , -5 , -4 , -7
1150 DATA -2 , -2 , -2 , -2 , -2 , -2 , -2 ,-2
1160 DATA 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
1170 DATA 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2
1180 DATA 7 , 4 , 5 , 9 , 99 , 5 , 4 , 7
1190 'PLAYER REQUESTS BLACK
1200 I = -I : A(4,1) = 99 : A(5,1) = 9 : A(4,8) = -99 : A(5,8) = -9 'FLIP BOARD
1210 'GRAPHIC DRIVER-FULL SCREEN
1220 FOR Y= 1 TO 8 : FOR X = 1 TO 8 : GOSUB 1240 : NEXT : NEXT : RETURN
1230 'GRAPHIC DRIVER-ONE PIECE
1240 L = 509 + X*3 - Y*64 : IF X + Y - INT((X + Y)/2)*2 = 0 THEN 1260
1250 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 1270 , 1280 , 90 , 1290 , 1300 , 90 , 1310 , 90 , 1320 :
1252 PRINT " K " ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 1270 , 1330 , 90 , 1340 , 1350 , 90 , 1360 , 90 , 1370 : PRINT , " k " ; : RETURN
1260 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 1380 , 1390 , 90 , 1400 , 1410 , 90 , 1420 , 90 , 1430 :
1262 PRINT "K" ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 1380 , 1440 , 90 , 1450 , 1460 , 90 , 1470 , 90 , 1480 :
1264 PRINT "k" ; : RETURN
1270 PRINT " " ; : RETURN
1280 PRINT " P " ; : RETURN
1290 PRINT " N " ; : RETURN
1300 PRINT " B " ; : RETURN
1310 PRINT " R ";; ; : RETURN
1320 PRINT " Q " ; : RETURN
1330 PRINT " p " ; : RETURN
1340 PRINT " n " ; : RETURN
1350 PRINT " b " ; : RETURN
1360 PRINT " r " ; : RETURN
1370 PRINT " q " ; : RETURN
1380 RETURN
1390 PRINT "P"; : RETURN
1400 PRINT "N"; : RETURN
1410 PRINT "B"; : RETURN
1420 PRINT "R" : RETURN
1430 PRINT "Q"; : RETURN
1440 PRINT "p"; : RETURN
1450 PRINT "n"; : RETURN
1460 PRINT "b"; : RETURN
1470 PRINT "r"; : RETURN
1480 PRINT "q"; : RETURN
1490 'INPUT ROUTINE
1500 PRINT , "cannot " ; : PRINT , "castle " ; : FOR J = 1 TO 1500 : NEXT : GOTO 1520
1510 PRINT , " entry " ; : PRINT , " error " ; : FOR J = 1 TO 1500 : NEXT
1520 GOSUB 1750 : GOSUB 1780 : PRINT , " your " ; : PRINT , " move ";
1530 X$ = INKEY$ : IF X$ = "" THEN 1530
1540 PRINT , X$;
1550 SOUND 120,1
1560 X1$ = INKEY$ : IF X1$ = "" THEN 1560
1570 PRINT , X1$;
1580 SOUND 120,1
1590 X2$ = INKEY$ : IF X2$ = "" THEN 1590
1600 PRINT , X2$;
1610 SOUND 120,1
1620 X3$ = INKEY$ : IF X3$ = "" THEN 1620
1630 PRINT , X3$ ; : IN$ = X$ + X1$ + X2$ + X3$
1640 SOUND 150,1
1650 IF X$ >= "A" AND X$ <= "H" THEN 1730
1660 IF X$ = "K" THEN IF A(5,1) = 99 AND A(8,1) = 7 AND A(6,1) < 2 AND A(7,1) < 2 THEN A(5,1) = 1 : A(6,1) = 7 : A(7,1) = 99 : A(8,1) = 1 : GOTO 1760
1670 IF X$ = "Q" THEN IF A(5,1) = 99 AND A(1,1) = 7 AND A(4,1) < 2 AND A(3,1) < 2 THEN A(5,1) = 1 : A(4,1) = 7 : A(3,1) = 99 : A(1,1) = 1 : GOTO 1760
1680 IF X$ = "K" THEN IF A(4,1) = 99 AND A(1,1) = 7 AND A(3,1) < 2 AND A(2,1) < 2 THEN A(4,1) = 1 : A(3,1) = 7 : A(2,1) = 99 : A(1,1) = 1 : GOTO 1760
1690 IF X$ = "Q" THEN IF A(4,1) = 99 AND A(8,1) = 7 AND A(5,1) < 2 AND A(6,1) < 2 THEN A(4,1) = 1 : A(5,1) = 7 : A(6,1) = 99 : A(8,1) = 1 : GOTO 1760
1700 'DECODE INPUT
1710 IF X$ = "I" THEN GOSUB 1940 : GOSUB 1130 : GOSUB 1220 : GOTO 1520
1720 IF X$ = "P" THEN RUN ELSE 1510
1730 IF LEN(IN$) = 4 THEN X = ASC(X$) - 64 : Y = ASC(MID$(IN$ , 2 , 1)) - 48 : A = ASC(MID$(IN$ , 3 , 1)) - 64 : B = ASC(MID$(IN$ , 4 , 1)) - 48 ELSE 1510
1740 IF Y < 1 OR Y > 8 OR A < 1 OR A > 8 OR B < 1 OR B > 8 THEN 1510 ELSE IF A(X,Y) < 2 OR A(A , B) > 1 THEN 1510 ELSE GOSUB 1750 : RETURN
1750 PRINT , " " ; : PRINT , " " ; : RETURN
1760 PRINT , "CASTLE " ; : PRINT , X$ ; "-SIDE " ; : GOSUB 1750 : GOSUB 1220 : RETURN
1770 'BLANK MESSAGE AREA
1780 FOR J = 217 TO 345 STEP 32 : PRINT , " " ; : NEXT : RETURN
1790 'PROMOTE PLAYER PAWN
1800 GOSUB 1780 : PRINT , " what " ; : PRINT , " piece " ; : PRINT , " PNBRQ " ; :
1810 IN$ = INKEY$ : IF IN$ = "" THEN 1810
1820 IF IN$ <> "P" AND IN$ <> "N" AND IN$ <> "B" AND IN$ <> "R" AND IN$ <> "Q" THEN PRINT , " " ; : GOTO 1810
1830 PRINT , IN$ ;
1840 IF IN$ = "P" THEN A(A,B) = 2 : RETURN
1850 IF IN$ = "N" THEN A(A,B) = 4 : RETURN
1860 IF IN$ = "B" THEN A(A,B) = 5 : RETURN
1870 IF IN$ = "R" THEN A(A,B) = 7 : RETURN
1880 IF IN$ = "Q" THEN A(A,B) = 9 : RETURN ELSE 1810
1890 'END OF GAME
1900 GOSUB 1780 : PRINT , " " ; : PRINT , " YOU " ; : PRINT , " WIN! " ;
1910 POKE65494,0
1920 GOTO 1920
1930 'INSTRUCTIONS
1940 CLS
1950 PRINT" * INSTUCTIONS *"
1960 PRINT"ENTER KKKK TO CASTLE KING SIDE"
1970 PRINT" QQQQ TO CASTLE QUEEN SIDE"
1980 PRINT" IIII TO GET INSTUCTIONS"
1990 PRINT" PPPP TO START NEW GAME"
2000 PRINT
2010 PRINT" TO PROMOTE TO P, N, B, R OR Q"
2020 PRINT" ENTER LETTER WHEN PROMPTED"
2030 PRINT : PRINT" TO MOVE, CAPTURE OR CAPTURE"
2040 PRINT" EN PASSANT, SPECIFY FROM/TO"
2050 PRINT" (E.G. 'B1C3')"
2060 PRINT : PRINT" LEVELS OF PLAY ARE 1 THRU 7"
2070 PRINT
2080 PRINT" (HIT ANY KEY)";
2090 IN$ = INKEY$ : IF IN$ = "" THEN 2090
2100 CLS : RETURN

Rob

Re: Found this on an old floppy - throwing it away!

Post by Rob » Mon Aug 13, 2007 1:06 am

There was a problem with kingmoves due to documented bug in gwbasic3.
I had to reformat line 500.
There still may be a problem with mating.
Better version:

10 '*******************
20 '* CHESSMASTER *
30 '* BY: *
40 '* HAROLD SNYDER *
50 '* P.O. BOX 3330 *
60 '* CHEYENNE, WY *
70 '* 82003 *
80 '*******************
90 CLS : CLEAR ,32768,6000 'INCREASE AVAILABLE MEMORY
100 PRINT," * CHESSMASTER *"
110 PRINT," BY"
120 PRINT," HAROLD SNYDER"
130 FOR QZ = 1 TO 2999 : NEXT
140 A = 0 : B = 0 : X = 0 : Y = 0 : S = 0 : A0 = 0 : T=0 : A8 = 0 : A2 = 0 : A3 = 0 : A4 = 0 : B1 = 0 : B6 = 0 : H = 0 : M = 0 : N = 0 : P = 0 : A5 = 0 : I = 1 : DIM A(9,9),C(64)
142 POKE 248,&H32 : POKE 249,&H62 : POKE 250,&H1C : POKE 251,&HAF : POKE 252,&H7E : POKE 253,&HAD : POKE 254,&HA5 : POKE 410,&H7E : POKE 411,0 : POKE 412,&HF8
150 CLS : PRINT : PRINT" * CAN THIS COMPUTER USE THE HIGH SPEED POKE Y/N"
160 IN$ = INKEY$ : IF IN$ = "" THEN 160
170 IF IN$ <> "Y" AND IN$ <> "N" THEN 160
180 IF IN$ = "Y" THEN POKE 65495,0
190 CLS : PRINT : PRINT"DO YOU WANT INSTRUCTIONS Y/N"
200 IN$ = INKEY$ : IF IN$ <> "Y" AND IN$ <> "N" THEN 200
210 IF IN$ = "Y" THEN GOSUB 1940
220 PRINT : PRINT"WHAT LEVEL OF PLAY 1-7"
230 IN$ = INKEY$ : IF IN$ = "" THEN 230
240 B8 = VAL(IN$)-1 : IF B8<0 OR B8>6 THEN 230
250 B7 = B8*2
260 IF B7 = 0 THEN B7 = 1
270 PRINT : PRINT"DO YOU WANT WHITE Y/N"
280 IN$ = INKEY$ : IF IN$ = "" THEN 280
290 IF IN$ <> "Y" AND IN$ <> "N" THEN 280
300 GOSUB 1110 'INIT
310 IF IN$ <> "N" THEN GOSUB 1220 : GOTO 410
320 GOSUB 1200 'PLAYER WANTS BLACK
330 'COMPUTER MOVE
340 F = -99 : A0 = 0 : FOR J = 1 TO 8 : FOR K = 1 TO 8 : IF A(J,K) = 99 THEN A6 = J:A7 = K : GOTO 350 ELSE NEXT : NEXT
350 FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) < 0 THEN GOSUB 520 : IF F >= B7 THEN 370
360 NEXT : NEXT : IF F >= -9 THEN 370 ELSE 190
370 A(R,U) = A(E,Q) : A(E,Q) = 1 : IF A(R,U) = -2 AND U = 1 THEN A(R,U) = -9
380 X = R : Y = U : A0 = 4 : GOSUB 520 : SOUND 190 , 1 : SOUND 110 , 1 : SOUND 160 , 1 : SOUND 140 , 1 : PRINT, "MY MOVE" ; : PRINT, " WAS " ; :
382 PRINT CHR$(E+64) ; CHR$(Q+48) ; CHR$(R+64) ; CHR$(U + 48);
390 GOSUB 1240 : X = E : Y = Q : GOSUB 1240 : IF C = 1 THEN PRINT , " check " ; : C = 0 ELSE PRINT , " "; :
400 'PLAYER MOVE
410 GOSUB 1520 : D = 0 : B4 = A : B9 = B : B5 = 0
420 IF X$ = "K" OR X$ = "Q" THEN 340
430 A0 = 3 : GOSUB 480 : IF D = 0 THEN PRINT , "illegal" ; : PRINT , " move " ; : FOR J = 1 TO 1500 : NEXT : GOTO 410
440 PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : PRINT " " ; : A = B4 : B = B9 :
442 A(A,B) = A(X,Y) : A(X,Y) = 1 : GOSUB 1240 : X = A : Y = B : GOSUB 1240
450 IF A(A,B) = 2 AND B = 8 THEN GOSUB 1800 : GOSUB 1240
460 IF B5 = 1 THEN A(A , B - 1) = 1 : X = A : Y = B - 1 : GOSUB 1240 : GOTO 340 ELSE 340
470 'COMPUTER PIECE MOVE
480 PRINT CHR$(191) ; :ON A(X , Y) GOTO 90 , 740 , 90 , 650 , 590 , 90 , 540 , 90 , 590
490 'KING MOVE
500 FOR A = X - 1 TO X + 1 :FOR B = Y - 1 TO Y + 1
505 IF A(A,B) <> 0 THEN GOSUB 940
506 NEXT B: NEXT A: RETURN
508 ELSE NEXT B: NEXT A: RETURN
510 'PLAYER PIECE MOVE
520 ON (-A(X,Y)) GOTO 90 , 800 , 90 , 650 , 590 , 90 , 540 , 90 , 590 : GOTO 500
530 'ROOK/QUEEN MOVE
540 B = Y : FOR A = X + 1 TO 8 : GOSUB 930 : IF S = 0 THEN NEXT 'RIGHT
550 FOR A = X - 1 TO 1 STEP - 1 : GOSUB 930 : IF S = 0 THEN NEXT 'LEFT
560 A = X : FOR B = Y + 1 TO 8 : GOSUB 930 : IF S = 0 THEN NEXT 'UP
570 FOR B = Y - 1 TO 1 STEP - 1 : GOSUB 930 : IF S = 0 THEN NEXT : RETURN ELSE RETURN 'DOWN
580 'BISHOP/QUEEN MOVE
590 B = Y : FOR A = X + 1 TO 8 : B = B + 1 : IF B >9 THEN 600 ELSE GOSUB 930 : IF S = 0 THEN NEXT
600 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B - 1 : IF B <0 THEN 610 ELSE GOSUB 930 : IF S = 0 THEN NEXT
610 B = Y : FOR A = X - 1 TO 1 STEP - 1 : B = B + 1 : IF B >9 THEN 620 ELSE GOSUB 930 : IF S = 0 THEN NEXT
620 B = Y : FOR A = X + 1 TO 8 : B = B - 1 : IF B <0 THEN 630 ELSE GOSUB 930 : IF S = 0 THEN NEXT
630 IF ABS(A(X,Y)) = 9 THEN 540 ELSE RETURN 'IF QUEEN TRY ROOK MOVES
640 'KNIGHT MOVE
650 A = X + 2 : B = Y + 1 : IF A < 9 AND B < 9 THEN GOSUB 940
660 B = B - 2 : IF B > 0 AND A < 9 THEN GOSUB 940
670 A = A - 4 : IF A > 0 AND B > 0 THEN GOSUB 940
680 B = B + 2 : IF B < 9 AND A > 0 THEN GOSUB 940
690 A = A + 1 : B = B + 1 : IF A > 0 AND A < 9 AND B < 9 THEN GOSUB 940
700 B = B - 4 : IF B > 0 AND A > 0 AND A < 9 THEN GOSUB 940
710 A = A + 2 : IF A > 0 AND A < 9 AND B > 0 THEN GOSUB 940
720 B = B + 4 : IF B < 9 AND A > 0 AND A < 9 THEN GOSUB 940 : RETURN ELSE RETURN
730 'PLAYER PAWN MOVE
740 A = X : IF Y > 2 THEN 760
750 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 950 : B = B + 1 : IF A(A,B) = 1 THEN GOSUB 950 : GOTO 770 ELSE 770 ELSE 770
760 B = Y + 1 : IF A(A,B) = 1 THEN GOSUB 950
770 A = X + 1 : B = Y + 1 : IF A(A,B) < 0 THEN GOSUB 950
780 A = A - 2 : IF A(A,B) < 0 THEN GOSUB 950 : RETURN ELSE RETURN
790 'COMPUTER PAWN MOVE
800 A = X : IF Y < 7 THEN 820
810 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 950 : B = B - 1 : IF A(A,B) = 1 THEN GOSUB 950 : GOTO 830 ELSE 830 ELSE 830
820 B = Y - 1 : IF A(A,B) = 1 THEN GOSUB 950
830 A = X - 1 : B = Y - 1 : IF A(A,B) > 1 THEN GOSUB 950
840 A = A + 2 : IF A(A,B) > 1 THEN GOSUB 950 : RETURN ELSE RETURN
850 'PROTECT ROUTINE
860 T = A(A,B) : IF T = -99 THEN B1 = T : RETURN
870 A5 = S : IF ABS(T) <= A(X,Y) THEN A(A,B) = A(X,Y) : A(X,Y) = 1 : GOTO 890
880 IF T < B1 THEN B1 = T : S = A5 : RETURN ELSE S = A5 : RETURN
890 A1 = X : A2 = Y : A3 = A : A4 = B : A8 = T : A0 = 2 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) <0 THEN GOSUB 520 : IF T = 0 THEN 910
900 NEXT : NEXT
910 X = A1 : Y = A2 : A = A3 : B = A4 : A0 = 5 : A(X,Y) = A(A,B) : A(A,B) = A8 : GOTO 880
920 'LEGAL MOVE CHECK
930 S = 0 'RESET LEGAL
932 IF A(A,B) = 1 THEN 950 ELSE IF A(A,B) = 0 THEN S = 1 : RETURN ELSE IF (SGN(A(A,B))) = (SGN(A(X,Y))) THEN S = 1 : RETURN ELSE S = 1 : GOTO 950 'EMPTY,OFFBOARD,FRIENDLY,OK
940 IF A(A,B) <> 1 THEN IF SGN(A(A,B)) = SGN(A(X,Y)) THEN RETURN 'friendly
950 PRINT " " ; : ON A0 GOTO 960 , 970 , 980 , 990 , 1000 : GOTO 1020
960 IF A6 = A AND A7 = B THEN B1 = B1 + 1 : RETURN ELSE RETURN
970 IF A3 = A AND A4 = B THEN T = 0 : RETURN ELSE RETURN
980 IF B4 = A AND B9 = B THEN D = 1 : RETURN ELSE RETURN
990 IF A6 = A AND A7 = B THEN C = 1 : RETURN ELSE RETURN
1000 IF A(A,B) < 0 THEN 860 ELSE RETURN
1010 'LOOK-AHEAD ROUTINE
1020 B3 = S : W = X : M = Y : N = A : H = B : P = A(A,B) : A(A,B) = A(X,Y) : A(X,Y) = 1 : B1 = 0
1030 A0 = 5 : FOR X = 1 TO 8 : FOR Y = 1 TO 8 : IF A(X,Y) > 1 THEN GOSUB 480
1040 NEXT : NEXT : X = N : Y = H : A0 = 1 : GOSUB 520 : A0 = 0 : S = B3 : X = W : Y = M : A = N : B = H : A(X,Y) = A(A,B) : A(A,B) = P
1050 'EVALUATE MOVE
1060 B6 = 1/(ABS(4.5 - A) + ABS(4.5 - B) + 1) : IF A(X,Y) < -2 AND A(X,Y) > -9 THEN B6 = B6 + 1/(ABS(A6 - A) + ABS(A7 - B) + 5) + RND(0)/15
1070 G = P + B1 + B6 : IF P = 99 THEN GOSUB 1780 : PRINT , " " ; : PRINT , " mate! " ; : PRINT , B$ ; : PRINT , " " ; : GOTO 1920
1080 IF G <= F THEN RETURN
1090 F = G : E = X : Q = Y : R = A : U = B : RETURN
1100 'INITIALIZATION ROUTINE
1110 CLS : FOR Y = 8 TO 1 STEP - 1 : FOR X = 1 TO 8 : READ A(X,Y) : NEXT : NEXT
1120 FOR J = 1 TO 4 : SB$ = SB$ + STRING$(3 , CHR$(140)) + STRING$(3 , CHR$(131)) : SW$ = SW$ + STRING$(3 , CHR$(131)) + STRING$(3 , CHR$(140)) : NEXT
1130 FOR J = 32 TO 416 STEP 128 : PRINT SB$ ; : PRINT SW$ ; : NEXT : FOR J = 1 TO 7 STEP 2 :
1132 PRINT CHR$(128) ; CHR$(J + 96) ; CHR$(128) ; CHR$(140) ; CHR$(J + 65) ; CHR$(140) ; : NEXT :
1134 FOR J = 1 TO 8 : PRINT CHR$(128) ; : PRINT CHR$(57-J) ; : NEXT : PRINT CHR$(128) ; : RETURN
1140 DATA -7 , -4 , -5 , -9 , -99 , -5 , -4 , -7
1150 DATA -2 , -2 , -2 , -2 , -2 , -2 , -2 ,-2
1160 DATA 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
1170 DATA 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2
1180 DATA 7 , 4 , 5 , 9 , 99 , 5 , 4 , 7
1190 'PLAYER REQUESTS BLACK
1200 I = -I : A(4,1) = 99 : A(5,1) = 9 : A(4,8) = -99 : A(5,8) = -9 'FLIP BOARD
1210 'GRAPHIC DRIVER-FULL SCREEN
1220 FOR Y= 1 TO 8 : FOR X = 1 TO 8 : GOSUB 1240 : NEXT : NEXT : RETURN
1230 'GRAPHIC DRIVER-ONE PIECE
1240 L = 509 + X*3 - Y*64 : IF X + Y - INT((X + Y)/2)*2 = 0 THEN 1260
1250 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 1270 , 1280 , 90 , 1290 , 1300 , 90 , 1310 , 90 , 1320 :
1252 PRINT " K " ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 1270 , 1330 , 90 , 1340 , 1350 , 90 , 1360 , 90 , 1370 : PRINT , " k " ; : RETURN
1260 IF I*A(X,Y) >0 THEN ON ABS(A(X,Y)) GOTO 1380 , 1390 , 90 , 1400 , 1410 , 90 , 1420 , 90 , 1430 :
1262 PRINT "K" ; : RETURN ELSE ON ABS(A(X,Y)) GOTO 1380 , 1440 , 90 , 1450 , 1460 , 90 , 1470 , 90 , 1480 :
1264 PRINT "k" ; : RETURN
1270 PRINT " " ; : RETURN
1280 PRINT " P " ; : RETURN
1290 PRINT " N " ; : RETURN
1300 PRINT " B " ; : RETURN
1310 PRINT " R ";; ; : RETURN
1320 PRINT " Q " ; : RETURN
1330 PRINT " p " ; : RETURN
1340 PRINT " n " ; : RETURN
1350 PRINT " b " ; : RETURN
1360 PRINT " r " ; : RETURN
1370 PRINT " q " ; : RETURN
1380 RETURN
1390 PRINT "P"; : RETURN
1400 PRINT "N"; : RETURN
1410 PRINT "B"; : RETURN
1420 PRINT "R" : RETURN
1430 PRINT "Q"; : RETURN
1440 PRINT "p"; : RETURN
1450 PRINT "n"; : RETURN
1460 PRINT "b"; : RETURN
1470 PRINT "r"; : RETURN
1480 PRINT "q"; : RETURN
1490 'INPUT ROUTINE
1500 PRINT , "cannot " ; : PRINT , "castle " ; : FOR J = 1 TO 1500 : NEXT : GOTO 1520
1510 PRINT , " entry " ; : PRINT , " error " ; : FOR J = 1 TO 1500 : NEXT
1520 GOSUB 1750 : GOSUB 1780 : PRINT , " your " ; : PRINT , " move ";
1530 X$ = INKEY$ : IF X$ = "" THEN 1530
1540 PRINT , X$;
1550 SOUND 120,1
1560 X1$ = INKEY$ : IF X1$ = "" THEN 1560
1570 PRINT , X1$;
1580 SOUND 120,1
1590 X2$ = INKEY$ : IF X2$ = "" THEN 1590
1600 PRINT , X2$;
1610 SOUND 120,1
1620 X3$ = INKEY$ : IF X3$ = "" THEN 1620
1630 PRINT , X3$ ; : IN$ = X$ + X1$ + X2$ + X3$
1640 SOUND 150,1
1650 IF X$ >= "A" AND X$ <= "H" THEN 1730
1660 IF X$ = "K" THEN IF A(5,1) = 99 AND A(8,1) = 7 AND A(6,1) < 2 AND A(7,1) < 2 THEN A(5,1) = 1 : A(6,1) = 7 : A(7,1) = 99 : A(8,1) = 1 : GOTO 1760
1670 IF X$ = "Q" THEN IF A(5,1) = 99 AND A(1,1) = 7 AND A(4,1) < 2 AND A(3,1) < 2 THEN A(5,1) = 1 : A(4,1) = 7 : A(3,1) = 99 : A(1,1) = 1 : GOTO 1760
1680 IF X$ = "K" THEN IF A(4,1) = 99 AND A(1,1) = 7 AND A(3,1) < 2 AND A(2,1) < 2 THEN A(4,1) = 1 : A(3,1) = 7 : A(2,1) = 99 : A(1,1) = 1 : GOTO 1760
1690 IF X$ = "Q" THEN IF A(4,1) = 99 AND A(8,1) = 7 AND A(5,1) < 2 AND A(6,1) < 2 THEN A(4,1) = 1 : A(5,1) = 7 : A(6,1) = 99 : A(8,1) = 1 : GOTO 1760
1700 'DECODE INPUT
1710 IF X$ = "I" THEN GOSUB 1940 : GOSUB 1130 : GOSUB 1220 : GOTO 1520
1720 IF X$ = "P" THEN RUN ELSE 1510
1730 IF LEN(IN$) = 4 THEN X = ASC(X$) - 64 : Y = ASC(MID$(IN$ , 2 , 1)) - 48 : A = ASC(MID$(IN$ , 3 , 1)) - 64 : B = ASC(MID$(IN$ , 4 , 1)) - 48 ELSE 1510
1740 IF Y < 1 OR Y > 8 OR A < 1 OR A > 8 OR B < 1 OR B > 8 THEN 1510 ELSE IF A(X,Y) < 2 OR A(A , B) > 1 THEN 1510 ELSE GOSUB 1750 : RETURN
1750 PRINT , " " ; : PRINT , " " ; : RETURN
1760 PRINT , "CASTLE " ; : PRINT , X$ ; "-SIDE " ; : GOSUB 1750 : GOSUB 1220 : RETURN
1770 'BLANK MESSAGE AREA
1780 FOR J = 217 TO 345 STEP 32 : PRINT , " " ; : NEXT : RETURN
1790 'PROMOTE PLAYER PAWN
1800 GOSUB 1780 : PRINT , " what " ; : PRINT , " piece " ; : PRINT , " PNBRQ " ; :
1810 IN$ = INKEY$ : IF IN$ = "" THEN 1810
1820 IF IN$ <> "P" AND IN$ <> "N" AND IN$ <> "B" AND IN$ <> "R" AND IN$ <> "Q" THEN PRINT , " " ; : GOTO 1810
1830 PRINT , IN$ ;
1840 IF IN$ = "P" THEN A(A,B) = 2 : RETURN
1850 IF IN$ = "N" THEN A(A,B) = 4 : RETURN
1860 IF IN$ = "B" THEN A(A,B) = 5 : RETURN
1870 IF IN$ = "R" THEN A(A,B) = 7 : RETURN
1880 IF IN$ = "Q" THEN A(A,B) = 9 : RETURN ELSE 1810
1890 'END OF GAME
1900 GOSUB 1780 : PRINT , " " ; : PRINT , " YOU " ; : PRINT , " WIN! " ;
1910 POKE65494,0
1920 GOTO 1920
1930 'INSTRUCTIONS
1940 CLS
1950 PRINT" * INSTUCTIONS *"
1960 PRINT"ENTER KKKK TO CASTLE KING SIDE"
1970 PRINT" QQQQ TO CASTLE QUEEN SIDE"
1980 PRINT" IIII TO GET INSTUCTIONS"
1990 PRINT" PPPP TO START NEW GAME"
2000 PRINT
2010 PRINT" TO PROMOTE TO P, N, B, R OR Q"
2020 PRINT" ENTER LETTER WHEN PROMPTED"
2030 PRINT : PRINT" TO MOVE, CAPTURE OR CAPTURE"
2040 PRINT" EN PASSANT, SPECIFY FROM/TO"
2050 PRINT" (E.G. 'B1C3')"
2060 PRINT : PRINT" LEVELS OF PLAY ARE 1 THRU 7"
2070 PRINT
2080 PRINT" (HIT ANY KEY)";
2090 IN$ = INKEY$ : IF IN$ = "" THEN 2090
2100 CLS : RETURN

Post Reply