【发布时间】:2014-09-26 12:10:29
【问题描述】:
我的任务是创建一个根据某些给定规则模拟细胞生长的程序。为此,我必须创建一个 2D 数组,并根据给定的概率用 Cell 对象填充它,这些对象要么是活的,要么是死的。到目前为止,我已经能够创建我认为这些对象的数组,但我不确定我将如何使用我被赋予的概率来分配“死亡” "或每个对象的"正常"状态。这是我到目前为止所做的(我知道的不多……):
public class CellGrid
{
// Store the cells of the game in this 2D array
private Cell[][] cells;
/**
* Contructor for a CellGrid. Populates the grid with cells that will be
* living and normal (with probability given by lifeChance) or dead. Cells
* will NOT start mutated.
*
* @param size
* the size of the grid will be size x size
* @param lifeChance
* the probability of each cell starting out alive
* @param mutationChance
* the probability that (when required) each cell will mutate
*/
public CellGrid(int size, double lifeChance, double mutationChance)
{
Cell[][] cells = new Cell[size][size];
//populates the array with new Cell objects
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cells[i][j]= new Cell();
}
}
【问题讨论】:
标签: java arrays object multidimensional-array