Ejemplo n.º 1
0
    public void RuleSelection()
    {
        //ruleSetting();

        int index2 = dropdown_rule.value;

        if (index2 == 0)
        {
            // _usingRule= ruleStore[0];
            selectedRule = false;
        }
        if (index2 > 0)
        {
            _usingRule   = ruleStore[index2];
            selectedRule = true;
            ruleText.GetComponent <Text>().text = _usingRule.getInstruction(0).ToString() + "," + _usingRule.getInstruction(1).ToString()
                                                  + "," + _usingRule.getInstruction(2).ToString() + "," + _usingRule.getInstruction(3).ToString();
        }
    }
Ejemplo n.º 2
0
    // Calculate CA function
    void CalculateCA()
    {
        // Go over all the voxels stored in the voxels array
        for (int i = 1; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel> ().GetState();
                int        aliveNeighbours   = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        GameObject currentNeigbour      = voxelGrid [i + x, j + y, 0];
                        int        currentNeigbourState = currentNeigbour.GetComponent <Voxel> ().GetState();
                        aliveNeighbours += currentNeigbourState;
                    }
                }
                aliveNeighbours -= currentVoxelState;

                //CHANGE RULE BASED ON CONDITIONS HERE:
                GOLRule currentRule = rule1;
                //CHANGE RULE BASED ON CONDITIONS HERE:
                //..........

                if (currentFrame > 40)
                {
                    currentRule = rule2;
                }

                /*
                 * if (currentVoxelObj.GetComponent<Voxel>().GetAge()>3)
                 * {
                 *  currentRule = deathrule;
                 * }
                 *
                 * if (layerdensity < 0.2)
                 * {
                 *  currentRule = rule2;
                 * }
                 */
                //..........

                //get the instructions
                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);

                // Rule Set 1: for voxels that are alive
                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(0);
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(1);
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(0);
                    }
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(1);
                    }
                }

                //age - here is an example of a condition where the cell is "killed" if its age is above a threshhold
                // in this case if this rule is put here after the Game of Life rules just above it, it would override
                // the game of lie conditions if this condition was true

                /*
                 * if (currentVoxelObj.GetComponent<Voxel>().GetAge() > 5)
                 * {
                 *  currentVoxelObj.GetComponent<Voxel>().SetFutureState(0);
                 * }
                 */
            }
        }
    }
