Class: RubyGo::Stone

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-go/stone.rb

Direct Known Subclasses

NullStone

Constant Summary collapse

LETTERS =
('a'..'z').to_a

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x_coord, y_coord, color) ⇒ Stone

Returns a new instance of Stone.



7
8
9
10
11
# File 'lib/ruby-go/stone.rb', line 7

def initialize(x_coord, y_coord, color)
  @x_coord = x_coord
  @y_coord = y_coord
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



5
6
7
# File 'lib/ruby-go/stone.rb', line 5

def color
  @color
end

#x_coordObject (readonly)

Returns the value of attribute x_coord.



5
6
7
# File 'lib/ruby-go/stone.rb', line 5

def x_coord
  @x_coord
end

#y_coordObject (readonly)

Returns the value of attribute y_coord.



5
6
7
# File 'lib/ruby-go/stone.rb', line 5

def y_coord
  @y_coord
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
31
# File 'lib/ruby-go/stone.rb', line 27

def ==(other)
  other.is_a?(Stone) &&
    (color == other.color) &&
    (to_coord == other.to_coord)
end

#empty?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ruby-go/stone.rb', line 19

def empty?
  false
end

#to_coordObject



23
24
25
# File 'lib/ruby-go/stone.rb', line 23

def to_coord
  [x_coord, y_coord]
end

#to_sgfObject



13
14
15
16
17
# File 'lib/ruby-go/stone.rb', line 13

def to_sgf
  x = LETTERS[x_coord]
  y = LETTERS[y_coord]
  ";#{color.to_s[0].upcase}[#{x}#{y}]"
end