Class: Rubykon::GTPCoordinateConverter
- Inherits:
-
Object
- Object
- Rubykon::GTPCoordinateConverter
- Defined in:
- lib/rubykon/gtp_coordinate_converter.rb
Constant Summary collapse
- X_CHARS =
('A'..'Z').reject { |c| c == 'I'.freeze }
Instance Method Summary collapse
- #from(string) ⇒ Object
-
#initialize(board) ⇒ GTPCoordinateConverter
constructor
A new instance of GTPCoordinateConverter.
- #to(index) ⇒ Object
Constructor Details
#initialize(board) ⇒ GTPCoordinateConverter
Returns a new instance of GTPCoordinateConverter.
6 7 8 |
# File 'lib/rubykon/gtp_coordinate_converter.rb', line 6 def initialize(board) @board = board end |
Instance Method Details
#from(string) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/rubykon/gtp_coordinate_converter.rb', line 10 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 |
#to(index) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/rubykon/gtp_coordinate_converter.rb', line 18 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 |