John Conway’s game of life的C语言

来源:百度知道 编辑:UC知道 时间:2024/05/22 05:34:16
传说中著名的生命游戏,具体要求如下:
Write a C program that will play John Conway’s game of life. This game is a game of solitare that is played on a two dimensional array. Use a square array that has dimensions of at least 9 by 9. Each position in the array has two possible states: occupied and vacant. The game itself is played by progressing from “generation” to “generation”. Where a “generation” is one set of array values.
The program is to start from an initial generation (given below) and display the next ten generations.

The rules for progressing from generation to generation are:

1) survival:
if a position is occupied and has 2 or 3 neighbours then it survives to the next generation.

2) death:
if a position is occupied and has any other number of neighbours (0, 1, 4, 5, 6, 7, 8) then it becomes vacant in the next generation.

3) birth:
if a position is vacant and it has exactly three neighbours then it is occupied in the next

二维数组当然要先初始化了,你只要控制最后print的范围就行了。

这道题的情况,要将数组定义为22×22,初始化的时候每个元素都定为".",这样就不需要考虑边际情况了。

一个函数可以处理的,就是for循环套for循环。。。

progressing from “generation