Class: Chess::Pawn
- Inherits:
-
BoardgameEngine::Piece
- Object
- BoardgameEngine::Piece
- Chess::Pawn
- Defined in:
- lib/boardgame_engine/chess.rb
Instance Attribute Summary
Attributes inherited from BoardgameEngine::Piece
Instance Method Summary collapse
-
#initialize(owner, front) ⇒ Pawn
constructor
A new instance of Pawn.
-
#valid_move?(start_location, end_location, board) ⇒ Boolean
Check whether the intended destination is a valid destination.
Methods inherited from BoardgameEngine::Piece
Constructor Details
#initialize(owner, front) ⇒ Pawn
Returns a new instance of Pawn.
84 85 86 87 88 |
# File 'lib/boardgame_engine/chess.rb', line 84 def initialize(owner, front) super(owner, 'p') @first_move = true @front = front end |
Instance Method Details
#valid_move?(start_location, end_location, board) ⇒ Boolean
Check whether the intended destination is a valid destination
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/boardgame_engine/chess.rb', line 97 def valid_move?(start_location, end_location, board) row, col = start_location end_row, end_col = end_location # Checks if moving 1 (or 2 if its the first move) cell forward return false unless valid_forward_move?(row, end_row) if col == end_col valid_line_move?(end_row, end_col, board) elsif (col - end_col).abs == 1 && (row + @front == end_row) valid_diag_move?(end_row, end_col, board) else false end end |