Class: ChessEngine::Piece

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

Direct Known Subclasses

Elephant, King, Knight, Pawn, Queen, Rook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Piece

Returns a new instance of Piece.



6
7
8
9
# File 'lib/chess_engine/piece.rb', line 6

def initialize(color)
  @color = color
  @moves_count = 0
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/chess_engine/piece.rb', line 3

def color
  @color
end

#moves_countObject

Returns the value of attribute moves_count.



4
5
6
# File 'lib/chess_engine/piece.rb', line 4

def moves_count
  @moves_count
end

#symbolObject (readonly)

Returns the value of attribute symbol.



3
4
5
# File 'lib/chess_engine/piece.rb', line 3

def symbol
  @symbol
end

Instance Method Details

#beats_diagonally?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/chess_engine/piece.rb', line 15

def beats_diagonally?
  elephant? || queen?
end

#beats_straight?Boolean

Returns:

  • (Boolean)


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

def beats_straight?
  rook? || queen?
end

#inspectObject



11
12
13
# File 'lib/chess_engine/piece.rb', line 11

def inspect
  "#{self.class}:#{@color}"
end