Sha256: 73f06a0c9cf13a768d75298b753e1a77d5532006119bee4998bdc55db94fb38c

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

# frozen-string-literal: true

module Bioshogi
  module InputAdapter
    class KifAdapter < AbstractAdapter
      include Ki2PlaceMethods
      include LocationValidation
      include OriginSoldierMethods
      include SharedValidation

      def piece
        piece_with_promoted[:piece]
      end

      def promoted
        piece_with_promoted[:promoted] || promote_trigger
      end

      def place_from
        Place.fetch(input[:kif_place_from].slice(/\d+/))
      end

      def promote_trigger
        !!input[:ki2_promote_trigger]
      end

      def drop_trigger
        force_drop_trigger
      end

      def hard_validations
        super

        if promoted && force_drop_trigger
          errors_add PromotedPiecePutOnError, "成った状態の駒は打てません"
        end

        # "1三金不成" と入力した場合。"1三金" の解釈になるのでスルーしてもよいが厳しくチェックする
        if have_promote_or_not_promote_force_instruction? && !piece.promotable?
          errors_add NoPromotablePiece, "#{piece}は裏がないので「成・不成・生」は指定できません"
        end
      end

      private

      def force_drop_trigger
        !!input[:kif_drop_trigger]
      end

      def location_key
        :ki2_location
      end

      # 成や不成の指示があるか?
      def have_promote_or_not_promote_force_instruction?
        input[:ki2_as_it_is] || input[:ki2_promote_trigger]
      end

      def piece_with_promoted
        @piece_with_promoted ||= Soldier.piece_and_promoted(input[:kif_piece])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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