Class: Chess::Pieces::Piece

Inherits:
Object
  • Object
show all
Defined in:
lib/chess/pieces/piece.rb

Overview

Piece

Direct Known Subclasses

Bishop, King, Knight, Pawn, Queen, Rook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Piece

Returns a new instance of Piece.



12
13
14
15
16
# File 'lib/chess/pieces/piece.rb', line 12

def initialize(color)
  @color = color
  @pos = []
  @valid_moves = []
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



9
10
11
# File 'lib/chess/pieces/piece.rb', line 9

def color
  @color
end

#posObject

Returns the value of attribute pos.



10
11
12
# File 'lib/chess/pieces/piece.rb', line 10

def pos
  @pos
end

#valid_movesObject

Returns the value of attribute valid_moves.



10
11
12
# File 'lib/chess/pieces/piece.rb', line 10

def valid_moves
  @valid_moves
end

Instance Method Details

#black?Boolean

checks if piece color is black

Returns:

  • (Boolean)


19
20
21
# File 'lib/chess/pieces/piece.rb', line 19

def black?
  @color == 'black'
end

#white?Boolean

checks if piece color is white

Returns:

  • (Boolean)


24
25
26
# File 'lib/chess/pieces/piece.rb', line 24

def white?
  @color == 'white'
end