Code covered by the BSD License

# Automata Engineer 2010 NITK- Documented version

### Anurag Ranjan (view profile)

The documented version of the code which solves the problem statement of Automata Engineer 2010 NITK

motion( path, dist, o )
```function [ mot, o ] = motion( path, dist, o )
%gives the motion followed by the bot and the orientation of the bot
%input: path matrix, dist:size(path) and initial orientation,o
%initial conditions... o=2
%FLAG
% orientation: up-1.. right-2.. down-3... left-4
mot=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
j=1;
for i=1:(dist)
switch o
case 1
switch (path(i+1)-path(i))
case -5
mot(j)='L';
mot(j+1)='F';
j=j+2;
o=4;
case -1
mot(j)='F';
j=j+1;
o=1;
case 5
mot(j)='R';
mot(j+1)='F';
j=j+2;
o=2;
case 1
mot(j)='R';
mot(j+1)='R';
mot(j+2)='F';
j=j+3;
o=3;
end
case 2
switch (path(i+1)-path(i))
case -1
mot(j)='L';
mot(j+1)='F';
j=j+2;
o=1;
case 5
mot(j)='F';
j=j+1;
o=2;
case 1
mot(j)='R';
mot(j+1)='F';
j=j+2;
o=3;
case -5
mot(j)='R';
mot(j+1)='R';
mot(j+2)='F';
j=j+3;
o=4;
end
case 3
switch (path(i+1)-path(i))
case 5
mot(j)='L';
mot(j+1)='F';
j=j+2;
o=2;
case 1
mot(j)='F';
j=j+1;
o=3;
case -5
mot(j)='R';
mot(j+1)='F';
j=j+2;
o=4;
case -1
mot(j)='R';
mot(j+1)='R';
mot(j+2)='F';
j=j+3;
o=1;
end
case 4
switch (path(i+1)-path(i))
case 1
mot(j)='L';
mot(j+1)='F';
j=j+2;
o=3;
case -5
mot(j)='F';
j=j+1;
o=4;
case -1
mot(j)='R';
mot(j+1)='F';
j=j+2;
o=1;
case 5
mot(j)='R';
mot(j+1)='R';
mot(j+2)='F';
j=j+3;
o=2;
end
end
end
mot(j)='S';

%   Detailed explanation goes here

end

```