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