private void fitnessUpdate() { Vector3 creature_position = gameObject.transform.position; Task t = Task.Factory.StartNew(() => { Vector2 proj = Line2D.projection(creature_position, m_controller.GoalLine); //Prox to Line // float lineProx = (9.8f-((proj - Vector2Calc.fromVector3(creature_position)).magnitude)); // float fitness = Mathf.Sign(lineProx) > 0 ? Mathf.Pow( lineProx, 2 ) : -Mathf.Pow( lineProx, 2 ); //Prox to Line + Distance From Origin // float lineProx = (9.8f-((proj - Vector2Calc.fromVector3(creature_position)).magnitude)); // float originDist = (Vector2.zero - Vector2Calc.fromVector3(creature_position)).magnitude; // float fitness = Mathf.Sign(lineProx*originDist) > 0 ? Mathf.Pow( lineProx*originDist, 2 ) : -Mathf.Pow( lineProx*originDist, 2 ); //Distance from origin only if within prox of line // float counting = (proj - Vector2Calc.fromVector3(creature_position)).magnitude > 1f ? 0 : 1; // float originDist = (Vector2.zero - Vector2Calc.fromVector3(creature_position)).magnitude; // float fitness = counting * originDist; //Distance from origin only if within prox of line and only above x axis float counting = (proj - Vector2Calc.fromVector3(creature_position)).magnitude > 1f ? 0 : 1; float negative = creature_position.x >= 0 ? 1 : -1; float originDist = (Vector2.zero - Vector2Calc.fromVector3(creature_position)).magnitude; float fitness = counting * originDist * negative; fit_samples++; m_fit_color = fitness; m_fitness += fitness; }); // if(m_fit_color > 0){ // m_renderer.color = new Color(0,Mathf.Clamp(0.2f+0.8f*(m_fit_color/98),0,1),0,1); // } else { // m_renderer.color = new Color(Mathf.Clamp(0.2f+(-0.8f)*(m_fit_color/98), 0, 1),0,0,1); // } //COLOR: Distance from origin only if within prox of line if (m_fit_color > 0f) { m_renderer.color = new Color(0, Mathf.Clamp(0.2f + 0.8f * (m_fit_color / 16), 0, 1), 0, 1); } else if (m_fit_color < 0f) { m_renderer.color = new Color(Mathf.Clamp(0.2f + (-0.8f) * (m_fit_color / 16), 0, 1), 0, 0, 1); } else { m_renderer.color = new Color(0, 0, 0.5f, 1); } }
private void fitnessUpdate() { Vector3 creature_position = gameObject.transform.position; //Prox to Line float fitlineProx = (Vector2Calc.fromVector3(gameObject.transform.position) - Line2D.projection(creature_position, m_controller.FitnessLine)).magnitude; float healthlineProx = (Vector2Calc.fromVector3(gameObject.transform.position) - Line2D.projection(creature_position, m_controller.HealthLine)).magnitude; Task t = Task.Factory.StartNew(() => { if ((fitlineProx < healthlineProx) || (healthlineProx > 1)) { float fitness = 10 - (fitlineProx * 10); m_fit_color = fitness; m_fitness += fitness; } else { if (m_heal_time++ < 2000) { m_heal_amount = 3 - (3 * (healthlineProx)); m_health.add(m_heal_amount); m_fit_color = 0; } else { m_fit_color = -10f; } } fit_samples++; }); // if(m_fit_color > 0){ // m_renderer.color = new Color(0,Mathf.Clamp(0.2f+0.8f*(m_fit_color/98),0,1),0,1); // } else { // m_renderer.color = new Color(Mathf.Clamp(0.2f+(-0.8f)*(m_fit_color/98), 0, 1),0,0,1); // } if (m_fit_color > 0f) { m_renderer.color = new Color(0, 0, Mathf.Clamp(0.2f + 0.8f * (m_fit_color / 10), 0, 1), 1); } else if (m_fit_color < 0f) { m_renderer.color = new Color(Mathf.Clamp(0.2f - 0.8f * (m_fit_color / 10), 0, 1), 0, 0, 1); } else { m_renderer.color = new Color(0, Mathf.Clamp(0.2f + 0.8f * (m_heal_amount / 3), 0, 1), 0, 1); } }