Generate Chess960 starting position: Difference between revisions

Added XPL0 example.
m (→‎{{header|Phix}}: added syntax colouring, marked p2js compatible)
(Added XPL0 example.)
Line 2,661:
♖ ♔ ♗ ♕ ♘ ♗ ♘ ♖
♖ ♔ ♘ ♗ ♕ ♘ ♗ ♖
</pre>
 
=={{header|XPL0}}==
<lang XPL0>char Col;
 
func ColNum(Start, Piece); \Return column number of Piece
int Start, Piece, I;
[for I:= Start to 7 do
if Col(I) = Piece then return I;
return -1;
];
 
proc Shuffle; \Randomly rearrange pieces in columns
int I, J, T;
[for I:= 8-1 downto 1 do
[J:= Ran(I); \range [0..I-1] (Sattolo cycle)
T:= Col(I); Col(I):= Col(J); Col(J):= T;
];
];
 
int N, B1, B2, BOK, R1, R2, K, KOK;
[for N:= 1 to 5 do
[Col:= "RNBQKBNR ";
repeat Shuffle;
B1:= ColNum(0, ^B);
B2:= ColNum(B1+1, ^B);
BOK:= ((B1 xor B2) and 1) # 0;
R1:= ColNum(0, ^R);
R2:= ColNum(R1+1, ^R);
K:= ColNum(0, ^K);
KOK:= R1<K and K<R2;
until BOK and KOK;
Text(0, Col); CrLf(0);
];
]</lang>
 
{{out}}
<pre>
BNRBQKRN
RBKNNQBR
BQRBNKNR
NRBBQKNR
RNKNBQRB
</pre>
 
772

edits