Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've made a simple game with a steering model that manage a crowd of agents. I use an genetic algorithm to find the best parameters to use in my system but I need to determine a fitness for each simulation. I know it's something like that:

number of collisions * time to reach goal * effort

But I don't know how to calculate the effort, is there a special way to do that ?

Here is what I've done so far:

// Evaluate the distance from agents to goal
Real totalDistance(0.0);
for (unsigned i=0; i<_agents.size(); i++)
    totalDistance += _agents[i]->position().distance(_agents[i]->_goal->position());

Real totalWallsCollision(0.0);
for (unsigned i=0; i<_agents.size(); i++)
    for (unsigned j=0; j<walls.size(); j++)
        if ( walls[j]->inside(_agents[i]->position()) )
            totalCollision += 1.0;

return totalDistance + totalWallsCollision;

Thanks for your help.

share|improve this question
up vote 2 down vote accepted

Effort will be specific to your simulation. You could do something like the sum of the distance each agent traveled. Or the sum of all the direction changes each agent had to make. It depends on what your definition of fitness is.

For either of the two above, you can just keep a running total for each agent, then add them all up, just as you do for distance:

Real totalEffort(0.0)
for (unsigned i=0; i<_agents.size(); i++)
    totalEffort+= _agents[i]->totalEffort();

return totalDistance + totalWallsCollision + totalEffort;

You could also try keeping a running total of work, so each step of your simulation, calculate aceleration * mass * distanceTraveled. Where distanceTraveled is the distance traveled since the last update. This will give you the total work (effort) that the agent exerted.

share|improve this answer
Thanks I already made that but it's not really what I expect. I've found a way to calculate the effort but I don't understand it correctly. It's effort = mass * integral( es + ew * |v|^2 dt ) where es = 2.23 and ew = 1.26 for a "normal" human walking. I don't know how to calculate this integral between 0 and my simulation time with the given speed v. When am I supposed to calculate the speed value because I only know the simulation time when it ends. Thanks. – Vodemki Dec 12 '12 at 18:05
The speed variable would be calculated per step of your simulation. You may just want to sum mass * acceleration or the force applied on each step. The es and ew are not really important unless you're comparing your results to other simulations that use those values. If you're just comparing to previous results in your own simulation, you shouldn't need them. – Byte56 Dec 12 '12 at 18:19
Thanks. My agent has a velocity which is a Vector2D, is there a way to get the acceleration with that ? – Vodemki Dec 12 '12 at 18:28
There was recently a question that will help you: How can I derive force vectors from velocity vectors – Byte56 Dec 12 '12 at 18:31
Ok got it. Thanks for your help. – Vodemki Dec 12 '12 at 18:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.