Ejemplo n.º 1
0
        protected virtual void expand(GrowthStrategy strategy)
        {
            int growAmount = 0;

            if (strategy == GrowthStrategy.Single)
            {
                growAmount = 1;
            }
            if (strategy == GrowthStrategy.Tenth)
            {
                growAmount = capacity / 10;
            }
            if (strategy == GrowthStrategy.Quarter)
            {
                growAmount = capacity / 4;
            }
            if (strategy == GrowthStrategy.Half)
            {
                growAmount = capacity / 2;
            }
            if (strategy == GrowthStrategy.Double)
            {
                growAmount = capacity * 2;
            }
            addNewObjects(growAmount);
        }
Ejemplo n.º 2
0
        private void solveInternal(GrowthStrategy growthStrategy, Grain[,] tab2, int i, int j)
        {
            if (!growthStrategy.canChangeGrain(grains[i, j]))
            {
                tab2[i, j].index = grains[i, j].index;
                tab2[i, j].stan  = grains[i, j].stan;
                return;
            }

            int gora  = j - 1;
            int dol   = j + 1;
            int prawy = i + 1;
            int lewy  = i - 1;

            //perdiodyczny warunek brzegowy
            if (i == 0)
            {
                lewy = width - 1;
            }
            if (i == width - 1)
            {
                prawy = 0;
            }
            if (j == 0)
            {
                gora = height - 1;
            }
            if (j == height - 1)
            {
                dol = 0;
            }

            Grain[] neighborhood = growthStrategy.getNeighborhood(grains, i, j, lewy, gora, dol, prawy);

            Grain grain = growthStrategy.apply(neighborhood, grains[i, j]);

            tab2[i, j].index = grain.index;
            tab2[i, j].stan  = grain.stan;
        }