Sha256: 319ad4c6c99455a06139d51b2f08380e7daa837868d0a83ec72df0ceb91a5237

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

# frozen-string-literal: true

module Bioshogi
  module InputAdapter
    class CsaAdapter < AbstractAdapter
      include LocationValidation
      include OriginSoldierMethods
      include SharedValidation

      def piece
        piece_and_promoted[:piece]
      end

      def promoted
        piece_and_promoted[:promoted]
      end

      def place_from
        unless drop_trigger
          Place.fetch(input[:csa_from])
        end
      end

      def place
        Place.fetch(input[:csa_to])
      end

      # 移動元の駒との差分で「成」を判断する
      def promote_trigger
        promoted && !board.fetch(place_from).promoted
      end

      def drop_trigger
        input[:csa_from] == "00"
      end

      def hard_validations
        super

        if drop_trigger && !player.piece_box.exist?(piece)
          errors_add HoldPieceNotFound, "#{player.call_name}は#{piece}を#{place}に打とうとしましたが#{piece}を持っていません"
        end
      end

      private

      def location_key
        :csa_sign
      end

      def piece_and_promoted
        @piece_and_promoted ||= Soldier.piece_and_promoted(input[:csa_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/csa_adapter.rb
bioshogi-0.0.14 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.10 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.9 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.8 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.7 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.5 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.4 lib/bioshogi/input_adapter/csa_adapter.rb
bioshogi-0.0.3 lib/bioshogi/input_adapter/csa_adapter.rb