
php我刚学这个没有多久,老师给了我一道题目,我不知道要怎么做,请大家帮帮我吧!谢了 题目是英文的。谢
WriteaprogramtosimulateasimplifiedversionofConway’sGameofLife.TheGameOfLifeisazeropla...
Write a program to simulate a simplified version of Conway’s Game of Life. The Game Of Life is a zero player game which starts from an initial (randomly generated) 2D array configuration and then evolves without any user input.
The simulation begins with a 16 x 16 2D array, which represents life. Each cell in the 2D array can be in one of two states: live or dead. Every cell in the 2D array can only interact with its surrounding 8 neighbours.
the program should randomly generate “dead” or “live” values for the initial configuration of the 2D array. Next, the program should generate a random number between 5 and 20, inclusive, which will be the number of times the simulation should run. For example, when 5 is randomly generated, the program should compute and display the next 5 steps of the 2D array configuration.
For each step of the simulation, the following rules must be applied to each cell:
Any “live” cell that has less than 2 “live” neighbour cells becomes “dead” due to under-population.
Any “live” cell that has 2 or 3 “live” neighbour cells remains “live”.
Any “live” cell that has more than 3 “live” neighbour cells becomes “dead” due to over-crowding.
Any “dead” cell that has exactly 3 “live” neighbour cells becomes “live” again due to reproduction.
Thus the simulation will run as follows:
• Show the initial configuration of the 2D array with the cells either “live” or “dead”
• Show the random number generated indicating the number of steps it will run
• For each step:
o Show the next configuration of the 2D array with the cells either “live” or “dead” based on the rules above.
the program should print the following statistics:
• Total number of initial “live” cells.
• Total number of initial “dead” cells.
• Total number of cells that went from “live” to “dead” after all the steps.
• Total number of cells that went from “dead” to “live” after all the steps. 展开
The simulation begins with a 16 x 16 2D array, which represents life. Each cell in the 2D array can be in one of two states: live or dead. Every cell in the 2D array can only interact with its surrounding 8 neighbours.
the program should randomly generate “dead” or “live” values for the initial configuration of the 2D array. Next, the program should generate a random number between 5 and 20, inclusive, which will be the number of times the simulation should run. For example, when 5 is randomly generated, the program should compute and display the next 5 steps of the 2D array configuration.
For each step of the simulation, the following rules must be applied to each cell:
Any “live” cell that has less than 2 “live” neighbour cells becomes “dead” due to under-population.
Any “live” cell that has 2 or 3 “live” neighbour cells remains “live”.
Any “live” cell that has more than 3 “live” neighbour cells becomes “dead” due to over-crowding.
Any “dead” cell that has exactly 3 “live” neighbour cells becomes “live” again due to reproduction.
Thus the simulation will run as follows:
• Show the initial configuration of the 2D array with the cells either “live” or “dead”
• Show the random number generated indicating the number of steps it will run
• For each step:
o Show the next configuration of the 2D array with the cells either “live” or “dead” based on the rules above.
the program should print the following statistics:
• Total number of initial “live” cells.
• Total number of initial “dead” cells.
• Total number of cells that went from “live” to “dead” after all the steps.
• Total number of cells that went from “dead” to “live” after all the steps. 展开
展开全部
给点分吧
写一个程序来模拟一个简化版本康威的生命游戏。生活的游戏是一零个玩家游戏,开始从最初的(随机)的二维数组配置和随后的发展没有任何用户输入。
仿真始于一个16×16的二维数组,它代表生命。每个细胞中的二维数组可以在一两个国家:活的或死的。每一个细胞在二维数组可以互动与周围的8个邻居。
程序随机生成的“死”或“活”的值的二维数组的初始配置。下一步,该程序应产生一个随机数之间的5和20,包容性,它会有多少次仿真运行。例如,当5个是随机产生的,该程序应计算和显示5个步骤的二维阵列配置。
每一步的仿真,以下规则必须应用到每个细胞:
任何“活”的细胞,有不少于2的“活”的邻居细胞变成“死”,由于under-population。
任何“活”的细胞有2个或3个“活”的邻居细胞仍然是“活”。
任何“活”的细胞,有超过3的“活”的邻居细胞变成“死”由于过度拥挤。
任何“死”细胞,正好有3个“活”的邻居细胞变成“活”,又由于繁殖。
因此,将模拟如下:
• 表明初始配置的二维数组的细胞可以“活”或“死”
• 显示的随机数生成的指示数的步骤,它将运行
• 的每一步:
哦, 显示下一个配置的二维数组的细胞可以“活”或“死”根据上述规则。
程序应该打印统计如下:
• 总人数的最初的“活”的细胞。
• 总人数的最初的“死”细胞。
• 总细胞数,从“活”到“死”后,所有的步骤。
• 总细胞数,从“死”到“活”后,所有的步骤。
写一个程序来模拟一个简化版本康威的生命游戏。生活的游戏是一零个玩家游戏,开始从最初的(随机)的二维数组配置和随后的发展没有任何用户输入。
仿真始于一个16×16的二维数组,它代表生命。每个细胞中的二维数组可以在一两个国家:活的或死的。每一个细胞在二维数组可以互动与周围的8个邻居。
程序随机生成的“死”或“活”的值的二维数组的初始配置。下一步,该程序应产生一个随机数之间的5和20,包容性,它会有多少次仿真运行。例如,当5个是随机产生的,该程序应计算和显示5个步骤的二维阵列配置。
每一步的仿真,以下规则必须应用到每个细胞:
任何“活”的细胞,有不少于2的“活”的邻居细胞变成“死”,由于under-population。
任何“活”的细胞有2个或3个“活”的邻居细胞仍然是“活”。
任何“活”的细胞,有超过3的“活”的邻居细胞变成“死”由于过度拥挤。
任何“死”细胞,正好有3个“活”的邻居细胞变成“活”,又由于繁殖。
因此,将模拟如下:
• 表明初始配置的二维数组的细胞可以“活”或“死”
• 显示的随机数生成的指示数的步骤,它将运行
• 的每一步:
哦, 显示下一个配置的二维数组的细胞可以“活”或“死”根据上述规则。
程序应该打印统计如下:
• 总人数的最初的“活”的细胞。
• 总人数的最初的“死”细胞。
• 总细胞数,从“活”到“死”后,所有的步骤。
• 总细胞数,从“死”到“活”后,所有的步骤。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询