Ejemplo n.º 3
0
    // Calculate CA function
    void CalculateCA()
    {
        // Go over all the voxels stored in the voxels array


        for (int i = 1; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel>().GetState();
                int        aliveNeighbours   = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        GameObject currentNeigbour      = voxelGrid[i + x, j + y, 0];
                        int        currentNeigbourState = currentNeigbour.GetComponent <Voxel>().GetState();
                        aliveNeighbours += currentNeigbourState;
                    }
                }
                aliveNeighbours -= currentVoxelState;


                if (ConditionsToggles[0].isOn)
                {
                    RuleChangeOnFrm1();
                }

                if (ConditionsToggles[1].isOn)
                {
                    RuleChangeOnFrm2();
                }

                if (ConditionsToggles[2].isOn)
                {
                    RuleChangeOnDens1();
                }
                if (ConditionsToggles[3].isOn)
                {
                    RuleChangeOnDens2();
                }



                //get the instructions
                int inst0 = RuleInUse.getInstruction(0);
                int inst1 = RuleInUse.getInstruction(1);
                int inst2 = RuleInUse.getInstruction(2);
                int inst3 = RuleInUse.getInstruction(3);

                // Rule Set 1: for voxels that are alive
                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                }

                //age - here is an example of a condition where the cell is "killed" if its age is above a threshhold
                // in this case if this rule is put here after the Game of Life rules just above it, it would override
                // the game of lie conditions if this condition was true

                if (currentVoxelObj.GetComponent <Voxel>().GetAge() > MaxAgeAll)
                {
                    currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                }
                if (ConditionsToggles[4].isOn)
                {
                    if (currentVoxelObj.GetComponent <Voxel>().GetAge() > AgeDropdown.value + 1)
                    {
                        RuleChangeOnAge();
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
    // Calculate CA function
    void CalculateCA()
    {
        // Go over all the voxels stored in the voxels array
        for (int i = 1; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel>().GetState();
                int        aliveNeighbours   = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        GameObject currentNeigbour      = voxelGrid[i + x, j + y, 0];
                        int        currentNeigbourState = currentNeigbour.GetComponent <Voxel>().GetState();
                        aliveNeighbours += currentNeigbourState;
                    }
                }
                aliveNeighbours -= currentVoxelState;

                // GameObject ruleclass= GUI.GetComponent<GUI_Interface>().GetRule();
                //CHANGE RULE BASED ON CONDITIONS HERE:
                GOLRule currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().GetRule();
                //CHANGE RULE BASED ON CONDITIONS HERE:
                //..........



                if (currentFrame < 40)
                {
                    if (layerdensity < 0.05)
                    {
                        GoingToDead = true;
                        GoingToFull = false;
                        GoingToStay = false;
                    }
                    if (layerdensity >= 0.05 && layerdensity < 0.25)
                    {
                        GoingToDead = false;
                        GoingToFull = false;
                        GoingToStay = true;
                    }
                    if (layerdensity >= 0.25)
                    {
                        GoingToDead = false;
                        GoingToFull = true;
                        GoingToStay = false;
                    }
                    if (GoingToStay == true && averageVNdensity < 1.5)///切成VN更大的且能maintain的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(3);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToDead == true)  ///切成增长最大的rule,无论VN
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(7);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToDead == true && averageVNdensity < 1.5)  ///切成增长第二且VN大的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(1);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToFull == true) ///切成变少最快的rule,无论VN
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(5);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToFull == true && averageVNdensity < 1.5)  ///切成变少第二快且VN大的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(2);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                }
                if (currentFrame >= 40)
                {
                    if (layerdensity < 0.25)
                    {
                        GoingToDead = true;
                        GoingToFull = false;
                        GoingToStay = false;
                    }
                    if (layerdensity >= 0.25 && layerdensity < 0.3)
                    {
                        GoingToDead = false;
                        GoingToFull = false;
                        GoingToStay = true;
                    }
                    if (layerdensity >= 0.3)
                    {
                        GoingToDead = false;
                        GoingToFull = true;
                        GoingToStay = false;
                    }
                    if (GoingToStay == true)  //选增长稍大的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(6);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToStay == true && averageVNdensity > 2) //选VN最小的,且增长稍大的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(8);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToFull == true)  //选增长一般的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(4);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToFull == true && averageVNdensity > 1.7)  //选VN小的,且增长一般的rule
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(1);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToDead == true) //选增长最大的,无论VN
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(7);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                    if (GoingToDead == true && averageVNdensity > 1.5)  //选增长大的,且VN小的,----VN小的分数高,占70,,,layer大的分数高,占30
                    {
                        GUI_InterfaceRef.GetComponent <GUI_Interface>().ChangeRule(7);
                        currentRule = GUI_InterfaceRef.GetComponent <GUI_Interface>().ReturnChangeRule();
                    }
                }

                //if (currentVoxelObj.GetComponent<Voxel>().GetAge() > 3)
                //{
                //    currentRule = deathrule;
                //}

                //if (layerdensity > 0.2)
                //{
                //    currentRule = rule8;
                //}
                //if (layerdensity > 0.3&&averageVNdensity>2)
                //{
                //    currentRule = rule7;
                //}
                //if (layerdensity < 0.05)
                //{
                //    currentRule = rule3;
                //}
                //if (layerdensity < 0.1 && averageVNdensity > 1.5)
                //{
                //    currentRule = rule2;
                //}

                //..........

                //get the instructions
                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);

                // Rule Set 1: for voxels that are alive
                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)//if(aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                }

                //age - here is an example of a condition where the cell is "killed" if its age is above a threshhold
                // in this case if this rule is put here after the Game of Life rules just above it, it would override
                // the game of lie conditions if this condition was true

                if (currentVoxelObj.GetComponent <Voxel>().GetAge() > GUI_InterfaceRef.GetComponent <GUI_Interface>().GetAge())
                {
                    currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                }
            }
        }
    }
    // Calculate CA function
    void CalculateCA()
    {
        // Go over all the voxels stored in the voxels array
        for (int i = width / 2; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel> ().GetState();
                int        aliveNeighbours   = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        GameObject currentNeigbour      = voxelGrid [i + x, j + y, 0];
                        int        currentNeigbourState = currentNeigbour.GetComponent <Voxel> ().GetState();
                        aliveNeighbours += currentNeigbourState;
                        // >>> Counting until 9
                        //Debug.Log("alive neighbours : " + aliveNeighbours);
                    }
                }
                aliveNeighbours -= currentVoxelState;

                //CHANGE RULE BASED ON CONDITIONS HERE:
                GOLRule currentRule = rule1;
                //GOLRule currentRule = rule2;
                //GOLRule currentRule = rule3;
                //GOLRule currentRule = rule4;
                //GOLRule currentRule = rule5;

                //if (currentFrame > width/4 && currentFrame < width/2) currentRule = rule3;

                //if (currentFrame > width/3 && currentFrame < width/2) currentRule = rule2;

                //if (currentFrame > width /2 && currentFrame <60) currentRule = rule1;

                //if (currentFrame > 70) currentRule = rule5;
                // if (currentFrame == timeEnd-2) currentRule = lastRule;

                //if (currentVoxelObj.GetComponent<Voxel>().GetAge() == 10) currentRule = rule2;

                if (Input.GetKeyDown(KeyCode.R))
                {
                    currentRule = rule1;
                }
                if (Input.GetKeyDown(KeyCode.T))
                {
                    currentRule = rule2;
                }
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    currentRule = rule3;
                }
                if (Input.GetKeyDown(KeyCode.U))
                {
                    currentRule = rule4;
                }


                // if (currentFrame > 40) currentRule = rule2;

                //if(currentVoxelObj.GetComponent<Voxel>().GetAge()>3) currentRule = deathrule;

                //if(layerdensity < 0.2) currentRule = rule1;
                //if (layerdensity<0.2 && maxAge > 15) currentRule = rule4;
                //if (currentFrame > 30) currentRule = rule6;
                //if (maxAge == 17) currentRule = rule4;
                //if (layerdensity >0.2 &&) currentRule = rule1;
                if (currentFrame > 40)
                {
                    currentRule = rule2;
                }
                // if (layerdensity > .4) currentRule = rule1;
                //if (layerdensity<0.2 && currentFrame >30) currentRule = rule4;
                if (currentFrame == timeEnd - 2)
                {
                    currentRule = lastRule;
                }

                //get the instructions
                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);

                // Rule Set 1: for voxels that are alive
                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(0);
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(1);
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(0);
                    }
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel> ().SetFutureState(1);
                    }
                }


                //CalculateMesh();

                //age - here is an example of a condition where the cell is "killed" if its age is above a threshhold
                // in this case if this rule is put here after the Game of Life rules just above it, it would override
                // the game of lie conditions if this condition was true

                /*
                 * if (currentVoxelObj.GetComponent<Voxel>().GetAge() > 5)
                 * {
                 *  currentVoxelObj.GetComponent<Voxel>().SetFutureState(0);
                 * }
                 */
            }
        }
    }
    void CalculateVN()
    {
        // Go over all the voxels stored in the voxels array
        for (int i = 1; i < width / 2; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel>().GetState();
                int        aliveVNNeighbours = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        if (x == 0 || y == 0)
                        {
                            GameObject currentNeigbour      = voxelGrid[i + x, j + y, 0];
                            int        currentNeigbourState = currentNeigbour.GetComponent <Voxel>().GetState();
                            aliveVNNeighbours += currentNeigbourState;
                            // >>> Counting until 9
                            //Debug.Log("alive neighbours : " + aliveNeighbours);
                        }
                    }
                }
                aliveVNNeighbours -= currentVoxelState;
                GOLRule currentRule = rule4;

                //if (layerdensity < 0.2) currentRule = rule1;
                //if (layerdensity < 0.2 && maxAge > 15) currentRule = rule4;
                //if (currentFrame > 30) currentRule = rule6;
                //if (maxAge == 17) currentRule = rule4;


                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);

                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveVNNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveVNNeighbours >= inst0 && aliveVNNeighbours <= inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveVNNeighbours > inst1)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                    }
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveVNNeighbours >= inst2 && aliveVNNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                    }
                }
            }
        }
    }
    // Calculate CA function
    public void CalculateCA()
    {
        // Go over all the voxels stored in the voxels array
        for (int i = 1; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                GameObject currentVoxelObj   = voxelGrid[i, j, 0];
                int        currentVoxelState = currentVoxelObj.GetComponent <Voxel> ().GetState();
                int        aliveNeighbours   = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        GameObject currentNeigbour      = voxelGrid [i + x, j + y, 0];
                        int        currentNeigbourState = currentNeigbour.GetComponent <Voxel> ().GetState();
                        aliveNeighbours += currentNeigbourState;
                    }
                }



                aliveNeighbours -= currentVoxelState;

                //CHANGE RULE BASED ON CONDITIONS HERE:
                GOLRule currentRule = rule1;
                //CHANGE RULE BASED ON CONDITIONS HERE:
                //..........

                //   if (currentFrame > 10)
                //   {
                //       currentRule = rule2;

                //    }
                //         if (currentFrame > 20)
                //         {
                //             currentRule = rule1;


                //         }
                //         if (currentFrame > 30)
                //         {
                //             currentRule = rule2;

                //         }
                //         if (currentFrame > 40)
                //         {
                //             currentRule = rule1;
                //         }
                //         if (currentFrame > 50)
                //         {
                //             currentRule = rule2;
                //         }
                //if (currentFrame > 60)
                //{
                //    currentRule = rule1;
                //}

                /*
                 * if (currentVoxelObj.GetComponent<Voxel>().GetAge()>3)
                 * {
                 * currentRule = deathrule;
                 * }
                 *
                 * if (layerdensity < 0.2)
                 * {
                 * currentRule = rule2;
                 * }
                 */
                //..........

                //get the instructions
                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);

                Voxel wow;
                Voxel wuw;
                Voxel wew;
                Voxel rose;
                Voxel lilac;
                Voxel lily;
                Voxel tulip;
                Voxel orchid;

                wow = voxelGrid[i, j + 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox1(wow);

                wuw = voxelGrid[i + 1, j + 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox2(wuw);

                wew = voxelGrid[i + 1, j, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox3(wew);

                rose = voxelGrid[i - 1, j + 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox4(rose);

                lilac = voxelGrid[i - 1, j, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox5(lilac);

                lily = voxelGrid[i - 1, j - 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox6(lily);

                tulip = voxelGrid[i, j - 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox7(tulip);

                orchid = voxelGrid[i + 1, j - 1, 0].GetComponent <Voxel>();
                currentVoxelObj.GetComponent <Voxel>().setVox8(orchid);

                // Rule Set 1: for voxels that are alive
                if (currentVoxelState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                        // orchid.SetFutureState(0);

                        //activating color for different behaviours
                        //lily.SaveColor(1, 0, 0);
                        //orchid.SaveColor(0, 1, 0);
                    }
                    if (orchid.getDensity3dVN() <= 4)
                    {
                        orchid.SetFutureState(0);
                    }

                    if (lily.getDensity3dMO() >= 1)
                    {
                        lily.SetFutureState(0);
                    }
                    //if (lilac.getDensity3dMO() <= 3)
                    //{
                    //    lilac.SetFutureState(1);
                    //}
                    //if (rose.getDensity3dMO() >= 2)
                    //{
                    //    lily.SetFutureState(1);
                    //}

                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        //currentVoxelObj.GetComponent<Voxel> ().SetFutureState (1);
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                        // if (orchid.GetState() == 1)
                        // {
                        // if (orchid.GetAge()>=maxvoxage)
                        // {
                        //wuw.SetFutureState(1);
                        //    orchid.SetFutureState(1);
                        // }
                        lily.SetFutureState(1);
                        // if (lily.GetAge()>=maxvoxage)
                        // {
                        //      lily.SetFutureState(0);
                        //  }
                        // }
                        //  else
                        // {
                        //      lily.SetFutureState(0);
                        //  }
                        ///
                        ///
                        ///
                        ///
                        lilac.SetFutureState(1);
                        rose.SetFutureState(1);
                        ///
                        ///
                        ///
                        ///
                    }
                    //If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst2)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                        tulip.SetFutureState(1);
                    }
                }



                int wowage    = wow.GetComponent <Voxel>().GetAge();
                int wewage    = wew.GetComponent <Voxel>().GetAge();
                int wuwage    = wuw.GetComponent <Voxel>().GetAge();
                int roseage   = rose.GetComponent <Voxel>().GetAge();
                int lilacage  = lilac.GetComponent <Voxel>().GetAge();
                int lilyage   = lily.GetComponent <Voxel>().GetAge();
                int tulipage  = tulip.GetComponent <Voxel>().GetAge();
                int orchidage = orchid.GetComponent <Voxel>().GetAge();


                maxvoxage = currentVoxelObj.GetComponent <Voxel>().maxage;
                voxage    = currentVoxelObj.GetComponent <Voxel>().GetAge();



                if (voxage > maxvoxage)
                {
                    //if (aliveNeighbours <= 2)
                    //{
                    //    currentVoxelObj.GetComponent<Voxel>().SetFutureState(1);
                    //}
                    //if (aliveNeighbours == 4 || aliveNeighbours == 3)
                    //{
                    //    currentVoxelObj.GetComponent<Voxel>().SetFutureState(0);
                    //}
                    currentVoxelObj.GetComponent <Voxel>().SetFutureState(0);
                }
                if (wowage > maxvoxage)
                {
                    wow.SetFutureState(0);
                }
                if (wewage > maxvoxage)
                {
                    wew.SetFutureState(0);
                }
                if (wuwage > maxvoxage)
                {
                    wuw.SetFutureState(0);
                }
                if (roseage > maxvoxage)
                {
                    rose.SetFutureState(0);
                }
                if (lilacage > maxvoxage)
                {
                    lilac.SetFutureState(1);
                }
                if (lilyage > maxvoxage)
                {
                    lily.SetFutureState(0);
                }
                if (tulipage > maxvoxage)
                {
                    tulip.SetFutureState(0);
                }
                if (orchidage > maxvoxage)
                {
                    orchid.SetFutureState(0);
                }
                // Rule Set 2: for voxels that are death
                if (currentVoxelState == 0)
                {
                    //	// If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        currentVoxelObj.GetComponent <Voxel>().SetFutureState(1);
                        //if (wew.GetState() == 1)
                        //{
                        // rose.SetFutureState(1);
                        //wuw.SetFutureState(0);
                        //}
                        //else
                        //{
                        //    rose.SetFutureState(1);
                        //}
                        // wew.SetFutureState(1);
                    }
                }


                //age - here is an example of a condition where the cell is "killed" if its age is above a threshhold
                // in this case if this rule is put here after the Game of Life rules just above it, it would override
                // the game of lie conditions if this condition was true

                //if (currentVoxelObj.GetComponent<Voxel>().GetAge() > 5)
                //{
                //    currentVoxelObj.GetComponent<Voxel>().SetFutureState(0);
                //    ///
                //    ///
                //    ///
                //    ///
                //     wow.SetFutureState(1);
                //     wuw.SetFutureState(0);

                //}
            }
        }
    }
