Sha256: 8d9117e26b8781fb00644d7fdb0d2ae56c1ef655a92b0f72598871b9747675d4

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# frozen-string-literal: true

module Bioshogi
  module Hand
    class Drop
      include Shared

      def initialize(*)
        super
        if soldier.promoted
          raise MustNotHappen, "成駒を打った"
        end
      end

      def execute(container)
        player = container.player_at(soldier.location)
        player.piece_box.pick_out(soldier.piece)
        container.board.place_on(soldier)
      end

      def revert(container)
        container.board.safe_delete_on(soldier.place)
        player = container.player_at(soldier.location)
        player.piece_box.add(soldier.piece.key => 1)
      end

      def soldier_for_counts
        soldier
      end

      def to_kif(options = {})
        options = {
          with_location: true,
        }.merge(options)

        if options[:with_location]
          s = soldier.name(options)
        else
          s = soldier.name_without_location(options)
        end
        s + "打"
      end

      def to_csa(options = {})
        [
          soldier.location.csa_sign,
          "00",
          soldier.place.hankaku_number,
          soldier.to_csa,
        ].join
      end

      def to_sfen(options = {})
        [
          soldier.piece.to_sfen,
          "*",
          soldier.place.to_sfen,
        ].join
      end

      def type
        :t_drop
      end

      def to_akf(options = {})
        {
          :_location => soldier.location.key,
          :type      => type,
          :to        => soldier.place.to_human_h,
          :piece     => soldier.piece.key,
          :_sfen     => to_sfen,
          :_kif      => to_kif,
          :_csa      => to_csa,
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bioshogi-0.0.15 lib/bioshogi/hand/drop.rb