Talk:Generate Chess960 starting position: Difference between revisions
Content added Content deleted
(→random starting position: ruby code was biased too) |
(→random starting position: added the REXX source that produced the histogram.) |
||
Line 79: | Line 79: | ||
file 8=270847 ============================================================ |
file 8=270847 ============================================================ |
||
</pre> |
</pre> |
||
The REXX program to produce the histograhs (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 /*════════════════════════════════════════════════════*/ |
|||
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 /*bump rook (r1) position counter*/ |
|||
rooks.r2=rooks.r2+1 /* " " (r2) " " */ |
|||
end /*t ══════════════════════════════════════════════════════════════*/ |
|||
mx=0; do j=1 for 8; mx=max(mx,rooks.j); end /*find max histo value*/ |
|||
do k=1 for 8 /*display the eight files numbers*/ |
|||
say 'file' k"="rooks.k copies('=', 60 * rooks.k % mx) |
|||
end /*k*/ /* [↑] display a nice histogram.*/ |
|||
/*stick a fork in it, we're done.*/</lang> |
|||
Many thanks to (user) Steenslag for pointing out the un-randomness of the rook placement in the REXX code. |
Many thanks to (user) Steenslag for pointing out the un-randomness of the rook placement in the REXX code. |
||