Skip to content

Commit

Permalink
Moved the logic into the forwards method.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemalvarambhia committed Oct 30, 2023
1 parent 1858d8d commit 6c0db22
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/mars_rover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ def execute(commands)
when 'b'
backwards(location)
when 'f'
new_location = forwards(location)
if @map.located_at_north_pole? new_location.coordinates
Location.new(coordinates: Coordinates.new(x: new_location.coordinates.x + 18, y: 8), direction: 'S')
else
new_location
end
forwards(location)
when 'l'
location.rotate_left
when 'r'
Expand All @@ -44,7 +39,12 @@ def inspect
private

def forwards(current_location)
@map.next_location_forwards(location: current_location)
new_location = @map.next_location_forwards(location: current_location)
if @map.located_at_north_pole? new_location.coordinates
Location.new(coordinates: Coordinates.new(x: new_location.coordinates.x + 18, y: 8), direction: 'S')
else
new_location
end
end

def backwards(current_location)
Expand Down

0 comments on commit 6c0db22

Please sign in to comment.