• 大小: 16KB
    文件类型: .m
    金币: 2
    下载: 0 次
    发布日期: 2024-02-05
  • 语言: Matlab
  • 标签: 内螺旋  全覆盖  

资源简介

采用内螺旋算法,房间抽象为矩阵,-1不可行,0未扫可行,1已扫

资源截图

代码片段和文件信息

function []=xunhuansaomiao07

global a;
global qj;
global qi;
global oj;
global oi;
global xz;
global zz;
global sz;
global yz;


global xzz;
global xsz;
global xyz;

global zxz;
global zsz;
global zyz;

global sxz;
global szz;
global syz;

global yxz;
global yzz;
global ysz;
global cz;

global mh;
global ms;


%%%%%%%%七号房间
a=[ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 0 0 0 0 0 0 0 -1 -1
    -1 0 0 0 -1 -1 -1 -1 -1 -1
    -1 0 0 0 -1 -1 -1 -1 -1 -1
    -1 0 0 0 -1 -1 -1 -1 -1 -1
    -1 0 0 0 -1 -1 -1 -1 -1 -1
    -1 0 0 0 0 0 0 0 -1 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 0 0 0 0 0 0 0 0 -1
    -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];
mh=10;
ms=14;
qi=2;
qj=2;
oi=qi;
oj=qj;


xz=1;
zz=0;
sz=0;
yz=0;
xzz=0;xsz=0;xyz=0;
zxz=0;zsz=0;zyz=0;
sxz=0;szz=0;syz=0;
yxz=0;yzz=0;ysz=0;
cz=0;
a(qiqj)=1;
xiaxing(qiqja(qiqj));
hxz=xz+zxz+sxz+yxz;
hzz=zz+szz+xzz+yzz;
hsz=sz+xsz+zsz+ysz;
hyz=yz+xyz+zyz+syz;
h=hxz+hzz+hsz+hyz;

cxz=xz-(zxz+sxz+yxz);
czz=zz-(szz+xzz+yzz);
csz=sz-(xsz+zsz+ysz);
cyz=yz-(xyz+zyz+syz);


cr=cz/(h-cz)
xlswrite(‘清扫结果7.xls‘a);
% a
 chongdianluxian;
 a
 cz
 h
 cr=cz/(h-cz)




function []=xiaxing(xixjxa)
global mh;
global ms;
global a;
global qj;
global qi;
global oj;
global oi;
global xz;

global xzz;
global xsz;
global xyz;

global cz;
xixjxa
 a

%a(xixj)=xa;
%下行扫描xiaxing(i-1ja(i-1j));
oi=xi;
oj=xj;
index=find(a==0);
if (index)~=0%没走完
    j=xj
    for i=xi:ms-1
%         if i==qi&&j==qj+1
%           disp(‘边界扫描完成‘);
%           neiluoxuan(ija(i.j));
%         end
i
        if a(ij+1)~=0&&a(ij-1)~=0&&a(i+1j)~=0 %判断有没有走进死胡同
            a(ij)=1;
            if a(i-1j)~=-1%后面无障碍
                i=i-1;
                a(ij)=1;
                cz=cz+1;
                xz=xz+1;
                oi=i;
                oj=j;
                disp(‘后退‘);
                xiaxing(ija(ij));%后退
                break;     
           
           
            
            elseif a(ij-1)~=-1%右转
                j=j-1;
                a(ij)=1;
                cz=cz+1;
                xz=xz+1;
                oi=i;
                oj=j;
                disp(‘右转‘);
                youxing(ija(ij));
                break
            elseif a(ij+1)~=-1%左转
                j=j+1;
                a(ij)=1;
                cz=cz+1;
                xz=xz+1;
                oi=i;
                oj=j;
                disp(‘左转‘);
                zuoxing(ija(ij));
                break
            elseif a(i+1j)~=-1
                i=i+1
                a(ij)=1;
                cz=cz+1;
                xz=xz+1;
                oi=i;
                oj=j;
                disp(‘掉头‘);
                shangxing(ija(ij));%反向掉头 上行
                 break 
            end
        elseif a(i

评论

共有 条评论

相关资源