richelbilderbeek / djog_unos_2018

Project by the Uno's at DJOG 2018-2019: Nature Zen
GNU General Public License v3.0
6 stars 2 forks source link

Put biological constants in biology classes #549

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

Is your feature request related to a problem? Please describe.

Currently, agent::eat has these magic constants:

    // Focal agent will eat the prey
    // As in any food chain, energy is lost: the predator gains less energy
    // than the prey gains
    m_health += 0.2;
    m_stamina += 0.2;
    other.set_health(other.get_health() - 2.0);

One should avoid magic constants (e.g. an

Also, we cannot test for the sanity of these consants

Describe the solution you'd like

void test_biology()
{
  const biology b;
  //#define FIX_ISSUE_549_A
  #ifdef FIX_ISSUE_549_A
  {
    assert(b.get_health_increase_when_eating() == 0.2);
  }
  #endif // FIX_ISSUE_549_A

  //#define FIX_ISSUE_549_B
  #ifdef FIX_ISSUE_549_B
  {
    assert(b.get_stamina_increase_when_eating() == 0.2);
  }
  #endif // FIX_ISSUE_549_B

  //#define FIX_ISSUE_549_C
  #ifdef FIX_ISSUE_549_C
  {
    assert(b.get_health_decrease_when_eaten() == 2.0);
  }
  #endif // FIX_ISSUE_549_C
}

For example:

    m_health += 0.2;

should become:

    m_health += biology().get_health_increase_when_eating();

Describe alternatives you've considered

None.

Additional context

None.

richelbilderbeek commented 5 years ago

Brilliant!