function [reward] = RewardFunction(sensor_Levels,MOTION_type)
% QLEARNING Summary of this function goes here
%   Detailed explanation goes here
    reward = -20;
    if (((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3))
        switch MOTION_type
            case 1
                reward = 3;
            case 2
                reward = -1;
            case 3
                reward = -1.5;
            case 4
                reward = -2.5;
            case 5
                reward = -5;
            case 6
                reward = -1;
            case 7
                reward = -1.5;
            case 8
                reward = -2.5;
            case 9
                reward = -5;        
        end
    elseif (((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 2) && ((sensor_Levels(6,1)-1) == 2))
        switch MOTION_type
            case 1
                reward = 3;
            case 2
                reward = -1;
            case 3
                reward = -1.5;
            case 4
                reward = -2.5;
            case 5
                reward = -5;
            case 6
                reward = -1;
            case 7
                reward = -1.5;
            case 8
                reward = -2.5;
            case 9
                reward = -5;        
        end    
    elseif (((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 2) && ((sensor_Levels(6,1)-1) == 3))
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = 3;
            case 3
                reward = -3;
            case 4
                reward = -2.5;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -5;
            case 8
                reward = -5;
            case 9
                reward = -5;        
        end
    elseif (((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 2))
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -5;
            case 5
                reward = -5;
            case 6
                reward = 3;
            case 7
                reward = -1;
            case 8
                reward = -2.5;
            case 9
                reward = -3;        
        end    
    elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -1;
            case 3
                reward = 3;
            case 4
                reward = -2.5;
            case 5
                reward = -5;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -5;        
        end
    elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 1)
        switch MOTION_type
            case 1,
                reward = -3;
            case 2,
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3.5;
            case 5
                reward = -3;
            case 6
                reward = -1.5;
            case 7
                reward = 3;
            case 8
                reward = -2.5;
            case 9
                reward = -5;        
        end
    elseif ((sensor_Levels(1,1)-1) >= 1) && ((sensor_Levels(3,1)-1) == 0) && ((sensor_Levels(5,1)-1) >= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = 3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
        end   
   elseif ((sensor_Levels(1,1)-1) >= 1) && ((sensor_Levels(3,1)-1) >= 1) && ((sensor_Levels(5,1)-1) <= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 1)
        switch MOTION_type
            case 1
                reward = -1;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -0.5;
            case 7
                reward = 3;
            case 8
                reward = -0.5;
            case 9
                reward = -1;        
        end 
   elseif ((sensor_Levels(1,1)-1) <= 1) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) >= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
        end
   elseif ((sensor_Levels(1,1)-1) >= 2) && ((sensor_Levels(3,1)-1) >= 1) && ((sensor_Levels(5,1)-1) <= 1) && ((sensor_Levels(4,1)-1) <= 1) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 1)
        switch MOTION_type
            case 1
                reward = -6;
            case 2
                reward = -6;
            case 3
                reward = -6;
            case 4
                reward = -6;
            case 5
                reward = -6;
            case 6
                reward = -3;
            case 7
                reward = 3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
        end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) >= 1) && ((sensor_Levels(5,1)-1) == 0) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -2;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -0.5;
            case 7
                reward = 3;
            case 8
                reward = -1.3;
            case 9
                reward = -1.3;        
        end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 0) && ((sensor_Levels(5,1)-1) >= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward =  3;
            case 5
                reward = -3;
            case 6
                reward = -6;
            case 7
                reward = -6;
            case 8
                reward = -6;
            case 9
                reward = -6;        
        end
      elseif ((sensor_Levels(1,1)-1) <= 1) &&((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 3)
        switch MOTION_type
            case 1
                reward = -10;
            case 2
                reward = -9;
            case 3
                reward = -8;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -9;
            case 7
                reward = -8;
            case 8
                reward = -3;
            case 9
                reward = 3;        
        end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 1) && ((sensor_Levels(5,1)-1) >= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) <= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -1.5;
            case 2
                reward = -1;
            case 3
                reward = -1;
            case 4
                reward = 3;
            case 5
                reward = -1;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -7;
            case 9
                reward = -10;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 1) && ((sensor_Levels(5,1)-1) >= 2) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) >= 2) 
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -2;
            case 3
                reward = -1.5;
            case 4
                reward = -1.5;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -5;
            case 8
                reward = -7;
            case 9
                reward = -10;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) > 1) && ((sensor_Levels(5,1)-1) <= 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) >= 2)
       switch MOTION_type
            case 1
                reward = -1.5;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -1;
            case 8
                reward = -3;
            case 9
                reward = -5;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 3) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) >= 1) && ((sensor_Levels(6,1)-1) >= 2)
       switch MOTION_type
            case 1
                reward = -1.5;
            case 2
                reward = -1;
            case 3
                reward = -0.7;
            case 4
                reward = -0.5;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -7;
            case 9
                reward = -10;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 0) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) >= 2)
       switch MOTION_type
            case 1
                reward = -1;
            case 2
                reward = 1.5;
            case 3
                reward = -0.5;
            case 4
                reward = -1.5;
            case 5
                reward = -1.5;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -7;
            case 9
                reward = -10;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) == 0) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) <= 1)
       switch MOTION_type
            case 1
                reward = -0.5;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -7;
            case 5
                reward = -10;
            case 6
                reward = 1.5;
            case 7
                reward = -0.5;
            case 8
                reward = -1;
            case 9
                reward = -1;        
       end
      elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 3) && ((sensor_Levels(5,1)-1) >=2) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) >= 1) && ((sensor_Levels(6,1)-1) <= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -7;
            case 5
                reward = -10;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = 3;        
       end
      elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) <= 2) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) <= 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -0.3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = 3;        
       end
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) <= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -1.5;
            case 2
                reward = -1;
            case 3
                reward = -0.5;
            case 4
                reward = 3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
      elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 2) && ((sensor_Levels(5,1)-1) <= 2) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) <= 1) && ((sensor_Levels(6,1)-1) >= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end     
   elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) <= 2) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
      elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) <= 2) && ((sensor_Levels(4,1)-1) <= 3) && ((sensor_Levels(2,1)-1) <= 3) && ((sensor_Levels(6,1)-1) <= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = 3;        
       end
         elseif ((sensor_Levels(1,1)-1) <= 3) && ((sensor_Levels(3,1)-1) <= 2) && ((sensor_Levels(5,1)-1) <= 2) && ((sensor_Levels(4,1)-1) <= 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 2) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 1)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = 3;
            case 9
                reward = -3;        
       end     
    elseif ((sensor_Levels(1,1)-1) >= 2) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = 3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
    elseif ((sensor_Levels(1,1)-1) == 2) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 1)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = 3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) <= 1) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 2) && ((sensor_Levels(6,1)-1) >= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = 3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 2) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) >= 2) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 2) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 1) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = 3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
      elseif ((sensor_Levels(1,1)-1) == 1) && ((sensor_Levels(3,1)-1) == 1) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 0) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 1) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) >= 2) && ((sensor_Levels(3,1)-1) >= 2) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) <= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = 3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
    elseif ((sensor_Levels(1,1)-1) == 2) && ((sensor_Levels(3,1)-1) <= 1) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 0) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = 3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 1) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
    elseif ((sensor_Levels(1,1)-1) == 1) && ((sensor_Levels(3,1)-1) == 3) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 0) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = 3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
    elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) ==1) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) ==2) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) >= 2) && ((sensor_Levels(3,1)-1) ==2) && ((sensor_Levels(5,1)-1) >= 1) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) >= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = 3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 1) && ((sensor_Levels(3,1)-1) ==2) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) >= 2) && ((sensor_Levels(2,1)-1) == 0) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = 3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) >= 2) && ((sensor_Levels(3,1)-1) <=1) && ((sensor_Levels(5,1)-1) >= 2) && ((sensor_Levels(4,1)-1) <= 2) && ((sensor_Levels(2,1)-1) <= 2) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
      elseif ((sensor_Levels(1,1)-1) <= 2) && ((sensor_Levels(3,1)-1) <=3) && ((sensor_Levels(5,1)-1) >= 2) && ((sensor_Levels(4,1)-1) <= 3) && ((sensor_Levels(2,1)-1) <= 3) && ((sensor_Levels(6,1)-1) >= 1)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = 3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end    
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) ==1) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 1) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) <= 2)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = 3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) <=2) && ((sensor_Levels(5,1)-1) == 1) && ((sensor_Levels(4,1)-1) == 3) && ((sensor_Levels(2,1)-1) == 2) && ((sensor_Levels(6,1)-1) == 1)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end
      elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 0) && ((sensor_Levels(5,1)-1) == 2) && ((sensor_Levels(4,1)-1) == 2) && ((sensor_Levels(2,1)-1) == 3) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = 3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = -3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end 
   elseif ((sensor_Levels(1,1)-1) == 3) && ((sensor_Levels(3,1)-1) == 2) && ((sensor_Levels(5,1)-1) == 3) && ((sensor_Levels(4,1)-1) == 1) && ((sensor_Levels(2,1)-1) == 1) && ((sensor_Levels(6,1)-1) == 3)
       switch MOTION_type
            case 1
                reward = -3;
            case 2
                reward = -3;
            case 3
                reward = -3;
            case 4
                reward = -3;
            case 5
                reward = -3;
            case 6
                reward = 3;
            case 7
                reward = -3;
            case 8
                reward = -3;
            case 9
                reward = -3;        
       end    
    end
end

