Sha256: d5daa0f5a2b60c312805d908b9e61be62c0a3ddb75fc8fdc819bfdee3b022a3a

Contents?: true

Size: 754 Bytes

Versions: 9

Compression:

Stored size: 754 Bytes

Contents

# frozen-string-literal: true

module Bioshogi
  module Parser
    class SfenParser < Base
      class << self
        def accept?(source)
          str = Source.wrap(source).to_s
          str.match?(/^(?:position|sfen)\b/i) || (str.lines.one? && Sfen.accept?(str))
        end
      end

      def parse
        @pi.sfen_info      = Sfen.parse(normalized_source)
        @pi.move_infos     = @pi.sfen_info.move_infos
        @pi.force_handicap = @pi.sfen_info.handicap?

        @pi.sfen_info.piece_counts.each do |location_key, counts|
          location = Location.fetch(location_key)
          name = location.call_name(@pi.sfen_info.handicap?)
          @pi.header["#{name}の持駒"] = Piece.h_to_s(counts)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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