/// <summary> /// /// </summary> private void HandleKeyPress() { // Reset model if (Input.GetKeyDown(KeyCode.Space)) { _model.ResetModel(); } // Update display mode if (Input.GetKeyDown(KeyCode.Alpha1)) { _display.DisplayMode = CellDisplayMode.Age; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { _display.DisplayMode = CellDisplayMode.LayerDensity; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { _display.DisplayMode = CellDisplayMode.NeighborDensity; } else if (Input.GetKeyDown(KeyCode.Alpha0)) { _display.DisplayMode = CellDisplayMode.Alive; } }
/// <summary> /// /// </summary> private void Update() { //check if stack is finished building //if build not complete, leave function if (_model.BuildComplete == false) { return; } //if stack building is complete, get fitness / update if (_model.BuildComplete == true) { //calculate fitness _analyser.Fitness(); //move the stack position var generations = _population.Population.Count + 1; Vector3 vector = new Vector3(1.5f * (_currentStack.RowCount) * (_curCount - 1), 0, 1.5f * (_currentStack.ColumnCount)); _currentStack.transform.localPosition = vector; _currentStack.transform.parent = gameObject.transform; //add stack to current generation AddStackToGeneration(_currentStack); _curCount++; //if count == popsize recalculate the mating pool if (_curCount == _genSize) { //add generation to the population history AddGenToPopulation(_currentGeneration); //run natural selection to generate breeding pool UpdateMatingPool(); //reset current population array _currentGeneration = new CellStack[_genSize]; //reset popcounter _curCount = 0; //move population Vector3 vec = new Vector3(0, 0, 1.5f * (_currentStack.ColumnCount)); foreach (var stack in _population.Population) { stack.transform.localPosition += vec; } } //breed new dna from mating pool IDNAF childdna = Breed(); //turn off/deactivate the stack _currentStack.gameObject.SetActive(false); Debug.Log("Generation: " + generations + ", Stack: " + _curCount + " | Fitness= " + _currentStack.Fitness); //reset the stack and insert new dna _currentStack = Instantiate(_stackPrefab); _currentStack.SetDNA(childdna); _model.SetStack(_currentStack); //synthesize 4 images from child gene Texture2D texture1 = _seeds[Mathf.RoundToInt(childdna.GetGene(0))]; Texture2D texture2 = _seeds[Mathf.RoundToInt(childdna.GetGene(1))]; Texture2D texture3 = _seeds[Mathf.RoundToInt(childdna.GetGene(2))]; Texture2D texture4 = _seeds[Mathf.RoundToInt(childdna.GetGene(3))]; Texture2D combined = ImageSynthesizer.CombineFour(texture1, texture2, texture3, texture4, _currentStack.RowCount, _currentStack.ColumnCount); //place the synthesized image into the stack _currentStack.SetSeed(combined); //resets/initializes the model using the synthesized image _model.ResetModel(combined); //_model.ResetModel(); //Debug.Log("I reseted the model"); } }