bprentice wrote:The archive YinYangFire.zip contains the complete Java source code...
Oops... duh... I didn't read your post carefully enough.
I notice that the pictures above don't seem to be similar....
Yeah that's another oops. Those "untested changes" I refer to in my original post are indeed wrong. Here is a cut-and-paste directly from my working Processing code. As you can see, the multiplicand is 8, not 9. Sorry about that!
Code: Select all
for (int x=0; x<latticeCols; x++) {
for (int y=0; y<latticeRows; y++) {
int cellSum = 0; // We'll count the neighbours
int l = (x + latticeCols - 1) & latticeColMask;
int r = (x + latticeCols + 1) & latticeColMask;
int u = (y + latticeRows - 1) & latticeRowMask;
int d = (y + latticeRows + 1) & latticeRowMask;
cellSum = cells[a][l][u] + cells[a][x][u] + cells[a][r][u] +
cells[a][l][y] + cells[a][r][y] +
cells[a][l][d] + cells[a][x][d] + cells[a][r][d];
int result = cells[a][x][y];
if ((result << 3) + 2 >= cellSum) {
result = (result + numStatesMask) & numStatesMask;
}
else {
result++;
}
cells[b][x][y] = result;
} // End of y loop
} // End of x loop
EDIT:
Wait, no, I changed my code so it matched what you have, and it seems to work. Here is a cut-and-paste showing these changes:
Code: Select all
for (int x=0; x<latticeCols; x++) {
for (int y=0; y<latticeRows; y++) {
int cellSum = 0; // We'll count the neighbours
int l = (x + latticeCols - 1) & latticeColMask;
int r = (x + latticeCols + 1) & latticeColMask;
int u = (y + latticeRows - 1) & latticeRowMask;
int d = (y + latticeRows + 1) & latticeRowMask;
cellSum = cells[a][l][u] + cells[a][x][u] + cells[a][r][u] +
cells[a][l][y] + cells[a][x][y] + cells[a][r][y] +
cells[a][l][d] + cells[a][x][d] + cells[a][r][d];
int result = cells[a][x][y];
if ((cells[a][x][y] * 9) + 2 >= cellSum) {
result = (result + numStatesMask) & numStatesMask;
}
else {
result++;
}
cells[b][x][y] = result;
} // End of y loop
} // End of x loop