antleft.m
来自「The Source of Genetic Programming develo」· M 代码 · 共 40 行
M
40 行
function antleft
%ANTLEFT Turns the GPLAB artificial ant to the left.
% ANTLEFT(SIM) returns the number of the time step used by the ant after
% turning. Other variables are returned as global variables.
%
% See also ANTFITNESS, ANTFOODAHEAD, ANTIF, ANTMOVE, ANTRIGHT, ANTPROGN2, ANTPROGN3
%
% Copyright (C) 2003-2007 Sara Silva (sara@dei.uc.pt)
% This file is part of the GPLAB Toolbox
%global trail;
global x;
global y;
global direction;
global npellets;
%global maxtime;
global ntime;
global sim;
global path;
% new direction:
if strcmp(direction,'u') % facing up
newdirection='l';
elseif strcmp(direction,'d') % facing down
newdirection='r';
elseif strcmp(direction,'r') % facing right
newdirection='u';
elseif strcmp(direction,'l') % facing left
newdirection='d';
end
direction=newdirection;
ntime=ntime+1;
if sim
antpath(ntime,x,y,direction,npellets,0);
% 0 is the setting of "looked ahead", true only if 'antif' is executed
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?