Generate Chess960 starting position: Difference between revisions

Added PowerShell
m (added whitespace before the TOC (table of contents), added other whitespace to the task's preamble.)
(Added PowerShell)
Line 843:
 
(bye)</lang>
=={{header|PowerShell}}==
{{works with|powershell|2}}
<lang PowerShell>
function Get-RandomChess960Start
{
$Starts = @()
 
ForEach ( $Q in 0..3 ) {
ForEach ( $N1 in 0..4 ) {
ForEach ( $N2 in ($N1+1)..5 ) {
ForEach ( $B1 in 0..3 ) {
ForEach ( $B2 in 0..3 ) {
$BB = $B1 * 2 + ( $B1 -lt $B2 )
$BW = $B2 * 2
$Start = [System.Collections.ArrayList]( '♖', '♔', '♖' )
$Start.Insert( $Q , '♕' )
$Start.Insert( $N1, '♘' )
$Start.Insert( $N2, '♘' )
$Start.Insert( $BB, '♗' )
$Start.Insert( $BW, '♗' )
$Starts += ,$Start
}}}}}
 
$Index = Get-Random 960
$StartString = $Starts[$Index] -join ''
return $StartString
}
 
Get-RandomChess960Start
Get-RandomChess960Start
Get-RandomChess960Start
Get-RandomChess960Start
</lang>
{{out}}
<pre>
♘♕♖♔♖♘♗♗
♗♕♘♖♔♗♖♘
♖♗♔♕♗♖♘♘
♘♖♔♖♕♗♗♘
</pre>
 
=={{header|Python}}==