lib/chess/board.rb
# Given two points on the board that form a diagonal, returns true
# if there are no pieces in between and false otherwise 
Given two points on the board that form a diagonal, returns true
if there are no pieces in between and false otherwise
Given two points on the board that form a diagonal returns true if there are no pieces in between and false otherwise
def no_pieces_in_between_diagonal?(from_row, from_column, to_row, to_column)
      row = from_row
      column = from_column
      if to_row > from_row && to_column > from_column
        row += 1
        column += 1
        until row == to_row
          return false unless @state[row][column] == nil
          row += 1
          column += 1
        end
      elsif to_row > from_row && to_column <= from_column
        row += 1
        column -= 1
        until row == to_row
          return false unless @state[row][column] == nil
          row += 1
          column -= 1
        end
      elsif to_row <= from_row && to_column <= from_column
        row -= 1
        column -= 1
        until row == to_row
          return false unless @state[row][column] == nil
          row -= 1
          column -= 1
        end
      elsif to_row <= from_row && to_column > from_column
        row -= 1
        column += 1
        until row == to_row
          return false unless @state[row][column] == nil
          row -= 1
          column += 1
        end
      end
      true
    end
def no_pieces_in_between_diagonal? ( from_row , from_column , to_row , to_column ) row = from_row column = from_column if to_row > from_row && to_column > from_column row += 1 column += 1 until row == to_row return false unless @state [ row ] [ column ] == nil row += 1 column += 1 end elsif to_row > from_row && to_column <= from_column row += 1 column -= 1 until row == to_row return false unless @state [ row ] [ column ] == nil row += 1 column -= 1 end elsif to_row <= from_row && to_column <= from_column row -= 1 column -= 1 until row == to_row return false unless @state [ row ] [ column ] == nil row -= 1 column -= 1 end elsif to_row <= from_row && to_column > from_column row -= 1 column += 1 until row == to_row return false unless @state [ row ] [ column ] == nil row -= 1 column += 1 end end true end
Given two points on the board that form a diagonal, returns true
if there are no pieces in between and false otherwise
Given two points on the board that form a diagonal returns true if there are no pieces in between and false otherwise
from_row
<not_specific>
from_column
<not_specific>
to_row
<not_specific>
to_column
<not_specific>