Jump to content

Generate random chess position: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments.
(→‎{{header|Perl 6}}: fix messed up indentation)
m (→‎{{header|REXX}}: added/changed whitespace and comments.)
Line 107:
<br>but not necessarily of the same kind).
 
If the number of chessboard specified is negative, then the number of pieces for each colorside will randomizedbe randonm.
 
This version also allows any number of chessboards to be displayed.
<lang rexx>/*REXX pgm generatesgens a chess position (randrandom pieces & positions) in a FEN format.*/
parse arg seed CBs . /*obtain optional arguments from the CL*/
if seed\=='' & seed\="," then call random ,,seed /*RANDOM repeatability? */
Line 122:
else call piece substr('bnpqr', random(1, 5), 1)
end /*p*/ /* [↑] place a piece. */
call cb /*display the chessboardChessBoard and its FEN.*/
end /*boards*/ /* [↑] CB ≡ ─ ─ */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
Line 134:
say /*a blank line (after the board).*/
say 'FEN='fen "w - - 0 1" /*show Forsyth-Edwards Notation.*/
return /* [↑] build/display chessboard.*/
return
/*────────────────────────────────────────────────────────────────────────────*/
piece: parse arg x; if p//2 then upper x; arg ux /*use white if odd P.*/
Line 145:
if ux=='K' then do rr=r-1 for 3 /*[↓] neighbor≡king?*/
do ff=f-1 for 3; z=@.rr.ff /*obtain the neighbor*/
upper z; if z=='K' then iterate # /*is a king?*/
end /*rr*/ /*[↑] neighbor≡king?*/
end /*ff*/
@.r.f=x; return /*place random piece.*/
end /*#*/ /*#: not incremented.*/</lang>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, &nbsp; so one is included here: &nbsp; ───► &nbsp; [[CHANGESTR.REX]]. <br><br>
'''output''' &nbsp; showing five chess positions (starting with a specific position by seeding the &nbsp; '''random''' &nbsp; BIF with &nbsp; '''96'''),
<br>specifying the arguments (for Regina REXX under Windows): &nbsp; 96 &nbsp; 5
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.