public bool[,] checkCell() { int livingCount; bool[,] nextGen = new bool[arraySize, arraySize]; for (int rowIndex = 0; rowIndex < LivingCells.GetLength(0); rowIndex++) { for (int collIndex = 0; collIndex < LivingCells.GetLength(1); collIndex++) { livingCount = 0; for (int row = -1; row <= 1; row++) { for (int coll = -1; coll <= 1; coll++) { if (Mod((rowIndex + row), LivingCells.GetLength(0)) == (rowIndex + row) && Mod((collIndex + coll), LivingCells.GetLength(1)) == (collIndex + coll)) { if (LivingCells[rowIndex + row, collIndex + coll]) { livingCount++; } } } } nextGen = GenerateNextGen(rowIndex, collIndex, livingCount, nextGen); } } return(nextGen); }
//True = Added Cell, False = Removed Cell public bool AddOrRemoveCell(Cell newCell) { if (newCell.CheckForDuplicates(LivingCells.CellList)) { LivingCells.AddCell(newCell); return(true); } else { LivingCells.RemoveCell(newCell); return(false); } }
//True = keep iterating, False = stop iterating public bool Iterate() { LivingCells = new Population(LivingCells.Run(Rules)); LivingCells.CheckForDuplicates(); LivingCells.UpdateCellCount(); UpdateGridEvent(this, EventArgs.Empty); CurrentIteration++; if (CurrentIteration >= MaxIterations && MaxIterations != 0) { CurrentIteration = 0; return(false); } else { return(true); } }