-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_messages.m
32 lines (27 loc) · 1.04 KB
/
create_messages.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function create_messages(nr,nf,nh,agent)
%function that populates the global data structure representing
%message information
%MESSAGES is a data structure containing information that agents need to
%broadcast to each other
% MESSAGES.atype - n x 1 array listing the type of each agent in the model
% (1=hare, 2-lynx, 3=human, 4=dead agent)
% MESSAGES.pos - list of every agent position in [x y]
% MESSAGE.dead - n x1 array containing ones for agents that have died
% in the current iteration
global MESSAGES
for an=1:length(agent)
if isa(agent{an},'hare')
MESSAGES.atype(an)=1;
MESSAGES.pos(an,:)=get(agent{an},'pos');
elseif isa(agent{an},'lynx')
MESSAGES.atype(an)=2;
MESSAGES.pos(an,:)=get(agent{an},'pos');
elseif isa(agent{an},'human')
MESSAGES.atype(an)=3;
MESSAGES.pos(an,:)=get(agent{an},'pos');
else
MESSAGES.atype(an)=0;
MESSAGES.pos(an,:)=[-1 -1];
end
MESSAGES.dead(an)=0;
end