function e=evosim()board=(zeros(12,12));pop=1;charac=([1, 0]);cloc=[];for i=1:pop %%Population generator%%
popcount=1; a=randi([1,12]); b=randi([1,12]); if board(a,b)==0 board(a,b)=charac(1); cloc=[b a popcount; cloc] endendfor i=1:10 %%Food generator%%
a=randi([1,12]); b=randi([1,12]); if board(a,b)==0 board(a,b)=2; endende=board;for i=1:pop xcord=cloc(i,1); ycord=cloc(i,2); if board(xcord-1,ycord)==2 end
Here's my code so far: basically, I have a blank 12×12 matrix, and randomly place 1's and 2's. I want to check the 8 squares around the 1, and the x and y coordinates of any 1s are stored in cloc. After it checks, I want the 1 to 'jump' to the location of where the 2 was.
I think I could do it by checking for (xcord+-1, ycord+-1,) etc, and recording the coordinates of the matrix 1s. However, I was wondering if there was a more efficient way of doing this.
I am new to matlab as well, so any suggestions are more than welcome in improving my code! Thanks!
Best Answer