Class: Chess::Knight

Inherits:
BoardgameEngine::Piece show all
Defined in:
lib/boardgame_engine/chess.rb

Instance Attribute Summary

Attributes inherited from BoardgameEngine::Piece

#owner, #status

Instance Method Summary collapse

Methods inherited from BoardgameEngine::Piece

#kill, #to_s

Constructor Details

#initialize(owner) ⇒ Knight

Returns a new instance of Knight.



212
213
214
215
# File 'lib/boardgame_engine/chess.rb', line 212

def initialize(owner)
  # K was already taken by king, so I had to choose N
  super(owner, 'N')
end

Instance Method Details

#valid_move?(start_location, end_location, board) ⇒ Boolean

Returns:

  • (Boolean)


217
218
219
220
221
222
223
# File 'lib/boardgame_engine/chess.rb', line 217

def valid_move?(start_location, end_location, board)
  row, col = start_location
  end_row, end_col = end_location

  within_movement(row, col, end_row, end_col) \
  && not_occupied(end_row, end_col, board)
end