world::max_energy: Implement upper limit for agent's energy

This commit is contained in:
Petr Baudis 2011-12-03 15:47:00 +01:00
parent a5745ea516
commit 04a475efbe
2 changed files with 3 additions and 0 deletions

View file

@ -94,6 +94,8 @@ void
agent::chenergy(int delta)
{
energy += delta;
if (energy > world::max_energy)
energy = world::max_energy;
if (energy <= 0)
die();
}

View file

@ -4,6 +4,7 @@
struct world {
const static int newborn_energy = 5000;
const static int herb_energy = 1000;
const static int max_energy = 20000;
const static int move_cost = -50;
const static int attack_cost = -400;