Sha256: 9dfed3d379fa2307ae2dc02e5422a97933d98f726911035982164a9f357c3ef7

Contents?: true

Size: 930 Bytes

Versions: 9

Compression:

Stored size: 930 Bytes

Contents

# frozen-string-literal: true

module Bioshogi
  class Simulator
    def self.run(...)
      new(...).tap(&:run)
    end

    attr_accessor :container
    attr_accessor :attributes
    attr_accessor :snapshots

    def initialize(attributes)
      @attributes = attributes
      @container = Container::Basic.new
      @snapshots = []
    end

    def run(&block)
      container.board.placement_from_any(attributes[:board])

      if v = attributes[:pieces]
        Location.each do |e|
          if str = v[e.key]
            container.player_at(e).pieces_add(str)
          end
        end
      end

      snapshots << container.deep_dup
      if block
        yield snapshots.last
      end
      InputParser.scan(attributes[:execute]).each do |str|
        container.execute(str)
        snapshots << container.deep_dup
        if block
          yield snapshots.last
        end
      end
      snapshots
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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