Generate Chess960 starting position: Difference between revisions

Add Factor example
(Generate Chess960 starting position en FreeBASIC)
(Add Factor example)
Line 478:
RKRQBBNN
RNBNKQRB</pre>
 
=={{header|Factor}}==
Using the single-die method: https://en.wikipedia.org/wiki/Chess960_starting_position#Single_die_method
<lang factor>USING: io kernel math random sequences ;
IN: rosetta-code.chess960
 
: empty ( seq -- n ) 32 swap indices random ;
: next ( seq -- n ) [ 32 = ] find drop ;
: place ( seq elt n -- seq' ) rot [ set-nth ] keep ;
 
: white-bishop ( -- elt n ) CHAR: ♗ 4 random 2 * ;
: black-bishop ( -- elt n ) white-bishop 1 + ;
: queen ( seq -- seq elt n ) CHAR: ♕ over empty ;
: knight ( seq -- seq elt n ) CHAR: ♘ over empty ;
: rook ( seq -- seq elt n ) CHAR: ♖ over next ;
: king ( seq -- seq elt n ) CHAR: ♔ over next ;
 
: chess960 ( -- str )
" " clone
black-bishop place
white-bishop place
queen place
knight place
knight place
rook place
king place
rook place ;
 
 
: chess960-demo ( -- ) 5 [ chess960 print ] times ;
 
MAIN: chess960-demo</lang>
{{out}}
<pre>
♕♖♗♘♔♘♖♗
♕♗♖♘♗♘♔♖
♗♘♕♖♔♗♖♘
♘♖♗♕♔♗♘♖
♗♗♘♖♘♔♕♖
</pre>
 
=={{header|Forth}}==
1,808

edits