/// <summary> /// Check if rule satisfies to expand row /// </summary> /// <param name="inputGrid"></param> /// <param name="outputGrid"></param> /// <param name="rowId"></param> private static void CheckRowGrowth(Grid inputGrid, Grid outputGrid, int rowId) { //Create a whole new row in the beginning or end if rule is satified for any of the cell Boolean rowCreatedFlag = false; //Boolean IsPreviousCellsFilled = false; // start with the index 1 until 1 less than last index as index 0 and last index cannot have 3 live adjacent cell in any case // This index 0 and last index must be included if rule is changed in future; dead can alive with 2 live adjacent cells for (int j = 1; j < inputGrid.ColumnCount - 1; j++) { if (Rule.CountAliveNeighbours(inputGrid, new CoOrdinates(rowId, j)) == 3) { if (rowCreatedFlag == false) { Row newRow = new Row(); //if (IsPreviousCellsFilled == false) //{ for (int k = 0; k < outputGrid.ColumnCount; k++) { // Fill all cells with false Cell newDeadCell = new Cell(false); newRow.AddCell(newDeadCell); } //IsPreviousCellsFilled = true; //} if (rowId == -1) { outputGrid.InsertRow(0, newRow); } else { outputGrid.AddRow(newRow); } rowCreatedFlag = true; } int XAxis = (rowId == -1) ? 0 : outputGrid.RowCount - 1; outputGrid[XAxis, j].IsAlive = true; } } }