public override void StepForward(int x, int y, BaseCell[,] oldGrid, BaseCell[,] nextGrid) { var count = GetNeighbors(x, y, oldGrid).Count(c => c is OnCell); if (count < 2 || count >= 4) { nextGrid[x, y] = new OffCell(); } }
public override void StepForward(int x, int y, BaseCell[,] oldGrid, BaseCell[,] nextGrid) { if (y - 1 >= 0) { var cellBelow = oldGrid[x, y - 1]; if (cellBelow is Fire || cellBelow is OffCell) { nextGrid[x, y] = new OffCell(); nextGrid[x, y - 1] = new Sand(); } else if (cellBelow is Water) { nextGrid[x, y] = new Water(); nextGrid[x, y - 1] = new Sand(); } } }
public LifeModel(int x, int y) { MaxX = x; MaxY = y; Grid = new BaseCell[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { Grid[i, j] = ChooseCell(i); } } for (int i = 0; i < x; i++) { Grid[0, i] = new OffCell(); Grid[i, 0] = new OffCell(); Grid[x - 1, i] = new OffCell(); Grid[i, y - 1] = new OffCell(); } }
public override void StepForward(int x, int y, BaseCell[,] oldGrid, BaseCell[,] nextGrid) { //falls if (!oldGrid[x, y - 1] is Sand && !oldGrid[x, y - 1] is Ice && !oldGrid[x, y - 1] is Water) //can't go through these cells { newGrid[x, y] = new OffCell(); //turn old cell (above) off? newGrid[x, y - 1] = new Water(); } //kills fire for (int i = -1; i < +2; i++) { for (int j = -1; j < +2; j++) //iterate over neighbors { if (oldGrid[i, j] is Fire) { nextGrid[i, j] = new OffCell(); //turn off all fire neighbors } } } }