编码操练招式——康威生命游戏
2013-06-08 14:26
267 查看
康威生命游戏(Conway’s Game Of Life)
在一个有边界的二维网格(Grid)中,每个格子中生活着一个细胞(Cell);每个细胞只有两种生命状态:生(Alive)或死(Dead);网格矩阵边界之外没有细胞;
每天天一亮,所有格子里的细胞都统一通过下面4个规则,进化到下一代。每个细胞下一代的生命状态与自己和8个邻居进化前的生命状态有关:
1)对于活的细胞,若其活着的邻居过于稀少,以至于少于2个,那么它的下一代就死去了;
2)对于活的细胞,若其活着的邻居过于稠密,以至于多于3个,那么它的下一代也会死去;
3)对于活的细胞,若其活着的邻居恰好是2~3个,那么它的下一代会接着愉快地活着;
4)对于死的细胞,若其活着的邻居恰好是3个,那么它的下一代会复生。
Your task is to write a program to calculate the next generation of Conway's game of life, given any starting position. You start with a two dimensional grid of cells, where each cell is either alive or dead. The grid is finite, and no life can exist off
the edges. When calculating the next generation of the grid, follow these four rules:
1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
2. Any live cell with more than three live neighbours dies, as if by overcrowding.
3. Any live cell with two or three live neighbours lives on to the next generation.
4. Any dead cell with exactly three live neighbours becomes a live cell.
Examples: * indicates live cell, . indicates dead cell
Example input: (4 x 8 grid)
4 8
........
....*...
...**...
........
Example output:
4 8
........
...**...
...**...
........
(英文资料来源:http://www.cyber-dojo.com/setup/show)
在一个有边界的二维网格(Grid)中,每个格子中生活着一个细胞(Cell);每个细胞只有两种生命状态:生(Alive)或死(Dead);网格矩阵边界之外没有细胞;
每天天一亮,所有格子里的细胞都统一通过下面4个规则,进化到下一代。每个细胞下一代的生命状态与自己和8个邻居进化前的生命状态有关:
1)对于活的细胞,若其活着的邻居过于稀少,以至于少于2个,那么它的下一代就死去了;
2)对于活的细胞,若其活着的邻居过于稠密,以至于多于3个,那么它的下一代也会死去;
3)对于活的细胞,若其活着的邻居恰好是2~3个,那么它的下一代会接着愉快地活着;
4)对于死的细胞,若其活着的邻居恰好是3个,那么它的下一代会复生。
Your task is to write a program to calculate the next generation of Conway's game of life, given any starting position. You start with a two dimensional grid of cells, where each cell is either alive or dead. The grid is finite, and no life can exist off
the edges. When calculating the next generation of the grid, follow these four rules:
1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
2. Any live cell with more than three live neighbours dies, as if by overcrowding.
3. Any live cell with two or three live neighbours lives on to the next generation.
4. Any dead cell with exactly three live neighbours becomes a live cell.
Examples: * indicates live cell, . indicates dead cell
Example input: (4 x 8 grid)
4 8
........
....*...
...**...
........
Example output:
4 8
........
...**...
...**...
........
(英文资料来源:http://www.cyber-dojo.com/setup/show)
相关文章推荐
- 康威生命游戏(Conway's Game of Life)的一种实现
- 约翰·康威的 生命游戏
- 康威生命游戏 Conway's game of life
- 康威生命游戏 第一部分-基本功能实现(C++ & Windows SDK)
- 康威生命游戏 第二部分-设置界面和存档功能
- python 实现康威生命游戏
- 编码操练招式——网球计分
- 练手:康威生命游戏demo
- 康威生命游戏的学习
- 康威生命游戏的简单实现
- 山寨腾讯“爱消除”游戏之生命特效
- LINQ 实现的生命游戏
- “生命游戏”的多线程算法思考[转]
- QT 生命游戏模拟
- 生命游戏
- 生命游戏
- “生命游戏”的多线程算法思考
- 【USACO3.3.5】游戏(区间dp的滚动数组与编码问题)
- 生命游戏的屏保
- [LeetCode] Game of Life 生命游戏