Sha256: e38544ebfd168d30fc0df9350d5462408c0a55add4199f43f2291914a951fbb6

Contents?: true

Size: 974 Bytes

Versions: 8

Compression:

Stored size: 974 Bytes

Contents

# frozen-string-literal: true
# http://www2.computer-shogi.org/protocol/record_v22.html

module Bioshogi
  module Board
    # P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
    # P2 * -HI *  *  *  *  * -KA *
    # P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
    # P4 *  *  *  *  *  *  *  *  *
    # P5 *  *  *  *  *  *  *  *  *
    # P6 *  *  *  *  *  *  *  *  *
    # P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
    # P8 * +KA *  *  *  *  * +HI *
    # P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
    class CsaFormatter
      def initialize(board)
        @board = board
      end

      def to_s
        Dimension::PlaceY.dimension.times.collect { |y|
          "P#{y.next}" + Dimension::PlaceX.dimension.times.collect { |x|
            place = Place.fetch([x, y])
            soldier_to_str(@board.surface[place])
          }.join + "\n"
        }.join
      end

      private

      def soldier_to_str(soldier)
        if soldier
          soldier.to_csa_bod
        else
          " * "
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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