tresinformal / drakkar

The tresinformal video game called 'Drakkar'
GNU General Public License v3.0
11 stars 4 forks source link

There is a maximum size a player can reach #726

Closed TheoPannetier closed 1 year ago

TheoPannetier commented 1 year ago

Context

Players are so far able to reach disproportionate sizes by continuously eating the same weaker player. This may no longer present an issue once we have some buffer time between two successive collisions + growth (e.g. #695), but for now it would be best to cap a player's max size to a reasonable* size. Rm later on if appropriate.

*you decide on what's reasonable!

Test

#ifdef FIX_ISSUE_726
  // (726) There is a maximum size a player can reach
  {
    player p;
    // How many growth cycles to max size?
    const double init_size = p.get_diameter();
    const double max_size = p.get_max_size();
    const double diff_size = max_size - init_size;
    assert(diff_size > 0);
    const double growth_factor = p.get_growth_factor();
    const int nb_cycles = static_cast<int>(std::ceil(diff_size / growth_factor));

    for (int i = 0; i < nb_cycles; i++)
    {
      p.grow();
    }
    p.grow(); // to be sure we should exceed max size
    assert(p.get_diameter() == max_size);
  }
#endif // FIX_ISSUE_726
TheoPannetier commented 1 year ago

Done!