2018-01-15 18:04 GMT+01:00 Photon <nico-braun@live.de>:
when I call the countNeighbours method i get an error: the block wants two arguments but I pass only one. This is probally because i want to pass x y but only really pass x wich ends up being a cell and not the index.
I still have trouble thinking it trough. The indicieDo: method seems to make the matrix bigger?! I don`t quite understand it.
It should not, and looking at the implementation, it just iterates with two loops 1 to number of rows times 1 to number of columns and calls your block argument with the pair of indexes.
There must be an easy way to to figure out if the suroundings are alive or not. I mean its all there what I need and in my mind its so easy to discribe it with normal words. But to tell the machine witth syntax is another thing really :/
About the surroundings, there is a nice method in Point Point>>eightNeighbors, that gives you the coordinates of the eight surrounding fields for example: (5@7) eightNeighbors "{(6@7). (6@8). (5@8). (4@8). (4@7). (4@6). (5@6). (6@6)}" with this method and if you iterate through all pairs of indices of the matrix, you can do your computation for every point, but you have to take care about the points that don't have valid matrix indices for some of their neighbours (like 0@0, the left and top neighbours may actually "on the other side of the matrix"). But you can take a look at SequenceableCollection>>atWrap: how it deals with "wrapping around".
what if i selected only one element with do:[] and let its tell me its idices. I store them in a temp object and then I check outside the block the neighbours and add to the counter. Once this is done I repeat as many times as their elements in the matrix?
Greetings
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html