-
大小: 1KB文件類型: .m金幣: 1下載: 0 次發(fā)布日期: 2021-05-28
- 語言: Matlab
- 標(biāo)簽: MATLAB_code??生命游戲??
資源簡(jiǎn)介
蘭頓螞蟻(longton’s ant)的MATLAB實(shí)現(xiàn)代碼,親測(cè)可用,直接運(yùn)行,首發(fā)資源,可修改棋盤大小,可修改螞蟻的初始位置或者初始方向,可自行設(shè)置行走的次數(shù)。
代碼片段和文件信息
%longton‘s?ant
clear?all
s=200;??%棋盤大小
%當(dāng)前棋盤狀態(tài)
cells(1:s1:s)?=?1;?%全為白色
imh=image(cat(3cellscellscells));
set(imh?‘erasemode‘‘none‘);
axis?equal;
axis?tight;
%螞蟻位置
posx=80;
posy=100;
%頭的朝向,從頂開始順時(shí)針方向?yàn)?234
direct=1;
for?i=1:100000
????????if(cells(posxposy)==0)??%當(dāng)前棋盤為黑格
????????????if(direct==1)
?????????????????cells(posxposy)=1;
?????????????????posy=posy+1;
?????????????????posx=posx;
?????????????????direct=2;??
????elseif(direct==2)
????????cells(posxposy)=1;
????????posy=posy;
????????posx=posx+1;
????????direct=3;
??
????elseif(direct==3)
????????cells(posxposy)=1;
????????posy=posy-1;
????????posx=posx;
????????direct=4;
??????????
- 上一篇:Keystone變換仿真程序
- 下一篇:matlab代碼讀電離層TEC文件
評(píng)論
共有 條評(píng)論