Class: Knight

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) ⇒ Knight

Returns a new instance of Knight.



139
140
141
# File 'lib/bangkok/piece.rb', line 139

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

Instance Method Details

#could_perform_move(move) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/bangkok/piece.rb', line 143

def could_perform_move(move)
  return false unless super

  square = move.square
  d_file = (@square.file - square.file).abs
  d_rank = (@square.rank - square.rank).abs
  return (d_file == 2 && d_rank == 1) || (d_file == 1 && d_rank == 2)
end