Generate Chess960 starting position: Difference between revisions
Generate Chess960 starting position (view source)
Revision as of 09:56, 4 December 2023
, 6 months agoadd Unix shell
(relaxing tax requirements (making it less English-centric)) |
(add Unix shell) |
||
Line 2,849:
♘♕♗♖♔♖♘♗
♘♘♖♔♗♗♕♖</pre>
=={{header|UNIX Shell}}==
{{trans|raku}}
{{works with|bash}}
<syntaxhighlight lang=bash>declare -a pieces=(♖ ♖ ♖ ♕ ♗ ♗ ♘ ♘)
declare -i pick
declare -ai picking_history
declare attempt
until [[ "$attempt" =~ ♗(..)*♗ ]]
do
attempt=''
picking_history=()
for _ in {1..8}
do
while ((pick=RANDOM%8, picking_history[pick]++))
do :
done
attempt+="${pieces[pick]}"
done
done
declare -i index
for i in {0..7}
do
if [[ "${attempt:i:1}" = ♖ ]] && ((index++))
then echo "${attempt:0:i}♔${attempt:i+1}"; break;
fi
done</syntaxhighlight>
=={{header|Wren}}==
|