Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A = zeros(200,20);
- A_up = 6*ones(1,20);
- A_down = zeros(1,20);
- A_left = 6*ones(202,1);
- A_right = A_left;
- A = [A_up; A; A_down];
- A = [A_left A A_right]
- M = zeros(200,20);
- M_up = 6*ones(1,20);
- M_left = 6*ones(202,1);
- M = [M_up; M; M_up];
- M = [M_left M M_left]
- total_ants = 1000
- N = total_ants
- x = A(2,2:21)
- X = sum(x)
- while X<N
- for i = 202:-1:2
- for j = 2:21
- if A(i,j)~=0
- for k = 1:A(i,j)
- Np = M(i-1,j)
- NEp = M(i-1,j-1)
- NWp = M(i-1,j+1)
- lst = [NEp Np NWp]
- mx = max(lst);
- plst = find(lst == mx);
- post = plst(randi([1,length(plst)],1))
- pher = lst(plst(randi([1,length(plst)],1)),1)
- if pher < level1
- kecepatan = 1
- if post = 1
- A(i-1,-1) = A(i-1,j-1)+1
- A(i,j) = A(i,j) - 1
- elseif post = 2
- A(i-1,j) = A(i-1,j) + 1
- A(i,j) = A(i,j) - 1
- else
- A(i-1,j+1) = A(i-1,j+1) -1
- A(i,j) = A(i,j) - 1
- end
- elseif pher < level2
- kecepatan = 2
- elseif pher < level3
- kecepatan = 3
- else
- kecepatan = 4
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement