Sha256: f239d3219b16a868f85a69acbb574e8b223f408f3c2e65f44143616b4f8092ea

Contents?: true

Size: 523 Bytes

Versions: 2

Compression:

Stored size: 523 Bytes

Contents

module Rubykon
  class GTPCoordinateConverter

    X_CHARS = ('A'..'Z').reject { |c| c == 'I'.freeze }

    def initialize(board)
      @board = board
    end

    def from(string)
      x = string[0]
      y = string[1..-1]
      x_index = X_CHARS.index(x) + 1
      y_index = @board.size - y.to_i + 1
      @board.identifier_for(x_index, y_index)
    end

    def to(index)
      x, y = @board.x_y_from(index)
      x_char = X_CHARS[x - 1]
      y_index = @board.size - y + 1
      "#{x_char}#{y_index}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubykon-0.3.1 lib/rubykon/gtp_coordinate_converter.rb
rubykon-0.3.0 lib/rubykon/gtp_coordinate_converter.rb