void Start() { shipScripts = new CollisionTest[10]; shipScripts[0] = ship0.GetComponent <CollisionTest>(); shipScripts[1] = ship1.GetComponent <CollisionTest>(); shipScripts[2] = ship2.GetComponent <CollisionTest>(); shipScripts[3] = ship3.GetComponent <CollisionTest>(); shipScripts[4] = ship4.GetComponent <CollisionTest>(); shipScripts[5] = ship5.GetComponent <CollisionTest>(); shipScripts[6] = ship6.GetComponent <CollisionTest>(); shipScripts[7] = ship7.GetComponent <CollisionTest>(); shipScripts[8] = ship8.GetComponent <CollisionTest>(); shipScripts[9] = ship9.GetComponent <CollisionTest>(); currentState = State_Type.Simulation; }
void Update() { if (States(shipScripts) == 10) { currentState = State_Type.Iteration; } else { currentState = State_Type.Simulation; } switch (currentState) { case State_Type.Simulation: Debug.Log("Simulation!!!!!!!!!!"); break; case State_Type.Iteration: Debug.Log("Iteration!!!!!!!!!!!"); break; } }
// Use this for initialization void Start() { CurrrentState = State_Type.ChooseMenu; }
private void FixedUpdate() { switch (currentState) { case State_Type.Simulation: // Debug.Log("Simulation!!!!!!!!!!"); for (int i = 0; i < 10; i++) { motorScript.Run(i, motorScript.ship[i]); } if (States(shipScripts) == 10) { currentState = State_Type.Iteration; } break; case State_Type.Iteration: Debug.Log("Iteration ongoing"); if (!selecFlag && !crossFlag && !mutatFlag && !reposFlag && !resurFlag) { chromosomes = Selection(shipScripts, chromosomes, rand); selecFlag = true; } if (selecFlag && !crossFlag && !mutatFlag && !reposFlag && !resurFlag) { //chromosomes = Crossover(shipScripts, chromosomes, rand); chromosomes = Crossover2(chromosomes, rand); crossFlag = true; } if (selecFlag && crossFlag && !mutatFlag && !reposFlag && !resurFlag) { chromosomes = Mutation(chromosomes, rand1, rand2, rand3); mutatFlag = true; } if (selecFlag && crossFlag && mutatFlag && !reposFlag && !resurFlag) { Reposition(ship0, ship1, ship2, ship3, ship4, ship5, ship6, ship7, ship8, ship9); reposFlag = true; } if (selecFlag && crossFlag && mutatFlag && reposFlag && !resurFlag) { Resurrection(ship0, ship1, ship2, ship3, ship4, ship5, ship6, ship7, ship8, ship9); resurFlag = true; } if (States(shipScripts) == 0 && selecFlag && crossFlag && mutatFlag && reposFlag && resurFlag) { resurFlag = false; reposFlag = false; selecFlag = false; crossFlag = false; mutatFlag = false; currentState = State_Type.Simulation; } // for (int i = 0; i < 10; i++) motorScript.Run(i, motorScript.ship[i]); break; } ///<summary> /// Only for Test /// </summary> //if (IterationDone(shipScripts) == 10 && selectFlag) //{ // chromosomes = Selection(shipScripts, chromosomes, rand); // chromosomes = Crossover(shipScripts, chromosomes, rand); // chromosomes = Mutation(shipScripts, chromosomes, rand1, rand2, rand3); // selectFlag = false; //} //if (!selectFlag && stopFlag) //{ // for (int i = 0; i < 10; i++) // { // for (int k = 0; k < 10; k++) // { // if (i == 0) // { // GameObject obj = (GameObject)Instantiate(cube0); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 1) // { // GameObject obj = (GameObject)Instantiate(cube1); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 2) // { // GameObject obj = (GameObject)Instantiate(cube2); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 3) // { // GameObject obj = (GameObject)Instantiate(cube3); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 4) // { // GameObject obj = (GameObject)Instantiate(cube4); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 5) // { // GameObject obj = (GameObject)Instantiate(cube5); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 6) // { // GameObject obj = (GameObject)Instantiate(cube6); // //cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 7) // { // GameObject obj = (GameObject)Instantiate(cube7); // // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 8) // { // GameObject obj = (GameObject)Instantiate(cube8); // // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 9) // { // GameObject obj = (GameObject)Instantiate(cube9); // // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // } // } // stopFlag = false; //} }
void Start() { amoutIndi = 10; chromosomes = new List <Vector3> [10]; individuals = new Dictionary <int, List <Vector3> >(); cubes = new List <GameObject>(); currentState = State_Type.Simulation; shipScripts = new CollisionTest[10]; shipScripts[0] = ship0.GetComponent <CollisionTest>(); shipScripts[1] = ship1.GetComponent <CollisionTest>(); shipScripts[2] = ship2.GetComponent <CollisionTest>(); shipScripts[3] = ship3.GetComponent <CollisionTest>(); shipScripts[4] = ship4.GetComponent <CollisionTest>(); shipScripts[5] = ship5.GetComponent <CollisionTest>(); shipScripts[6] = ship6.GetComponent <CollisionTest>(); shipScripts[7] = ship7.GetComponent <CollisionTest>(); shipScripts[8] = ship8.GetComponent <CollisionTest>(); shipScripts[9] = ship9.GetComponent <CollisionTest>(); motorScript = this.GetComponent <Motor>(); rand = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); r1 = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); r2 = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); rand1 = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); rand2 = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); rand3 = new System.Random((int)DateTime.Now.Ticks % int.MaxValue); #region Generate chromosome for (int i = 0; i < 10; i++) { List <Vector3> chroms = new List <Vector3>(); for (int k = 1; k < 11; k++) { float x = (float)r1.NextDouble(); float z = (float)r2.NextDouble(); //Get random position at layer j (y = j) Vector3 pos = new Vector3(x * 100, k * 20, z * 100); //print("generate Pos = " + pos); chroms.Add(pos); } individuals.Add(i, chroms); } for (int j = 0; j < 10; j++) { foreach (List <Vector3> value in individuals.Values) { chromosomes[j] = value; j++; } } //for (int i = 0; i < 10; i++) //{ // for (int k = 0; k < 10; k++) // { // Debug.Log("Dictionary number: " + i + " Chromosome number: " + k + " Vector: " + chromosomes[i][k]); // } //} #endregion #region Indication cubes //for (int i = 0; i < 10; i++) //{ // for (int k = 0; k < 10; k++) // { // if (i == 0) // { // GameObject obj = (GameObject)Instantiate(cube0); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 1) // { // GameObject obj = (GameObject)Instantiate(cube1); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 2) // { // GameObject obj = (GameObject)Instantiate(cube2); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 3) // { // GameObject obj = (GameObject)Instantiate(cube3); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 4) // { // GameObject obj = (GameObject)Instantiate(cube4); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 5) // { // GameObject obj = (GameObject)Instantiate(cube5); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 6) // { // GameObject obj = (GameObject)Instantiate(cube6); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 7) // { // GameObject obj = (GameObject)Instantiate(cube7); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 8) // { // GameObject obj = (GameObject)Instantiate(cube8); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // else if (i == 9) // { // GameObject obj = (GameObject)Instantiate(cube9); // cubes.Add(obj); // obj.transform.position = chromosomes[i][k]; // } // } //} #endregion }