Commit 25ec082f authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

Merge branch 'snakes_permanently_loose_mass' into 'dev'

Snakes permanently loose mass

See merge request GPN18Programmierspiel/gameserver!21
parents f3caa3c1 dcbcdba3
......@@ -146,6 +146,8 @@ void Field::consumeFood(void)
}
}
}
b->getSnake()->ensureSizeMatchesMass();
}
createStaticFood(newStaticFood);
updateMaxSegmentRadius();
......@@ -211,6 +213,9 @@ void Field::moveAllBots(void)
killBot(victim, victim);
}
}
// adjust size to new mass
victim->getSnake()->ensureSizeMatchesMass();
}
}
......
......@@ -66,7 +66,6 @@ real_t Snake::maxRotationPerStep(void)
void Snake::consume(const Food& food)
{
m_mass += food.getValue();
ensureSizeMatchesMass();
}
std::size_t Snake::move(real_t targetAngle, bool boost)
......@@ -165,6 +164,8 @@ std::size_t Snake::move(real_t targetAngle, bool boost)
m_boostedLastMove = boost;
m_mass *= (1.0 - config::SNAKE_SURVIVAL_LOSS_FACTOR);
return m_segments.size(); // == number of new segments at head
}
......@@ -204,7 +205,7 @@ void Snake::convertToFood(const std::shared_ptr<Bot> &hunter) const
}
}
void Snake::dropFood(float_t value)
void Snake::dropFood(real_t value)
{
Vector2D dropOffset = (m_segments.end() - 1)->pos() - (m_segments.end() - 2)->pos();
Vector2D dropPos = (m_segments.end() - 1)->pos() + dropOffset.normalized() * 5;
......@@ -220,8 +221,6 @@ void Snake::dropFood(float_t value)
if(m_mass < 1e-6) {
m_mass = 1e-6;
}
ensureSizeMatchesMass();
}
real_t Snake::getConsumeRadius()
......
......@@ -52,12 +52,6 @@ class Snake
real_t m_boostedLastMove = false; //!< Track if the snake boosted during the last move
real_t m_foodToDrop = 0;
/*!
* Updates the length of m_segments and calculates the current m_segmentRadius
*/
void ensureSizeMatchesMass(void);
public:
/*!
* Construct a unit snake (1 segment at 0/0, heading 0°).
......@@ -67,6 +61,11 @@ class Snake
Snake(Field *field, const Vector2D &start_pos, real_t start_mass,
real_t start_heading);
/*!
* Updates the length of m_segments and calculates the current m_segmentRadius
*/
void ensureSizeMatchesMass(void);
/*!
* Consume the given food piece.
*/
......
......@@ -48,6 +48,12 @@ namespace config {
// Part of Snake's mass to drop in every frame the boost is on.
static const real_t SNAKE_BOOST_LOSS_FACTOR = 5e-3;
// Snakes continuously loose mass. This parameter adjust the part of mass
// lost every movement (==frame). The mass is not dropped, but simply lost.
// 1e-5 means that a mass 100k-Snake has to eat food of value 1 on average every
// frame to keep its mass.
static const real_t SNAKE_SURVIVAL_LOSS_FACTOR = 1e-5;
// Mass below which Snake dies through starvation
static const real_t SNAKE_SELF_KILL_MASS_THESHOLD = 1.0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment