Generate Chess960 starting position: Difference between revisions
(new draft) |
(not imposing the use of unicode characters) |
||
Line 10: | Line 10: | ||
With those constraints there are 960 possible starting positions, thus the name of the variant. |
With those constraints there are 960 possible starting positions, thus the name of the variant. |
||
The purpose of this task is to write a program that randomly generates a Chess960 initial position. You will show the result as the first rank displayed with [[wp:Chess symbols in Unicode|Chess symbols in Unicode]]. |
The purpose of this task is to write a program that randomly generates a Chess960 initial position. You will show the result as the first rank displayed with [[wp:Chess symbols in Unicode|Chess symbols in Unicode]] or with the letters '''K'''ing '''Q'''ueen '''R'''ook '''B'''ishop k'''N'''ight. |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
Line 25: | Line 25: | ||
@squares[$king, $queen, @rooks, @bishops, @knights] = |
@squares[$king, $queen, @rooks, @bishops, @knights] = |
||
< |
< K Q R R B B N N >; |
||
say @squares;</lang> |
say @squares;</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>Q N B R K B R N</pre> |
Revision as of 07:26, 1 May 2014
Chess960 is a variant of chess created by world champion Bobby Fisher. Unlike other variant of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
- as in the standard chess game, all height pawns must be placed on the second rank.
- pieces must stand on the first rank as in the standard game, in random column order but with the two following constraints:
- the bishops must be placed on opposite color squares ;
- the King must be between two rooks ;
With those constraints there are 960 possible starting positions, thus the name of the variant.
The purpose of this task is to write a program that randomly generates a Chess960 initial position. You will show the result as the first rank displayed with Chess symbols in Unicode or with the letters King Queen Rook Bishop kNight.
Perl 6
<lang perl6>my Set $squares = set ^8;
$squares = $squares (-) set my @knights = $squares.pick(2); $squares = $squares (-) set my @bishops = $squares.list.grep(* % 2).pick, $squares.list.grep(* %% 2).pick; $squares = $squares (-) set my $queen = $squares.pick; my ($king, @rooks) = $squares.list[1, 0, 2];
my @squares;
@squares[$king, $queen, @rooks, @bishops, @knights] =
< K Q R R B B N N >;
say @squares;</lang>
- Output:
Q N B R K B R N