Created
March 30, 2016 21:54
-
-
Save pshushereba/3aa5abf89fc112138a3709ba3865a706 to your computer and use it in GitHub Desktop.
Distance method for Chess Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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