function [rover_latitude,rover_longitude] = ...
  rover_move(command_num,init_pos,init_dir)
% Convert command numbers into rover movements.
% Command numbers for strings are:
%       '0' = 0
%       '1' = 1
%    'left' = 2
%   'right' = 3
% Inputs:
%   command_num = horizontal array of command #'s, values 0 to 3
%   init_pos = array of 2 values (x and y) for initial position
%   init_dir = array of 2 values (x and y) for initial direction of movement
% Outputs:
%   rover_latitude = array of x positions of rover
%   rover_longitude = array of y positions of rover


% Initialize position.
position_vec = init_pos
% Initialize direction.
direction_vec = init_dir

rover_latitude = []
rover_longitude = []
% Step through the list of commands.
for comm_index = 1 : length(command_num)
  % Decide what command is and take action.
  switch command_num(comm_index)
    case 0
      % '0' = don't move.
    case 1
      % '1' = add direction vector to current position.
      position_vec = position_vec + direction_vec
      % Add this new position to list.
      rover_latitude = [rover_latitude, position_vec(1)]
      rover_longitude = [rover_longitude, position_vec(2)]
    case 2
      % 'left' = rotate direction vector +90 degrees.
      direction_vec = ([0, -1; 1, 0]*direction_vec')'
    case 3
      % 'right' = rotate direction vector -90 degrees.
      direction_vec = ([0, 1; -1, 0]*direction_vec')'
    otherwise
      disp('unknow code number')
  end
end

return
