lib/chess/board.rb
# Returns true if the move is valid (given a from and to location)
# => The starting position of the move is an actual piece (not empty square)
# => The move is valid for that piece type
# => No pieces on path between starting and new location
# => Piece is moving to a location that is empty or occupied by the enemy
Returns true if the move is valid (given a from and to location)
> The starting position of the move is an actual piece (not empty square)
> The move is valid for that piece type
> No pieces on path between starting and new location
> Piece is moving to a location that is empty or occupied by the enemy
Returns true if the move is valid ( given a from and to location ) > The starting position of the move is an actual piece ( not empty square ) > The move is valid for that piece type > No pieces on path between starting and new location > Piece is moving to a location that is empty or occupied by the enemy
def valid_move?(from_row, from_column, to_row, to_column)
      piece = @state[from_row][from_column]
      return false if piece == nil
      new_location = [to_row, to_column]
      return false unless piece.moves.include? new_location
      return pawn_valid_move?(piece, new_location, to_column, from_column) if
             piece.class == Pawn
      return false unless empty_location?([to_row, to_column]) || 
                          enemy_piece_at_location?(piece.color, new_location)
      unless piece.class == Knight || piece.class == King
        return no_pieces_in_between?(from_row, from_column, to_row, to_column)
      end
      true
    end
def valid_move? ( from_row , from_column , to_row , to_column ) piece = @state [ from_row ] [ from_column ] return false if piece == nil new_location = [ to_row , to_column ] return false unless piece . moves . include? new_location return pawn_valid_move? ( piece , new_location , to_column , from_column ) if piece . class == Pawn return false unless empty_location? ( [ to_row , to_column ] ) || enemy_piece_at_location? ( piece . color , new_location ) unless piece . class == Knight || piece . class == King return no_pieces_in_between? ( from_row , from_column , to_row , to_column ) end true end
Returns true if the move is valid (given a from and to location)
> The starting position of the move is an actual piece (not empty square)
> The move is valid for that piece type
> No pieces on path between starting and new location
> Piece is moving to a location that is empty or occupied by the enemy
Returns true if the move is valid ( given a from and to location ) > The starting position of the move is an actual piece ( not empty square ) > The move is valid for that piece type > No pieces on path between starting and new location > Piece is moving to a location that is empty or occupied by the enemy
from_row
<not_specific>
from_column
<not_specific>
to_row
<not_specific>
to_column
<not_specific>