Skip to content

Conversation

@JeremyFan
Copy link

Hi Marijn,
When count neighbors, the cells at the end of right would count with the cells at the start of next row.
20150506141703
in the end of the inner loop, 'x1' will be 'width', then 'x1+y1*width' will be next row. So I ignore this condition.

@marijnh
Copy link
Owner

marijnh commented May 8, 2015

Doesn't the fact that the loop only goes to Math.min(width, x + 1) already take care of this?

@JeremyFan
Copy link
Author

Maybe no...say width is 30, when x is 29, count neighbors. than the loop will be for (var x1 =28; x1 <=30; x1++), so still loop 3 times, and in the last time,x1 is 30, equals to width, x1 + y1 * width will be (y1+1)*width, means first cell in next row.

I test the situation in the picture. when the threes live cells in first column, the cell with blue border will be live in next generation...

@marijnh
Copy link
Owner

marijnh commented May 8, 2015

Good point! Since I'm using <=, I should be clipping to width - 1 and height - 1. Attached patch fixes this.

@marijnh marijnh closed this May 8, 2015
@JeremyFan
Copy link
Author

Oh, you're great. And thanks for this awesome book!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants