优化Conway的“生命游戏” [英] Optimizing Conway's 'Game of Life'

查看:238
本文介绍了优化Conway的“生命游戏”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要尝试,我(不久前)执行康威的生命游戏(我知道的这个的相关问题!)。

To experiment, I've (long ago) implemented Conway's Game of Life (and I'm aware of this related question!).

我的执行情况保持2阵列布尔值,再presenting了最后的状态的工作,而状态更新(2个阵列被交换在每次迭代)。虽然这是相当快的,我经常在想,如何来优化它。

My implementation worked by keeping 2 arrays of booleans, representing the 'last state', and the 'state being updated' (the 2 arrays being swapped at each iteration). While this is reasonably fast, I've often wondered about how to optimize this.

一种想法,例如,将是precompute在迭代n了所述区域可以的在迭代被修改(N + 1)(因此,如果一个小区不属于此类一个区域,它甚至不会被考虑修饰迭代(N + 1))。我知道,这是非常模糊的,我从来没有花时间去详谈......

One idea, for example, would be to precompute at iteration N the zones that could be modified at iteration (N+1) (so that if a cell does not belong to such a zone, it won't even be considered for modification at iteration (N+1)). I'm aware that this is very vague, and I never took time to go into the details...

你有什么想法(或经验!)如何去优化(速度)的生命迭代游戏?

Do you have any ideas (or experience!) of how to go about optimizing (for speed) Game of Life iterations?

推荐答案

我会从另一个问题引用我的答案,因为我提的章节有一些非常有趣和微调的解决方案。一些实施细节在C和/或组件,是的,但在大多数情况下的算法,可以用任何语言工作:

I am going to quote my answer from the other question, because the chapters I mention have some very interesting and fine-tuned solutions. Some of the implementation details are in c and/or assembly, yes, but for the most part the algorithms can work in any language:

章节 17 和的18 的   迈克尔Abrash的<一个href="http://www.gamedev.net/page/resources/_/reference/programming/140/283/graphics-programming-black-book-r1698">Graphics   程序员黑皮书是一   最有趣的读取我曾经   了。这是思维的教训   外箱。全书   确实很大,但最终的优化   解决方案,以生命的游戏是   编程不可思议位。

Chapters 17 and 18 of Michael Abrash's Graphics Programmer's Black Book are one of the most interesting reads I have ever had. It is a lesson in thinking outside the box. The whole book is great really, but the final optimized solutions to the Game of Life are incredible bits of programming.

这篇关于优化Conway的“生命游戏”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