Class: Knight
Instance Attribute Summary
Attributes inherited from Piece
Instance Method Summary collapse
- #could_perform_move(move) ⇒ Object
-
#initialize(board, listener, color, square) ⇒ Knight
constructor
A new instance of Knight.
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 |