Talk:Generate Chess960 starting position: Difference between revisions

m
→‎random starting position: updated the REXX program which produces the histograph/histogram.
m (→‎random starting position: updated the REXX program which produces the histograph/histogram.)
 
Line 79:
file 8=270847 ============================================================
</pre>
The REXX program to produce the histograhshistograms (shown above) is:
<lang rexx>/*REXX program generates a histogram of 100,000 rook placement positions*/
parse arg seed times . /*obtain optional args from C.L. */
if times=='' then times=100000 /*use default for TIMES? {100k} */
if seed\=='' then call random ,,seed /*if SEED specified, use the seed*/
rooks.=0 /*zero the rook position counters*/
 
do t=1 for times /*═════════════════════════════════════════════════*/
do t=1 for times /*════════════════════════════════════════════════════*/
r1=random(1 ,8); /*place the first rook on rank1.*/
r1m=r1-1; r1p=r1+1 /*used for faster comparisons. */
do forever; r2=random(1,8) /*place the second rook on rank1.*/
if r2==r1 then iterate /*position is the same as rook1. */
if r2==r1m then iterate /*it's immediately before rook1. */
if r2==r1p then iterate /* " " after " */
leave /*found a good 2nd rook placement*/
end /*forever*/
 
rooks.r1=rooks.r1+1 do until r2\==r1 & /*bumpr2\==r1-1 rook (r1)& position counter*/r2\==r1+1
rooks.r2=rooks.r2+1 r2=random(1,8) /* " " (r2) " /*find placement "for the 2nd rook*/
end /*forever*/
end /*t ══════════════════════════════════════════════════════════════*/
 
rooks.r1=rooks.r1+1 /*bump rook (r1) position counter*/
if rooks.r2==r1prooks.r2+1 then iterate /* " " (r2) " " after " " */
end /*t ════════════════════════════════════════════════════════════*/
 
mx=0; do j=1 for 8; mx=max(mx,rooks.j); end /*find max histo value*/