Ejemplo n.º 1
0
        public async Task FillListAsync(int height, bool losowo = true)
        {
            ///  lblResult.Text = "Tworzenie zarodków.... ";
            // btnDraw.Enabled = false;
            nonUsedGrains.Clear();
            if (losowo)
            {
                var watch1 = System.Diagnostics.Stopwatch.StartNew();
                Parallel.For(0, height, (i, ParallelLoopState) =>
                {
                    for (int j = 0; j < WidthSize; j++)
                    {
                        if (gr.grid[i, j].isEmpty && (gr.grid[i, j].X == 0 || Neighborhood.haveNeighborhood(gr.grid, i, j)))
                        {
                            nonUsedGrains.Add(gr.grid[i, j]);
                        }
                    }
                });
            }
            else
            {
                bool flaga     = true;
                int  iteratorr = 0;
                int  pomValue  = (WidthSize - 1) / LayerGerne;
                var  watch1    = System.Diagnostics.Stopwatch.StartNew();


                for (int i = 0; i < height; i++)
                {
                    if (pomValue > WidthSize)
                    {
                        pomValue = 0;
                    }
                    if (gr.grid[i, pomValue].isEmpty && (Neighborhood.haveNeighborhood(gr.grid, i, pomValue) || gr.grid[i, pomValue].X == 0))
                    {
                        nonUsedGrains.Add(gr.grid[i, pomValue]);
                        pomValue += (WidthSize) / LayerGerne;
                        i         = 0;
                        //  }



                        if (nonUsedGrains.Count == LayerGerne)
                        {
                            break;
                        }

                        // }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void growthStep()
        {
            Parallel.For(0, ActualHeightOfLayers, i =>
            {
                for (int j = 0; j < temp.GetLength(1); j++)
                {
                    if (temp[i, j].isEmpty)
                    {
                        int counterWinner       = 0;
                        List <Grain> neighbours = Neighborhood.GetNeighbours(temp[i, j], temp, i, j, type, bc, temp.GetLength(1), ActualHeightOfLayers);
                        Grain winner            = temp[i, j];
                        foreach (Grain item in neighbours)
                        {
                            if (item.ID != 0 && item.numberOfLayer == ActualLayerNumber)
                            {
                                int counter = 0;
                                foreach (Grain itemNext in neighbours)
                                {
                                    if (item.ID == itemNext.ID)
                                    {
                                        counter++;
                                    }

                                    if (counter > counterWinner)
                                    {
                                        counterWinner = counter;
                                        winner        = item;
                                    }
                                }
                            }
                        }
                        if (!winner.isEmpty)
                        {
                            grains[i, j] = new Grain(winner);
                        }
                    }
                }
            });
        }