Generate random chess position: Difference between revisions

m
→‎{{header|ZX Spectrum Basic}}: a few typos and comments
m (→‎{{header|ZX Spectrum Basic}}: a few typos and comments)
Line 2,940:
 
<syntaxhighlight lang="zxbasic">
1 DEF FN r(v)=INT (RND*v)+1: REM we'll be using this a lot here for setup, although in real chess it should barely be used at all...
 
5010 GO TOSUB 95009400: REM modularity is pretty much vital in making Sinclair BASIC legible
10 GO SUB 9400
20 GO SUB 9100
30 GO SUB 9200
40 GO SUB 8800
50 GO TO 9500
50 GO TO 9500: REM modularity is pretty much vital in making Sinclair BASIC legible
 
8799 REM Material assignment
8800 LET b=FN r(16)-1: REM give black and white a random number of additional pieces each
8810 LET w=FN r(16)-1
8820 FOR x=1 TO b
Line 2,967:
8960 LET r=FN r(8)
8970 LET f=FN r(8)
8980 IF d$(r,f)<>" " THEN GO TO 88408950
8990 IF w$(k)="P" AND (r=1 OR r=8) THEN GO TO 89408950
9000 LET d$(r,f)=w$(k)
9010 IF k=p THEN LET w$=w$(1 TO k-1): GO TO 9030
Line 3,016:
9510 PRINT CHR$ (105-x);: REM rank letter
9520 FOR y=1 TO 8
9530 PRINT INVERSE (((x+y)/2)<>INT ((x+y)/2));d$(x,y);: REM evaluates to 1, a black square, if rank number + file number, read from the top left, is odd; the bottom right square is 8 + 8 = 16 = even = white, conforming to "white to the right" standards
9540 LET f$=f$+d$(x,y): REM building the FEN
9550 NEXT y
77

edits