Class: Chess::King

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

Returns a new instance of King.



195
196
197
# File 'lib/boardgame_engine/chess.rb', line 195

def initialize(owner)
  super(owner, 'K')
end

Instance Method Details

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

Returns:

  • (Boolean)


199
200
201
202
203
204
205
206
207
208
# File 'lib/boardgame_engine/chess.rb', line 199

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

  return false unless (row - end_row).abs == 1 && (col - end_col).abs == 1

  board.clear_diag_path?(row, col, end_row, end_col, board) \
  || board.clear_horz_path?(row, col, end_row, end_col, board) \
  || board.clear_vert_path?(row, col, end_row, end_col, board)
end