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

Write 'get_agent_reproduction_health' #540

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

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

Currently, there is this if statement to determine if an agent can reproduce:

  if ((m_type == agent_type::grass && m_health > 100.0) ||
      (m_type == agent_type::tree && m_health > 500.0) ||
      (m_type == agent_type::cow && m_health > 100.0) ||
      (m_type == agent_type::cactus && m_health > 100.0))
  {
    // ...
  }

This should be simplified to:

  if (m_health > get_agent_reproduction_health(m_type)
  {
    // ...
  }

Describe the solution you'd like

double get_agent_reproduction_health(const agent_type t) noexcept

It should return the same values as currently in the if statement

As shown above

  //#define FIX_ISSUE_540
  #ifdef FIX_ISSUE_540
  {
    assert(get_agent_reproduction_health(agent_type::cactus) == 100.0);
    assert(get_agent_reproduction_health(agent_type::cow) == 100.0);
    assert(get_agent_reproduction_health(agent_type::grass) == 100.0);
    assert(get_agent_reproduction_health(agent_type::tree) == 500.0);
  }
  #endif // FIX_ISSUE_540

Remove the lines with preprocessor directives (#define, #ifdef and #endif).

If the tests pass, you did it :+1:

Describe alternatives you've considered

None.

Additional context

None.

richelbilderbeek commented 5 years ago

@Rijk-van-Putten: well done, don't forget to add the header :+1:

If you did so, I will check again :rainbow:

richelbilderbeek commented 5 years ago

I am unsure what the state of this Issue, will keep Rijk assigned and move this to In Progress.

richelbilderbeek commented 5 years ago

Awesomely done!