lib/shogi/format/usi/board.rb in shogi-ruby-0.0.9 vs lib/shogi/format/usi/board.rb in shogi-ruby-0.1.0

- old
+ new

@@ -27,9 +27,36 @@ space_count = 0 end usi_row }.join("/") << "\n" end + alias_method :to_sfen, :to_usi + + def usi_captured + ['+', '-'].map do |prefix| + caps = @captured + .select { |x| x[0] == prefix } + .map { |x| x[1..-1] } + .group_by { |x| x } + .map { |w, ws| [w, ws.length] } + .to_h + [Piece::HI, + Piece::KA, + Piece::KI, + Piece::GI, + Piece::KE, + Piece::KY, + Piece::FU].map do |type| + n = caps[type::CSA_NAME] || 0 + usi = type::USI_NAME + usi = usi.downcase if prefix == '-' + "#{n}#{usi}" if n > 0 + end.join + end.join.tap do |x| + return '-' if x == '' + end + end + alias_method :sfen_captured, :usi_captured end end end end