Getting Started with FLAME
79
(rabbitInformation_message);
}
/* If there is a rabbit close */
if(closest_rabbit_id != -1)
{
/* Is the closest rabbit in eating distance */
if(shortest_distance <= (fox_eat_length*fox_eat_length))
{
printf("Eat rabbit %d\n", closest_rabbit_id);
/* Send eaten message to rabbit */
add_rabbitEaten_message(closest_rabbit_id);
/* Move to rabbit position */
FOXX = closest_x;
FOXY = closest_y;
/* Increase life expectancy */
LIFEEXPECTANCY = LIFEEXPECTANCY + 10;
}
else /* Else chase closest rabbit */
{
/* Calculate angle to rabbit */
theta = atan((closest_y - FOXY)/(closest_x - FOXX));
/* Move run length of fox towards rabbit */
FOXX = FOXX + (fox_run_length * cos(theta));
FOXY = FOXY + (fox_run_length * sin(theta));
}
}
else
{
/* Move randomly */
FOXX = FOXX + (fox_run_length - (rand()/(double)(RAND_MAX)
*(fox_run_length*2.0)));
FOXY = FOXY + (fox_run_length - (rand()/(double)(RAND_MAX)
*(fox_run_length*2.0)));
}
/* Mirror location off boundary */
FOXX = handle_boundaryX(FOXX);
FOXY = handle_boundaryY(FOXY);
return 0;
}
/* Example Rabbit functions */
/** \fn Send message with rabbit location
*/
int rabbitInformation()
{
/* Send rabbit location message */
add_rabbitInformation_message(RABBITID, RABBITX, RABBITY);
return 0;
}
Précédent

- 108/329

Suivant