Module: Shogi::Format::USI::Board
- Defined in:
- lib/shogi/format/usi/board.rb
Instance Method Summary collapse
- #to_usi ⇒ Object (also: #to_sfen)
- #usi_captured ⇒ Object (also: #sfen_captured)
Instance Method Details
#to_usi ⇒ Object Also known as: to_sfen
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shogi/format/usi/board.rb', line 5 def to_usi @table.map {|row| usi_row = "" space_count = 0 row.each do |cell| if cell == "" space_count += 1 else if space_count > 0 usi_row << space_count.to_s space_count = 0 end usi = Piece.const_get(cell[1..2]).new.usi if cell[0] == "-" usi_row << usi.downcase else usi_row << usi end end end if space_count > 0 usi_row << space_count.to_s space_count = 0 end usi_row }.join("/") << "\n" end |
#usi_captured ⇒ Object Also known as: sfen_captured
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shogi/format/usi/board.rb', line 34 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 |