Skip to content

Commit

Permalink
Refactor/Parallel Change: removed obsolete code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemalvarambhia committed Oct 25, 2023
1 parent 3758a89 commit 25be252
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions lib/mars_rover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,19 @@ class MarsRover

def initialize(starting_position:, direction:, map:)
@map = map
@current_position = starting_position
@direction = direction
@current_location = Location.new(coordinates: starting_position, direction: direction)
end

def execute(commands)
commands.each do |command|
case command
when 'b'
@current_position = move_backwards
@current_location = backwards
when 'f'
@current_position = move_forwards
@current_location = forwards
when 'l'
@direction = turn_left
@current_location = rotate_left
when 'r'
@direction = turn_right
@current_location = rotate_right
end
end
Expand All @@ -49,14 +43,6 @@ def inspect

private

def turn_right
TURN_LEFT.invert[@direction]
end

def turn_left
TURN_LEFT[@direction]
end

def forwards
Location.new(
coordinates: @map.next_coordinate_forwards(current_position: @current_location.coordinates, direction: @current_location.direction),
Expand All @@ -82,12 +68,4 @@ def rotate_right
coordinates: @current_location.coordinates, direction: TURN_LEFT.invert[@current_location.direction]
)
end

def move_backwards
@map.next_coordinate_backwards(current_position: @current_position, direction: @direction)
end

def move_forwards
@map.next_coordinate_forwards(current_position: @current_position, direction: @direction)
end
end

0 comments on commit 25be252

Please sign in to comment.