예제 #1
0
 void RuleChangeOnAge()
 {
     if (cdnRule5 > 0)
     {
         currentRule = ruleStore[cdnRule5 - 1];
     }
 }
예제 #2
0
 public void RuleChangeOnFrm2()
 {
     if (currentFrame > FrameDropdowns[1].value && ConditionRule[1].value > 0)
     {
         RuleInUse = ruleStore[ConditionRule[1].value - 1];
     }
 }
예제 #3
0
 public void RuleChangeOnAge()
 {
     if (ConditionRule[4].value > 0)
     {
         RuleInUse = ruleStore[ConditionRule[4].value - 1];
     }
 }
예제 #4
0
 void RuleChangeOnDens2()
 {
     if (layerdensity > conditionDensity[cdnDst4 - 1] && currentFrame > frameThershold && cdnRule4 > 0)
     {
         currentRule = ruleStore[cdnRule4 - 1];
     }
 }
예제 #5
0
 void RuleChangeOnDens1()
 {
     if (layerdensity < conditionDensity[cdnDst3 - 1] && currentFrame > frameThershold && cdnRule3 > 0)
     {
         currentRule = ruleStore[cdnRule3 - 1];
     }
 }
예제 #6
0
 void RuleChangeOnFrm2()
 {
     if (currentFrame > cdnFrm2 && cdnRule2 > 0)
     {
         currentRule = ruleStore[cdnRule2 - 1];
     }
 }
예제 #7
0
 void RuleChangeOnFrm1()
 {
     if (currentFrame > cdnFrm1 && cdnRule1 > 0)
     {
         currentRule = ruleStore[cdnRule1 - 1];
     }
     frameThershold = cdnFrm1;
 }
예제 #8
0
    public void RuleChangeOnDens2()
    {
        int index  = DensityDropdowns[1].value;
        int index2 = ConditionRule[3].value;

        if (layerdensity > conditionDensity[index] && currentFrame > FrameDropdowns [0].value && ConditionRule [3].value > 0)
        {
            RuleInUse = ruleStore[index2 - 1];
        }
    }
예제 #9
0
    public void SelectRule()
    {
        int index2 = RuleDropdown.value;

        if (index2 > 0)
        {
            ruleSelected = true;
            RuleInUse    = ruleStore[index2 - 1];
        }
        else
        {
            ruleSelected = false;
        }
    }
예제 #10
0
    public void SelectRule(int RuleIndex)
    {
        RuleDropdown.value = RuleIndex;

        if (RuleIndex > 0)
        {
            ruleSelected   = true;
            rulesText.text = rulesOptions[RuleIndex] + " Selected";
            RuleInUse      = ruleStore[RuleIndex - 1];
        }
        else
        {
            ruleSelected = false;
        }
    }
예제 #11
0
    public void QuickGame()
    {
        _usingRule = ruleStore[2];

        seedImage = SeedImage[1];

        rawSeedImage.GetComponent <RawImage>().texture = seedImage;
        width  = seedImage.width;
        length = seedImage.height;
        ResetCamera();
        selectedSeedImage = true;
        selectedRule      = true;

        SetTimeEnd();
        startedGame = true;
        stoppedGame = false;
    }
예제 #12
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();
        }
    }
    // 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);
                 * }
                 */
            }
        }
    }
    // 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);

                //}
            }
        }
    }
예제 #15
0
 public void ChangeRule(int _whichRule)
 {
     whichRule     = ruleStore[_whichRule];
     viewusingRule = _whichRule;
 }
    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);
                    }
                }
            }
        }
    }
예제 #17
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);
                }
            }
        }
    }
예제 #18
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);
                 * }
                 */
            }
        }
    }
예제 #19
0
    //pure data store without model
    public void getStructureData()
    {
        seedImage   = seedImageStore[imgIndex - 1];
        currentRule = ruleStore[ruleIndex - 1];

        width  = seedImage.width;
        length = seedImage.height;
        height = timeEnd;


        //create a database
        VoxelStateStore      = new int[width, length, height];
        VoxelAge             = new int[width, length, height];
        FutureStructureState = new int[width, length];

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < length; j++)
            {
                FutureStructureState[i, j] = 0;
                for (int k = 0; k < height; k++)
                {
                    if (k == 0)
                    {
                        // Create a new state based on the input image
                        float t = seedImage.GetPixel(i, j).grayscale;
                        if (t > 0.8f)
                        {
                            VoxelStateStore[i, j, k] = 0;
                        }
                        else
                        {
                            VoxelStateStore[i, j, k] = 1;
                        }
                    }
                    else
                    {
                        // Set the state to death
                        VoxelStateStore[i, j, k] = 0;
                    }
                    VoxelAge[i, j, k] = 0;
                }
            }
        }//createDataGrid

        for (int a = 0; a <= timeEnd; a++) //Calculate each frame
        {
            if (currentFrame < timeEnd)
            {
                CalculateCaData();

                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < length; j++)
                    {
                        VoxelStateStore[i, j, 0] = FutureStructureState[i, j];

                        if (VoxelStateStore[i, j, 0] == 1)
                        {
                            VoxelAge[i, j, 0]++;
                        }
                        if (VoxelStateStore[i, j, 0] == 0)
                        {
                            VoxelAge[i, j, 0] = 0;
                        }
                    }
                }
                SaveCaData();
                currentFrame++;
            }
        }

        connect3dVn();
    }