Find Chess960 starting position identifier: Difference between revisions
Find Chess960 starting position identifier (view source)
Revision as of 21:03, 23 July 2022
, 1 year ago→{{header|Ruby}}: Fix algorithm, add Unicode piece output and troublesome examples.
(→{{header|Raku}}: Add troublesome examples.) |
(→{{header|Ruby}}: Fix algorithm, add Unicode piece output and troublesome examples.) |
||
Line 806:
=={{header|Ruby}}==
<lang ruby>CHESS_PIECES = %w<♖♘♗♕♔ ♜♞♝♛♚>
start_str = pos.tr(
#1 knights score
s = start_str.delete("QB")
n = [0,1,2,3,4].combination(2).to_a.index( [s.index("N"), s.rindex("N")] )
#2 queen score
q = start_str.delete("
#3 bishops
bs = start_str.index("B"), start_str.rindex("B")
Line 821 ⟶ 822:
end
%w<QNRBBNKR RNBQKBNR RQNBBKRN RNQBBKRN>.each_with_index do |array, i|
pieces = array.tr("RNBQK", CHESS_PIECES[i%2])
puts "#{pieces} (#{array}): #{chess960_to_spid array}"
end
</lang>
{{out}}
<pre>♕♘♖♗♗♘♔♖ (QNRBBNKR): 105
♜♞♝♛♚♝♞♜ (RNBQKBNR): 518
♖♕♘♗♗♔♖♘ (RQNBBKRN): 601
♜♞♛♝♝♚♜♞ (RNQBBKRN): 617
</pre>
=={{header|Wren}}==
{{libheader|Wren-trait}}
|