Пример #1
0
        /// <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;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Set target grid schema similar to source grid schema
 /// </summary>
 /// <param name="sourceGrid"></param>
 /// <param name="targetGrid"></param>
 private static void MatchSchema(Grid sourceGrid, Grid targetGrid)
 {
     while (targetGrid.RowCount < sourceGrid.RowCount)
     {
         Row newRow = new Row();
         for (int k = 0; k < targetGrid.ColumnCount; k++)
         {
             Cell newCell = new Cell(false);
             newRow.AddCell(newCell);
         }
         targetGrid.AddRow(newRow);
     }
     while (targetGrid.ColumnCount < sourceGrid.ColumnCount)
     {
         Cell cell = new Cell(false);
         for (int k = 0; k < targetGrid.RowCount; k++)
         {
             targetGrid[k].AddCell(cell);
         }
         targetGrid.ColumnCount += 1;
     }
 }
Пример #3
0
 /// <summary>
 /// Set target grid schema similar to source grid schema 
 /// </summary>
 /// <param name="sourceGrid"></param>
 /// <param name="targetGrid"></param>
 private static void MatchSchema(Grid sourceGrid, Grid targetGrid)
 {
     while (targetGrid.RowCount < sourceGrid.RowCount)
     {
         Row newRow = new Row();
         for (int k = 0; k < targetGrid.ColumnCount; k++)
         {
             Cell newCell = new Cell(false);
             newRow.AddCell(newCell);
         }
         targetGrid.AddRow(newRow);
     }
     while (targetGrid.ColumnCount < sourceGrid.ColumnCount)
     {
         Cell cell = new Cell(false);
         for (int k = 0; k < targetGrid.RowCount; k++)
         {
             targetGrid[k].AddCell(cell);
         }
         targetGrid.ColumnCount += 1;
     }
 }
Пример #4
0
 /// <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;
         }
     }
 }