另一个游戏生活问题(无限网格)? [英] another Game of Life question (infinite grid)?

查看:251
本文介绍了另一个游戏生活问题(无限网格)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与康威生命游戏玩了,最近发现了一些令人惊讶的快速实现,如Hashlife和天啊。 (下载天哪此处 - http://golly.sourceforge.net/

I have been playing around with Conway's Game of life and recently discovered some amazingly fast implementations such as Hashlife and Golly. (download Golly here - http://golly.sourceforge.net/)

有一件事我无法解决,编码人员如何实现无限网格?我们不能让一个无限阵列的任何东西,如果你运行天哪,并得到了几个滑翔机飞了出去,过去的边缘,等待几分钟,放大右出,你会看到滑翔机还有在太空中跑出来的,那么神的名字就是这个无穷无尽的概念以编程方式处理?是否有很好的文件格式或什么?

One thing that I cant get my head around is how do coders implement the infinite grid? We can't keep an infinite array of anything, if you run golly and get a few gliders to fly off past the edges, wait for a few mins and zoom right out, you will see the gliders still there out in space running away, so how in gods name is this concept of infinity dealt with programmatically? Is there a well documented pattern or what?

非常感谢

推荐答案

(LivingNode,Coordinate)对的列表,而不是节点数组,其中每个无论是生还是死,我们只是改变坐标,而不是增加数组的大小。因此,所需的空间与 LivingNodes 的数量成正比。

It is possible to represent living nodes with some type of sparse matrix in this situation. For instance, if we store a list of (LivingNode, Coordinate) pairs instead of an array of Nodes where each is either living or dead, we are simply changing the Coordinates rather than increasing an array's size. Thus, the space required for this is proportional to the number of LivingNodes.

此解决方案不适用于说明生活节点数量在不断增加的状态,但它对滑翔机的效果非常好。

This solution doesn't work for states where the number of living nodes is constantly increasing, but it works very well for gliders.

编辑:我的头。结果是维基百科有一篇文章,展示了一个更加深思熟虑的解决方案。好吧! :)享受。

So that was off the top of my head. Turns out Wikipedia has an article that shows a much more well-thought out solution. Oh well! :) Enjoy.

这篇关于另一个游戏生活问题(无限网格)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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