I've been messing around with the initialisation of Conway's Game of Life and I'm running into some problems. I can't for the life of me figure out why the number of 'alive neighbour particles' (I'm calling this 'positionSum') isn't being counted correctly. I have the following MATLAB code.
I'm starting with a simple 3x3 grid to get my code working.
R = 3; C = 3; % row and column numbers
X = rand(R, C); % generates random grid
Y = X < 0.5; % creates array of logicals
A = Y;
imshow(Y, 'InitialMagnification', 'fit') % shows initial cell configuration
north = [R, 1:R-1]; % north neighbour
east = [2:C, 1]; % east neighbour
south = [2:R, 1]; % south neighbour
west = [C, 1:C-1]; % west neighbour
% gives the total number of live neighbours
positionSum = A(north, :) + A(south, :) + A(:, east) + A(:, west) ...
+ A(north, east) + A(north, west) + A(south, east) + A(south, west)
Using this process I believe I'm getting incorrect totals.
For a 3x3 checkerboard with white in the upper left (as seen here) I get the following counts:
4 5 4
5 4 5
4 5 4