%ant_sim
clc
clear all
close all
food_1=0;
room_cap=zeros(30,30);
home_center=[15.5,15.5];
x=1:30;
y=1:30;
home_helmo=zeros(30,30);
for ii=1:30
for jj=1:30
home_helmo(ii,jj)=sqrt((ii-home_center(1))^2+(jj-home_center(2))^2);
end
end
max_hel=max(max(home_helmo));
%find(home_helmo==max_hel)
home_helmo=(max_hel-home_helmo)./max_hel(1)+0.001;
%food_center=[25.5,25.5];
food_center=[15.5,15.5];
circle_center(1)=randint(1,1,[1,30]);
circle_center(2)=circle_center(1);
food_helmo=zeros(30,30);%
%start place==(100,200)
for ii=1:30
for jj=1:30
food_helmo(ii,jj)=sqrt((ii-food_center(1))^2+(jj-food_center(2))^2);
end
end
max_hel=max(max(food_helmo));
%find(home_helmo==max_hel)
%food_helmo=(max_hel-food_helmo)./max_hel(1)+0.001;
food_helmo=(food_helmo)./max_hel+0.001;
food_num=randint(1,1,[1,30]);
%food_helmo=zeros(30,30);%
home_up=16;
home_down=15;
home_right=16;
home_left=15;
for ii=1:30
ant(ii,1)=randint(1,1,[15,16]);
ant(ii,2)=randint(1,1,[15,16]);
ant(ii,3)=1;
end
up=16*(x(15:16)<=16&x(15:16)>=15);
down=15*(x(15:16)<=16&x(15:16)>=15);
left=15*(y(15:16)<=16&y(15:16)>=15);
right=16*(y(15:16)<=16&y(15:16)>=15);
sanum=1/28:1/28:2*pi;
Rr=2.5;
%circle_center=randint(1,1,[20,27]);
xx=2.5*sin(sanum)+circle_center(1);
yy=2.5*cos(sanum)+circle_center(2);
figure(1)
ll=find(ant(:,3)==1);
p1=plot(ant(ll,1),ant(ll,2),'or');
mm=find(ant(:,3)==0);
p11=plot(ant(mm,1),ant(mm,2),'ok');
%p1=plot(ant(:,1),ant(:,2),'ro');
hold on
axis([-10,30,-10,30])
p2=plot(x(15:16),up,'-');
%hold on
p3=plot(x(15:16),down,'-');
%hold on
p4=plot(left,y(15:16),'-');
%hold on
p5=plot(right,y(15:16),'-');
%hold on
p6=plot(right,y(15:16),'-');
hold on
ppl=plot(xx(:),yy(:),'g-');
hold on
%plot(ant(:,1),ant(:,2),'ro')
%pause(0.1)
%plot(300,300,'ok')
for iii=1:1000
room_cap=zeros(31,31);
delete(p1,p11);
%delete(p7);
% set(p1,'visible','on');
%set(p7,'visible','on');
%mishi
for jj=1:size(ant,1);
if food_1==1
if luan==1;
food_helmo=randint(30,30,[1,300]);%
food_helmo=(food_helmo)./max_hel+0.001;
end
end
if ant(jj,3)==1 %find food!
dir_on_p=1/8*ones(1,8);
dir=ones(1,8);
aa=ant(jj,1)-1;
bb=ant(jj,1)+1;
cc=ant(jj,2)-1;
dd=ant(jj,2)+1;
if aa<=1
aa=ant(jj,1);
end
if bb>=30
bb=ant(jj,1);
end
if cc<=1
cc=ant(jj,2);
end
if dd>=30
dd=ant(jj,2);
end
dir(1)=food_helmo(ant(jj,1),cc);
dir(2)=food_helmo(ant(jj,1),dd);
dir(3)=food_helmo(aa,cc);
dir(4)=food_helmo(aa,ant(jj,2));
dir(5)=food_helmo(aa,dd);
dir(6)=food_helmo(bb,cc);
dir(7)=food_helmo(bb,ant(jj,2));
dir(8)=food_helmo(bb,dd);
dir_sum=sum(dir);
[dir_new,seq]=sort(dir);
dir_on_p(seq(1:4))=0.05;
dir_on_p(seq(5:6))=0.1;
dir_on_p(seq(7:8))=0.3;
dir_on(jj)=randsrc(1,1,[1,2,3,4,5,6,7,8;dir_on_p]);%1:x,y-1;x,y+1;x-1,y-1;x-1,y;x-1,y+1;x+1,y-1;x+1,y;x+1,y+1
if dir_on(jj)==1
if(room_cap(ant(jj,1),cc)==0)
ant(jj,1)=ant(jj,1);
ant(jj,2)=cc;
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==2
if(room_cap(ant(jj,1),dd)==0)
ant(jj,1)=ant(jj,1);
ant(jj,2)=dd;
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==3
if(room_cap(aa,cc)==0)
ant(jj,1)=aa;
ant(jj,2)=cc;
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==4
if(room_cap(aa,ant(jj,2))==0)
ant(jj,1)=aa;
ant(jj,2)=ant(jj,2);
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==5
if(room_cap(aa,dd)==1)
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
else
ant(jj,1)=aa;
ant(jj,2)=dd;
end
elseif dir_on(jj)==6
if(room_cap(bb,cc)==1)
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
else
ant(jj,1)=bb;
ant(jj,2)=cc;
end
elseif dir_on(jj)==7
if(room_cap(bb,ant(jj,2))==1)
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
else
ant(jj,1)=bb;
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==8
if(room_cap(bb,dd)==1)
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
else
ant(jj,1)=bb;
ant(jj,2)=dd;
end
end
if ant(jj,1)>=circle_center-Rr&ant(jj,1)<=circle_center+Rr
if ant(jj,2)>=circle_center-Rr&ant(jj,2)<=circle_center+Rr
luan=0;
ant(jj,3)=0;
food_num=food_num-1;
for iiii=1:30
for jjjj=1:30
food_helmo(iiii,jjjj)=sqrt((iiii-circle_center(1))^2+(jjjj-circle_center(2))^2);
end
end
max_hel=max(max(food_helmo));
%find(home_helmo==max_hel)
food_helmo=(max_hel-food_helmo)./max_hel(1)+0.001;
if food_num==0
food_num=randint(1,1,[1,30]);
circle_center(1)=randint(1,1,[1,30]);
circle_center(2)=circle_center(1);
ppl=plot(xx(:),yy(:),'w-');
p2=plot(x(15:16),up,'-');
%hold on
p3=plot(x(15:16),down,'-');
%hold on
p4=plot(left,y(15:16),'-');
%hold on
p5=plot(right,y(15:16),'-');
%hold on
p6=plot(right,y(15:16),'-');
Rr=rand(1,1)*2.5+1
xx=Rr*sin(sanum)+circle_center(1);
yy=Rr*cos(sanum)+circle_center(2);
%set(p111,'visible','off');
%delete(ppl);
food_1=1;
luan=1;
food_helmo=randint(30,30,[1,99]);%
max_hel=max(max(food_helmo));
food_helmo=(food_helmo)./max_hel+0.001;
%start place==(100,200)
%{
for ii=1:30
for jj=1:30
food_helmo(ii,jj)=sqrt((ii-food_center(1))^2+(jj-food_center(2))^2);
end
end
max_hel=max(max(food_helmo));
%find(home_helmo==max_hel)
%food_helmo=(max_hel-food_helmo)./max_hel(1)+0.001;
food_helmo=(food_helmo)./max_hel+0.001;
%}
end
ppl=plot(xx,yy,'g-');
% food_center=[25.5,25.5];
end
end
else
dir_on_p=1/8*ones(1,8);
dir=ones(1,8);
aa=ant(jj,1)-1;
bb=ant(jj,1)+1;
cc=ant(jj,2)-1;
dd=ant(jj,2)+1;
if aa<=1
aa=ant(jj,1);
end
if bb>=30
bb=ant(jj,1);
end
if cc<=1
cc=ant(jj,2);
end
if dd>=30
dd=ant(jj,2);
end
dir(1)=home_helmo(ant(jj,1),cc);
dir(2)=home_helmo(ant(jj,1),dd);
dir(3)=home_helmo(aa,cc);
dir(4)=home_helmo(aa,ant(jj,2));
dir(5)=home_helmo(aa,dd);
dir(6)=home_helmo(bb,cc);
dir(7)=home_helmo(bb,ant(jj,2));
dir(8)=home_helmo(bb,dd);
dir_sum=sum(dir);
[dir_new,seq]=sort(dir);
dir_on_p(seq(1:4))=0.025;
dir_on_p(seq(5:6))=0.05;
dir_on_p(seq(7:8))=0.4;
dir_on(jj)=randsrc(1,1,[1,2,3,4,5,6,7,8;dir_on_p]);%1:x,y-1;x,y+1;x-1,y-1;x-1,y;x-1,y+1;x+1,y-1;x+1,y;x+1,y+1
if dir_on(jj)==1
if(room_cap(ant(jj,1),cc)==0)
ant(jj,1)=ant(jj,1);
ant(jj,2)=cc;
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
end
elseif dir_on(jj)==2
if(room_cap(ant(jj,1),dd)==0)
ant(jj,1)=ant(jj,1);
ant(jj,2)=dd;
else
ant(jj,1)=ant(jj,1);
ant(jj,2)=ant(jj,2);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
AI.zip (32个子文件)
AI
food_amp.m 2KB
food_find.m 609B
neural.m 167B
ant_map.m 10KB
liziqun.m 6KB
p_inherbit.asv 7KB
fire_up.m 5KB
food_eat.m 1KB
ACATSP.m 4KB
freeze_down.m 5KB
downfire.m 2KB
rpos.m 424B
fire_move.m 5KB
ant_anology.m 10KB
p_move.asv 4KB
onfire.asv 486B
equal_c.m 5KB
food_find.asv 473B
ACATSP.zip 2KB
food_amp.asv 2KB
DrawRoute.m 625B
p_death.m 561B
yichuan.asv 4KB
ant.m 4KB
p_inherbit.m 7KB
liziqun.asv 6KB
genetic.m 4KB
shi_ant.m 201B
p_move.m 4KB
food_eat.asv 1KB
ant_map.asv 10KB
neural.asv 55B
共 32 条
- 1
资源评论
tigerWingsLab007
- 粉丝: 26
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功