RosettaCodeData/Task/Generate-Chess960-starting-position/Perl/generate-chess960-starting-position.pl
2015-02-20 09:02:09 -05:00

17 lines
300 B
Raku

sub rnd($) { int(rand(shift)) }
sub empties { grep !$_[0][$_], 0 .. 7 }
sub chess960 {
my @s = (undef) x 8;
@s[2*rnd(4), 1 + 2*rnd(4)] = qw/B B/;
for (qw/Q N N/) {
my @idx = empties \@s;
$s[$idx[rnd(@idx)]] = $_;
}
@s[empties \@s] = qw/R K R/;
@s
}
print "@{[chess960]}\n" for 0 .. 10;