Sha256: 3627225c82c43b4dc5131374e0325b8bb89bde8a6225ee77c26f085a18d89755

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

# frozen-string-literal: true

module Bioshogi
  module InputAdapter
    concern :Ki2PlaceMethods do
      def place
        absolute_place || same_place
      end

      def hard_validations
        super

        # 初手に同歩の場合
        if same? && !same_place
          errors_add BeforePlaceNotFound, "同に対する座標が不明です"
        end

        # 記事などで改ページしたとき明示的に "同歩" ではなく "同2四歩" と書く場合もあるとのことで同の座標が2四ではない場合
        if same? && same_place && absolute_place
          if same_place != absolute_place
            errors_add SamePlaceDifferent, "同は#{same_place}を意味しますが明示的に指定した移動先は#{absolute_place}です"
          end
        end

        # 結局座標がわからない場合
        unless place
          errors_add SyntaxDefact, "移動先の座標が不明です"
        end
      end

      private

      def absolute_place
        if v = input[:kif_place]
          Place.fetch(v)
        end
      end

      def same_place
        if hand_log = player.container.hand_logs.last
          hand_log.soldier.place
        end
      end

      def same?
        !!input[:ki2_same]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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