public override void OnInspectorGUI()
    {
        PlantGeneration myObject = (PlantGeneration)target;


        EditorGUI.BeginChangeCheck();
        base.OnInspectorGUI();

        if (EditorGUI.EndChangeCheck())
        {
            myObject.Initialize();
        }


        if (GUILayout.Button("Force Initialization"))
        {
            myObject.Initialize();
        }



        if (GUILayout.Button("UpdateMesh"))
        {
            if (!hasBeenInitialized)
            {
                myObject.Initialize();
                hasBeenInitialized = true;
            }
            else
            {
                myObject.UpdateMesh();
            }
        }
    }
Exemple #2
0
        public void Part1()
        {
            var plants = new PlantGeneration(_initialState, _rules);

            while (plants.Generation < 20)
            {
                plants = plants.Evolve();
            }
            Assert.Equal(3059, plants.SumPlants);
        }
Exemple #3
0
        public void Part2()
        {
            var plants           = new PlantGeneration(_initialState, _rules);
            var targetGeneration = 50000000000;

            var lastCycleGrowth = 0L;
            var lastCycle       = plants.SumPlants;
            var stagnatedCycles = 0;

            while (plants.Generation < targetGeneration)
            {
                plants = plants.Evolve();
                var tmpSum  = plants.SumPlants;
                var tmpDiff = tmpSum - lastCycle;
                if (tmpDiff == lastCycleGrowth)
                {
                    if (stagnatedCycles >= 5)
                    {
                        // Stagnated
                        break;
                    }
                    stagnatedCycles += 1;
                }
                else
                {
                    stagnatedCycles = 0;
                }
                lastCycle       = tmpSum;
                lastCycleGrowth = tmpDiff;
            }

            var remainingGenerations = targetGeneration - plants.Generation;
            var result = plants.SumPlants + (remainingGenerations * lastCycleGrowth);

            Assert.Equal(3650000001776L, result);
        }