public void UpdateField() { Field.Iteration += 1; Field TempField = new Field(new TwoIntegerVariable { X = Field.Cells.GetLength(0), Y = Field.Cells.GetLength(1) }); for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Cell c = new Cell(); TempField.Cells[x, y] = new Cell(); CellUpdate Update = new CellUpdate(c); Update.ChangeStatus(Field.Cells[x, y].IsAlive); Update.ChangeStatus(new Neighbors(Field.Cells).GetNeighborCount(x, y)); //Update.ChangeStatus(Neighbors().GetNeighborCount(x, y)); bug is here Update = new CellUpdate(TempField.Cells[x, y]); Update.ChangeStatus(c.IsAlive); } } int AliveCells = new AliveCells(Field.Cells).GetAliveCellsCount(); Field.Cells = TempField.Cells; }
public void CreateBlinker() { for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Field.Cells[x, y] = new Cell(); CellUpdate = new CellUpdate(Field.Cells[x, y]); if (x == 2 && ((y == 1) || (y == 2) || (y == 3))) { CellUpdate.ChangeStatus(true); } else { CellUpdate.ChangeStatus(false); } } } }
public void RandomPopulation() { Random r = new Random(); for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Field.Cells[x, y] = new Cell(); CellUpdate = new CellUpdate(Field.Cells[x, y]); if (r.Next(2) == 1) { CellUpdate.ChangeStatus(true); } else { CellUpdate.ChangeStatus(false); } } } }