Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public int NextAt(int i, int j, int[,] current)
        {
            //get current state
            int state = current[i, j];

            //get local neighborhood data
            int sumMO     = GetNeighborSum(i, j, current, Neighborhoods.MooreR1);
            int sumVNPair = GetNeighborSum(i, j, current, Neighborhoods.VonNeumannPair1);

            //choose an instruction set
            GOLInstructionSet instructionSet = _instSetMO1;

            // collect relevant analysis results
            CellLayer[] layers    = _analyser.Layers;
            int         currIndex = _analyser.CurrentLayerIndex;

            float currStackDensity = _analyser.StackDensity;
            float prevLayerDensity = 1.0f;
            int   prevCellAge      = 0;

            // get attributes of corresponding cell on previous layer (if it exists)
            if (currIndex > 0)
            {
                var prevLayer = layers[currIndex - 1];
                prevLayerDensity = prevLayer.Density;
                prevCellAge      = prevLayer.Cells[i, j].Age;
            }

            /*
             * if (currentlayerdensity < .17)
             * {
             *  instructionSet = _instSetMO3;
             * }
             *
             * if (currentlayerdensity >= .17 && currentlayerdensity<.2)
             * {
             *  instructionSet = _instSetMO1;
             * }
             *
             * if (currentlayerdensity >.2)
             * {
             *  instructionSet = _instSetMO2;
             * }
             */

            /*
             * if(state==0 && sumVNPair == 2)
             * {
             *  return 1;
             * }
             *
             * if (state == 1 && sumVNPair == 2)
             * {
             *  return 0;
             * }
             */


            /*
             * if(currentlevel <= 40)
             * {
             *  instructionSet = _instSetMO1;
             * }
             *
             * if (currentlevel > 40 && currentlevel<65)
             * {
             *  instructionSet = _instSetMO2;
             * }
             *
             * if (currentlevel >= 65)
             * {
             *  instructionSet = _instSetMO3;
             * }
             */


            int output = 0;

            //if current state is "alive"
            if (state == 1)
            {
                if (sumMO < instructionSet.getInstruction(0))
                {
                    output = 0;
                }

                if (sumMO >= instructionSet.getInstruction(0) && sumMO <= instructionSet.getInstruction(1))
                {
                    output = 1;
                }

                if (sumMO > instructionSet.getInstruction(1))
                {
                    output = 0;
                }
            }

            //if current state is "dead"
            if (state == 0)
            {
                if (sumMO >= instructionSet.getInstruction(2) && sumMO <= instructionSet.getInstruction(3))
                {
                    output = 1;
                }
                else
                {
                    output = 0;
                }
            }

            return(output);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public int NextAt(Index2 index, int[,] current)
        {
            //get current state
            int state = current[index.I, index.J];

            //get local neighborhood data
            int sumMO     = GetNeighborSum(index, current, Neighborhoods.MooreR1);
            int sumVNPair = GetNeighborSum(index, current, Neighborhoods.VonNeumannPair1);

            //choose an instruction set
            GOLInstructionSet instructionSet = _instSetIncrease1;

            // collect relevant analysis results
            CellLayer[] layers       = _model.Stack.Layers;
            int         currentLayer = _model.CurrentLayer;

            float prevLayerDensity;
            int   prevCellAge;

            // get attributes of corresponding cell on the previous layer (if it exists)
            if (currentLayer > 0)
            {
                var prevLayer = layers[currentLayer - 1];
                prevLayerDensity = prevLayer.Density;
                prevCellAge      = prevLayer.Cells[index.I, index.J].Age;
            }
            else
            {
                prevLayerDensity = 1.0f;
                prevCellAge      = 0;
            }


            //new rule
            if (currentLayer < 10)
            {
                instructionSet = _instSetIncrease1;
            }
            else
            {
                if (prevLayerDensity < 0.1 && prevLayerDensity >= 0.05)
                {
                    instructionSet = _instSetIncrease3;
                }

                else if (prevLayerDensity >= 0.2)
                {
                    instructionSet = _instSetDecrease1;
                }

                else
                {
                    instructionSet = _instSetStripeImage;
                }
            }


            int output = 0;

            //if current state is "alive"
            if (state == 1)
            {
                if (sumMO < instructionSet.getInstruction(0))
                {
                    output = 0;
                }

                if (sumMO >= instructionSet.getInstruction(0) && sumMO <= instructionSet.getInstruction(1))
                {
                    output = 1;
                }

                if (sumMO > instructionSet.getInstruction(1))
                {
                    output = 0;
                }
            }

            //if current state is "dead"
            if (state == 0)
            {
                if (sumMO >= instructionSet.getInstruction(2) && sumMO <= instructionSet.getInstruction(3))
                {
                    output = 1;
                }
                else
                {
                    output = 0;
                }
            }

            return(output);
        }
Example #3
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="i"></param>
            /// <param name="j"></param>
            /// <param name="current"></param>
            /// <returns></returns>
            public int NextState(Index2 index, int[,] current)
            {
                if (_dna != _model.Stack.DNA)
                {
                    _dna = _model.Stack.DNA;
                }

                //get current state
                int state = current[index.I, index.J];

                //get local neighborhood data
                int sumMO     = GetNeighborSum(index, current, Neighborhoods.MooreR1);
                int sumVNPair = GetNeighborSum(index, current, Neighborhoods.VonNeumannPair1);

                //choose an instruction set
                GOLInstructionSet instructionSet = _instSetMO1;

                // collect relevant analysis results
                CellLayer[] layers       = _model.Stack.Layers;
                int         currentLayer = _model.CurrentLayer;

                float prevLayerDensity;
                int   prevCellAge;

                // get attributes of corresponding cell on the previous layer (if it exists)
                if (currentLayer > 0)
                {
                    var prevLayer = layers[currentLayer - 1];
                    prevLayerDensity = prevLayer.Density;
                    prevCellAge      = prevLayer.Cells[index.I, index.J].Age;
                }
                else
                {
                    prevLayerDensity = 1.0f;
                    prevCellAge      = 0;
                }

                /*
                 * if (currentlayerdensity < .17)
                 * {
                 *  instructionSet = _instSetMO3;
                 * }
                 *
                 * if (currentlayerdensity >= .17 && currentlayerdensity<.2)
                 * {
                 *  instructionSet = _instSetMO1;
                 * }
                 *
                 * if (currentlayerdensity >.2)
                 * {
                 *  instructionSet = _instSetMO2;
                 * }
                 */

                /*
                 * if(state==0 && sumVNPair == 2)
                 * {
                 *  return 1;
                 * }
                 *
                 * if (state == 1 && sumVNPair == 2)
                 * {
                 *  return 0;
                 * }
                 */


                //example of using Gene from DNA
                if (currentLayer <= _dna.GetGene(4))
                {
                    instructionSet = _instSetMO2;
                }

                float threshholdValue = (float)_dna.GetGene(5) / 100f;

                if (prevLayerDensity <= threshholdValue)
                {
                    instructionSet = _instSetMO2;
                }



                int output = 0;

                //if current state is "alive"
                if (state == 1)
                {
                    if (sumMO < instructionSet.getInstruction(0))
                    {
                        output = 0;
                    }

                    if (sumMO >= instructionSet.getInstruction(0) && sumMO <= instructionSet.getInstruction(1))
                    {
                        output = 1;
                    }

                    if (sumMO > instructionSet.getInstruction(1))
                    {
                        output = 0;
                    }
                }

                //if current state is "dead"
                if (state == 0)
                {
                    if (sumMO >= instructionSet.getInstruction(2) && sumMO <= instructionSet.getInstruction(3))
                    {
                        output = 1;
                    }
                    else
                    {
                        output = 0;
                    }
                }

                return(output);
            }
            /// <summary>
            ///
            /// </summary>
            /// <param name="i"></param>
            /// <param name="j"></param>
            /// <param name="current"></param>
            /// <returns></returns>
            public int NextAt(Index2 index, int[,] current)
            {
                //get current state
                int state = current[index.I, index.J];

                //get local neighborhood data
                int sumMO     = GetNeighborSum(index, current, Neighborhoods.MooreR1);
                int sumVNPair = GetNeighborSum(index, current, Neighborhoods.VonNeumannPair1);

                //choose an instruction set
                GOLInstructionSet instructionSet = _instSetMO1;

                // GOLInstructionSet instr1 = instructionSetArray[Mathf.RoundToInt(_dna.GetGene(0))];
                //GOLInstructionSet instr2 = instructionSetArray[Mathf.RoundToInt(_dna.GetGene(1))];
                //float densityThreshhold = _dna.GetGene(2);

                // collect relevant analysis results
                CellLayer[] layers       = _model.Stack.Layers;
                int         currentLayer = _model.CurrentLayer;

                float prevLayerDensity;
                int   prevCellAge;

                // get attributes of corresponding cell on the previous layer (if it exists)
                if (currentLayer > 0)
                {
                    var prevLayer = layers[currentLayer - 1];
                    prevLayerDensity = prevLayer.Density;
                    prevCellAge      = prevLayer.Cells[index.I, index.J].Age;
                }
                else
                {
                    prevLayerDensity = 1.0f;
                    prevCellAge      = 0;
                }

                /*
                 * if (currentlayerdensity < .17)
                 * {
                 *  instructionSet = _instSetMO3;
                 * }
                 *
                 * if (currentlayerdensity >= .17 && currentlayerdensity<.2)
                 * {
                 *  instructionSet = _instSetMO1;
                 * }
                 *
                 * if (currentlayerdensity >.2)
                 * {
                 *  instructionSet = _instSetMO2;
                 * }
                 */

                /*
                 * if(state==0 && sumVNPair == 2)
                 * {
                 *  return 1;
                 * }
                 *
                 * if (state == 1 && sumVNPair == 2)
                 * {
                 *  return 0;
                 * }
                 */


                /*
                 * if(currentlevel <= 40)
                 * {
                 *  instructionSet = _instSetMO1;
                 * }
                 *
                 * if (currentlevel > 40 && currentlevel<65)
                 * {
                 *  instructionSet = _instSetMO2;
                 * }
                 *
                 * if (currentlevel >= 65)
                 * {
                 *  instructionSet = _instSetMO3;
                 * }
                 */


                //float density = _analyser.MeanStackDensity;


                //Change the Model with Mean Stack Density

                /*
                 * if (density > densityThreshhold)
                 * {
                 *  instructionSet = instr1;
                 * }
                 * else
                 * {
                 *  instructionSet = instr2;
                 * }
                 *
                 *
                 *
                 * if (currentLayer == 39)
                 * {
                 *  Debug.Log("current layer is: " + currentLayer);
                 *  //Debug.Log($"Density GA Threshold: {densityThreshhold}");
                 *  Debug.Log("density is: " + density);
                 * }
                 */

                int output = 0;

                //if current state is "alive"
                if (state == 1)
                {
                    if (sumMO < instructionSet.getInstruction(0))
                    {
                        output = 0;
                    }

                    if (sumMO >= instructionSet.getInstruction(0) && sumMO <= instructionSet.getInstruction(1))
                    {
                        output = 1;
                    }

                    if (sumMO > instructionSet.getInstruction(1))
                    {
                        output = 0;
                    }
                }

                //if current state is "dead"
                if (state == 0)
                {
                    if (sumMO >= instructionSet.getInstruction(2) && sumMO <= instructionSet.getInstruction(3))
                    {
                        output = 1;
                    }
                    else
                    {
                        output = 0;
                    }
                }

                return(output);
            }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public int NextAt(Index2 index, int[,] current)
        {
            //get current state
            int state = current[index.I, index.J];

            //get local neighborhood data
            int sumMO     = GetNeighborSum(index, current, Neighborhoods.MooreR1);
            int sumVNPair = GetNeighborSum(index, current, Neighborhoods.VonNeumannPair1);

            //choose an instruction set
            GOLInstructionSet instructionSet = _instSetStable1;

            // collect relevant analysis results
            CellLayer[] layers       = _model.Stack.Layers;
            int         currentLayer = _model.CurrentLayer;

            float prevLayerDensity;
            int   prevCellAge;

            // get attributes of corresponding cell on the previous layer (if it exists)
            if (currentLayer > 0)
            {
                var prevLayer = layers[currentLayer - 1];
                prevLayerDensity = prevLayer.Density;
                prevCellAge      = prevLayer.Cells[index.I, index.J].Age;
            }
            else
            {
                prevLayerDensity = 1.0f;
                prevCellAge      = 0;
            }

            Dropdown myDropdown = GameObject.Find("Rule").GetComponent <Dropdown>();

            if (myDropdown.value == 1)
            {
                instructionSet = _instSetStable2;
            }
            if (myDropdown.value == 2)
            {
                instructionSet = _instSetStable3;
            }
            if (myDropdown.value == 3)
            {
                instructionSet = _instSetStable4;
            }
            if (myDropdown.value == 4)
            {
                instructionSet = _instSetStable5;
            }

            //垂直生长&成柱子
            if (myDropdown.value == 5)
            {
                instructionSet = _instSetVerticle;
            }
            if (myDropdown.value == 6)
            {
                instructionSet = _instSetColumn;
            }

            //增长生长
            if (myDropdown.value == 7)
            {
                instructionSet = _instSetIncrease1;
            }
            if (myDropdown.value == 8)
            {
                instructionSet = _instSetIncrease2;
            }
            if (myDropdown.value == 9)
            {
                instructionSet = _instSetIncrease3;
            }
            if (myDropdown.value == 10)
            {
                instructionSet = _instSetIncrease4;
            }

            //减少生长
            if (myDropdown.value == 11)
            {
                instructionSet = _instSetDecrease1;
            }
            if (myDropdown.value == 12)
            {
                instructionSet = _instSetDecrease2;
            }

            //死亡
            if (myDropdown.value == 13)
            {
                instructionSet = _instSetDead;
            }

            //桌面
            if (myDropdown.value == 14)
            {
                instructionSet = _instSetOriginalImage;
            }

            if (myDropdown.value == 15)
            {
                instructionSet = _instSetStripeImage;
            }

            //line_outside
            if (myDropdown.value == 16)
            {
                instructionSet = _instSetIncrease4;//1234
                if (currentLayer >= 20)
                {
                    instructionSet = _instSetDecrease2;//2333
                }
                if (currentLayer >= 40)
                {
                    instructionSet = _instSetStable3;//3322
                }
                if (prevLayerDensity < 0.08)
                {
                    instructionSet = _instSetStable3;//3322
                }
                if (prevLayerDensity >= 0.08)
                {
                    instructionSet = _instSetDecrease2;//2333
                }
            }

            //自定义
            if (myDropdown.value == 0)
            {
                instructionSet = _instSetDecrease2;
            }

            int output = 0;

            //if current state is "alive"
            if (state == 1)
            {
                if (sumMO < instructionSet.getInstruction(0))
                {
                    output = 0;
                }

                if (sumMO >= instructionSet.getInstruction(0) && sumMO <= instructionSet.getInstruction(1))
                {
                    output = 1;
                }

                if (sumMO > instructionSet.getInstruction(1))
                {
                    output = 0;
                }
            }

            //if current state is "dead"
            if (state == 0)
            {
                if (sumMO >= instructionSet.getInstruction(2) && sumMO <= instructionSet.getInstruction(3))
                {
                    output = 1;
                }
                else
                {
                    output = 0;
                }
            }

            return(output);
        }