Generate Chess960 starting position: Difference between revisions

→‎{{header|Commodore BASIC}}: Normalize input instead of erroring on >= 960; work without BEGIN/BEND
(→‎Header: BASIC: Consolidate BASIC entries)
(→‎{{header|Commodore BASIC}}: Normalize input instead of erroring on >= 960; work without BEGIN/BEND)
Line 81:
=={{header|BASIC}}==
==={{header|Commodore BASIC}}===
{{works with|Commodore BASIC|3.5,7.0}}
Uses structured DO/LOOP introduced in Commodore BASIC 3.5 on the C-16 and BEGINPlus/BEND4, fromalso Commodorefound in BASIC 7.0 on the C-128.
 
<lang basic>100 REM CHESS 960
Line 90:
140 IF SP<0 THEN SP=INT(RND(.)*960):PRINT SP
150 PRINT
160 IFDO SP<0 ORWHILE SP>959: THEN PRINT "NEED 0 <SP= SP < -960":GOTO 110LOOP
170 AR$="--------"
180 P=SP
Line 102:
260 FOR N1=0 TO 3
270 : FOR N2=N1+1 TO 4
280 : IF N=<>0 THEN BEGIN340
290 : P$="N":N=N1:GOSUB 420
300 : P$="N":N=N2-1:GOSUB 420
310 : N1=3
320 : N2=4
330 : BEND
340 : N=N-1
350 : NEXT N2
Line 114 ⟶ 113:
380 P$="K":N=0:GOSUB 420
390 P$="R":N=0:GOSUB 420
400 PRINT STR$(SP);":";AR$
410 END
420 FOR I=1 TO LEN(AR$)
430 : IF MID$(AR$,I,1)=<>"-" THEN BEGIN510
440 : IF N=<>0 THEN BEGIN480
450 : MID$(AR$,I,1)=P$
460 : I=LEN(AR$)
470 : GOTO BEND:ELSE BEGIN510
480 : N=N-1
490 : BEND
500 : BEND
510 NEXT I
520 RETURN</lang>
</lang>
 
{{Out}}
Line 133 ⟶ 131:
RUN
SPID (-1 FOR RANDOM):518
518:RNBQKBNR
 
READY.
RUN
SPID (-1 FOR RANDOM):- 9261
926:RKRQNBBN
 
RKRQNBBN
 
READY.</pre>
1,480

edits