Sha256: 6ec5abdeece6a70ae20bc2f2af68eb181672242caabe6760a01fb49f43ec5ac0

Contents?: true

Size: 785 Bytes

Versions: 9

Compression:

Stored size: 785 Bytes

Contents

# frozen-string-literal: true

module Bioshogi
  module BoardParser
    class SfenBoardParser < Base
      def self.accept?(source)
        source && source.include?("/")
      end

      def parse
        @source.split("/").each.with_index do |row, y|
          x = 0
          row.scan(/(\+?)(.)/) do |promoted, ch|
            place = Place.fetch([x, y])
            if ch.match?(/\d+/)
              x += ch.to_i
            else
              location = Location.fetch_by_sfen_char(ch)
              promoted = (promoted == "+")
              piece = Piece.fetch_by_sfen_char(ch)
              soldiers << Soldier.create(piece: piece, place: place, location: location, promoted: promoted)
              x += 1
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bioshogi-0.0.15 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.14 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.10 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.9 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.8 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.7 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.5 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.4 lib/bioshogi/board_parser/sfen_board_parser.rb
bioshogi-0.0.3 lib/bioshogi/board_parser/sfen_board_parser.rb