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

Simplify will_drown [WIP] #551

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

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

Currently, will_drown looks like this:

bool will_drown(agent_type a) { //!OCLINT can't be simpler
  switch (a) {
    case agent_type::plankton:
      return false;
  case agent_type::worm:
    return false;
    case agent_type::bird:
      return false;
    case agent_type::cow:
      return true;
    case agent_type::giraffe:
      return true;
    case agent_type::crocodile:
      return false;
    case agent_type::chameleon:
      return true;
    case agent_type::fish:
      return false;
    case agent_type::whale:
      return false;
    case agent_type::goat:
      return true;
    case agent_type::spider:
      return true;
    case agent_type::octopus:
      return false;
    case agent_type::snake:
      return true;
    default:
      return true;
  }
}

It can be simpler. A messy incomplete code snippet with the main idea here:

#include <set>

bool will_drown(agent_type a) {
  //Agents that can drown
  const std::set<agent_type> s = { agent_type::cow, agent_type::giraffe };
  return s.count(a);
}

Describe the solution you'd like

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.