Class: Queen
Instance Attribute Summary
Attributes inherited from Piece
Instance Method Summary collapse
-
#could_perform_move(move) ⇒ Object
There can be more than one queen on the board, thus this method must be implemented.
-
#initialize(board, listener, color, square) ⇒ Queen
constructor
A new instance of Queen.
Methods inherited from Piece
#clear_to?, create, #move_off_board, #move_to, #to_s
Constructor Details
#initialize(board, listener, color, square) ⇒ Queen
Returns a new instance of Queen.
95 96 97 |
# File 'lib/bangkok/piece.rb', line 95 def initialize(board, listener, color, square) super(board, listener, color, :Q, square) end |
Instance Method Details
#could_perform_move(move) ⇒ Object
There can be more than one queen on the board, thus this method must be implemented.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/bangkok/piece.rb', line 101 def could_perform_move(move) return false unless super # Check for horizontal or vertical square = move.square if @square.file == square.file || @square.rank == square.rank return clear_to?(square) end # Check for diagonal 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 |