用 JavaScript 和 HTML5 Canvas 实现的元胞自动机
我用 JavaScript 实现了康威的生命游戏,但我没有看到相同的模式,例如高斯珀的滑翔机枪。我按照维基百科文章中描述的方式播种网格,但是枪从未发生过。
有人会看一下我的代码,看看它是否有什么问题,对实现有什么建议吗?
I implemented a Conway's Game of Life in JavaScript but I'm not seeing the same patterns such as Gosper's Glider Gun. I seed the grid the ways it's depicted in the Wikipedia article but, the gun never happens.
Will someone look at my code and see if there's anything wrong with it, any suggestions to the implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不是同时更新所有单元格,而是按顺序更新。在第一代中诞生的细胞在第一代其他细胞的计算中不会显得活着(它仍然算作死亡)。
创建一个名为 willBeAlive 的新属性,并使用它来保存单元格新计算的活动状态。一旦该代的所有计算完成,将每个单元格的alive属性设置为其willBeAlive属性并重绘。
以下是更改:
这是“Gosper's Glider Gun”的种子数组:
You are not updating all of the cells simultaneously, rather sequentially. A cell that is born in the first generation will not appear alive to the calculation of other cells of the first generation (it still counts as dead).
Create a new property called willBeAlive and use that to hold the cell's new calculated alive state. Once all the calculations for that generation are done, set each cell's alive property to its willBeAlive property and redraw.
Here are the changes:
and here is a seed array for "Gosper's Glider Gun":