function [rrow, rcol] = takeAction(r, c, x2, y2, explored, pits, monsters)
for x = 1:4
    for y = 1:4
        row = 4 - y + 1;
        col = x;
        if explored(row,col) == 1 && ~(row == r && col == c)
            if pits(row, col) <= 1 && monsters(row,col) <= 1
                rrow = x;
                rcol = y;
                return;
            end
        end
    end
end

for x =  1:4
    for y = 1:4
        row = 4 - y + 1;
        col = x;
        if explored(row,col) == 1 && ~(row == r && col == c)
            if pits(row,col) < 22 && monsters(row,col) <= 1
                rrow = x;
                rcol = y;
                return;
            end
        end
    end
end




rcol = y2;
if y2 ~= 4 || x2 == 1
  rrow = x2+1;
else
    rrow = x2-1;
end

end


