Skip to content

Instantly share code, notes, and snippets.

@pshushereba
Created March 30, 2016 21:54
Show Gist options
  • Save pshushereba/3aa5abf89fc112138a3709ba3865a706 to your computer and use it in GitHub Desktop.
Save pshushereba/3aa5abf89fc112138a3709ba3865a706 to your computer and use it in GitHub Desktop.
Distance method for Chess Application
def distance(destination_row, destination_col)
if self.vertical?(destination_row, destination_col)
return (destination_row - current_row_index).abs
elsif self.horizontal?(destination_row, destination_col)
return (destination_col - current_column_index).abs
elsif self.diagonal?(destination_row, destination_col)
return (destination_col - current_column_index).abs
# destination_col - current_row_index
else
puts "Invalid Input"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment