Jump to content

Generate random chess position: Difference between revisions

m
→‎{{header|REXX}}: changed REXX program to allow generation of an unbalanced total number of pieces (by color).
m (→‎{{header|REXX}}: alternated literal quotes.)
m (→‎{{header|REXX}}: changed REXX program to allow generation of an unbalanced total number of pieces (by color).)
Line 102:
 
=={{header|REXX}}==
This REXX version normally generates balanced number of pieces   (both sides have an equal number of total pieces,
<br>but not necessarily of the same kind).
 
If the number of chessboard specified is negative, then the number of pieces for each color will randomized.
It also allows any number of chessboards to be displayed.
 
ItThis version also allows any number of chessboards to be displayed.
<lang rexx>/*REXX pgm generates a chess position (rand pieces & positions) in FEN format.*/
parse arg seed CBs . /*obtain optional arguments from the CL*/
Line 111 ⟶ 113:
if CBs =='' | CBs =',' then CBs=1 /*CBs: number of generated chessboards*/
/* [↓] maybe display any # of boards. */
do boards=1 for abs(CBs ) /* [↓] maybe display separator & title*/
if abs(CBs)\==1 then do; say; say center(' board' boards" ", 79, '▒'); end
@.=. /*initialize the chessboard to be empty*/
do p=1 for random(2,32) /*generate a random number of chessmen.*/
Line 132 ⟶ 134:
return
/*────────────────────────────────────────────────────────────────────────────*/
piece: parse arg x; if p//2 then upper x; arg ux /*use white if odd P.*/
if CBs<0 & p>2 then if random(1) then upper x /*CBs>0? Use balanced*/
 
do #=0 by 0; r=random(1, 8); f=random(1, 8) /*random rank & file.*/
if @.r.f\==. then iterate /*position occupied? */
Cookies help us deliver our services. By using our services, you agree to our use of cookies.