Ejemplo n.º 8
0
    void CalculateCaData()
    {
        //calculate data
        for (int i = 1; i < width - 1; i++)
        {
            for (int j = 1; j < length - 1; j++)
            {
                int currentVoxel          = VoxelStateStore[i, j, 0];
                int CurrentStructureState = currentVoxel;
                int aliveNeighbours       = 0;

                // Calculate how many alive neighbours are around the current voxel
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        int currentNeighbour     = VoxelStateStore[i + x, j + y, 0];
                        int CurrentNeighourState = currentNeighbour;
                        aliveNeighbours += CurrentNeighourState;
                    }
                }
                aliveNeighbours -= CurrentStructureState;

                if (c1 == true)
                {
                    RuleChangeOnFrm1();
                }
                if (c2 == true)
                {
                    RuleChangeOnFrm2();
                }
                if (c3 == true)
                {
                    RuleChangeOnDens1();
                }
                if (c4 == true)
                {
                    RuleChangeOnDens2();
                }
                if (c5 == true)
                {
                    if (VoxelAge[i, j, 0] > cdnAge5 && cdnAge5 > 0)
                    {
                        RuleChangeOnAge();
                    }
                }

                //get the instructions
                int inst0 = currentRule.getInstruction(0);
                int inst1 = currentRule.getInstruction(1);
                int inst2 = currentRule.getInstruction(2);
                int inst3 = currentRule.getInstruction(3);


                /////////////////////////////////////////////////////////////
                //Calculate state

                if (CurrentStructureState == 1)
                {
                    // If there are less than two neighbours I am going to die
                    if (aliveNeighbours < inst0)
                    {
                        FutureStructureState[i, j] = 0;
                    }
                    // If there are two or three neighbours alive I am going to stay alive
                    if (aliveNeighbours >= inst0 && aliveNeighbours <= inst1)
                    {
                        FutureStructureState[i, j] = 1;
                    }
                    // If there are more than three neighbours I am going to die
                    if (aliveNeighbours > inst1)
                    {
                        FutureStructureState[i, j] = 0;
                    }
                }
                // Rule Set 2: for voxels that are death
                if (CurrentStructureState == 0)
                {
                    // If there are exactly three alive neighbours I will become alive
                    if (aliveNeighbours >= inst2 && aliveNeighbours <= inst3)
                    {
                        FutureStructureState[i, j] = 1;
                    }
                }
                if (VoxelAge[i, j, 0] > ageLimit)
                {
                    FutureStructureState[i, j] = 0;
                }
            }
        }
    }