function direction = myAI4(game)

d1 = {'up', 'down'};
d2 = {'left', 'right'};

h=game.HighestBlock;
while h>=32
    
    b=find(game.Board==h);
    
    if length(b)>1   
        n1=b(1);n2=b(2);
        for i=1:length(b)-1
            if abs(b(i)-b(i+1))<abs(n1-n2)
                n1=b(i);n2=b(i+1);
            end
        end
        
        if abs(n1-n2)==1
            move(game,d1{randi(2)});
        else if abs(n1-n2)==4
                move(game,d2{randi(2)});
            else if abs(n1-n2)==3 || abs(n1-n2)==5
                    diagonal(game,n1,n2);
                else
            
        [i1,j1]=getindex(n1);
        [i2,j2]=getindex(n2);
    
        if sumn(game,1:i1,j1)==sumn(game,1:i2,j2)
            move(game,'up');
        else if sumn(game,i1:4,j1)==sumn(game,i2:4,j2)
                move(game,'down');
            end
        end
        if sumn(game,i1,1:j1)==sumn(game,i2,1:j2)
            move(game,'left');
        else if sumn(game,i1,j1:4)==sumn(game,i2,j2:4)
                move(game,'right');
            end
        end
    
    if j1==j2&&abs(sumn(game,1:i1,j1)-sumn(game,1:i2,j2))==1
        move(game,d1{randi(2)});
    end
    if i1==i2&&abs(sumn(game,i1,1:j1)-sumn(game,i2,1:j2))==1
        move(game,d2{randi(2)});
    end
%     move(game,myAI3(game));
%     direction=myAI3(game);
%     return
                end
            end
        end
    end
    h=h/2;
end

direction=myAI3(game);