Class: Chess::King
- Inherits:
-
BoardgameEngine::Piece
- Object
- BoardgameEngine::Piece
- Chess::King
- Defined in:
- lib/boardgame_engine/chess.rb
Instance Attribute Summary
Attributes inherited from BoardgameEngine::Piece
Instance Method Summary collapse
-
#initialize(owner) ⇒ King
constructor
A new instance of King.
- #valid_move?(start_location, end_location, board) ⇒ Boolean
Methods inherited from BoardgameEngine::Piece
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
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 |