Class: Bishop

Inherits:
Piece show all
Defined in:
lib/bangkok/piece.rb

Instance Attribute Summary

Attributes inherited from Piece

#color, #piece, #square

Instance Method Summary collapse

Methods inherited from Piece

#clear_to?, create, #move_off_board, #move_to, #to_s

Constructor Details

#initialize(board, listener, color, square) ⇒ Bishop

Returns a new instance of Bishop.



120
121
122
# File 'lib/bangkok/piece.rb', line 120

def initialize(board, listener, color, square)
  super(board, listener, color, :B, square)
end

Instance Method Details

#could_perform_move(move) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bangkok/piece.rb', line 124

def could_perform_move(move)
  return false unless super

  # Quick square color check
  square = move.square
  return false unless square.color == @square.color

  d_file = (@square.file - square.file).abs
  d_rank = (@square.rank - square.rank).abs
  return false unless d_file == d_rank # diagonal
  return clear_to?(square)
end