80
X-Machines for Agent-Based Modeling: FLAME Perspectives
/** \fn Dodge_foxes()
* \brief Read fox locations and dodge
*/
int dodgeFoxes()
{
/* Use idea of force from foxes to move rabbits */
double fox_x_force = RABBITX;
double fox_y_force = RABBITY;
/* Angle to move rabbit, calculated from fox force */
double theta;
/* Distance from current agent to agent sending message */
double current_distance_squared;
/* Fox count */
int foxes = 0;
/* Check if eaten, by reading eaten messages */
rabbitEaten_message = get_first_rabbitEaten_message();
while(rabbitEaten_message)
{
/* If message relates to me then die */
if(rabbitEaten_message->rabbitID == RABBITID)
{
printf("Rabbit %d dies\n", RABBITID);
return 1;
}
rabbitEaten_message = get_next_rabbitEaten_message
(rabbitEaten_message);
}
/* Dodge foxes, by reading fox location messages */
foxInformation_message = get_first_foxInformation_message();
while(foxInformation_message)
{
current_distance_squared =
(foxInformation_message->foxX - RABBITX)*
(foxInformation_message->foxX - RABBITX) +
(foxInformation_message->foxY - RABBITY)*
(foxInformation_message->foxY - RABBITY);
/* If distance within rabbit view distance */
if(current_distance_squared
<= (rabbit_view_length*rabbit_view_length))
{
/* Add fox location to fox force */
fox_x_force += foxInformation_message->foxX;
fox_y_force += foxInformation_message->foxY;
/* Increment fox count */
foxes++;
}
X-Machines for Agent-Based Modeling: FLAME Perspectives
/** \fn Dodge_foxes()
* \brief Read fox locations and dodge
*/
int dodgeFoxes()
{
/* Use idea of force from foxes to move rabbits */
double fox_x_force = RABBITX;
double fox_y_force = RABBITY;
/* Angle to move rabbit, calculated from fox force */
double theta;
/* Distance from current agent to agent sending message */
double current_distance_squared;
/* Fox count */
int foxes = 0;
/* Check if eaten, by reading eaten messages */
rabbitEaten_message = get_first_rabbitEaten_message();
while(rabbitEaten_message)
{
/* If message relates to me then die */
if(rabbitEaten_message->rabbitID == RABBITID)
{
printf("Rabbit %d dies\n", RABBITID);
return 1;
}
rabbitEaten_message = get_next_rabbitEaten_message
(rabbitEaten_message);
}
/* Dodge foxes, by reading fox location messages */
foxInformation_message = get_first_foxInformation_message();
while(foxInformation_message)
{
current_distance_squared =
(foxInformation_message->foxX - RABBITX)*
(foxInformation_message->foxX - RABBITX) +
(foxInformation_message->foxY - RABBITY)*
(foxInformation_message->foxY - RABBITY);
/* If distance within rabbit view distance */
if(current_distance_squared
<= (rabbit_view_length*rabbit_view_length))
{
/* Add fox location to fox force */
fox_x_force += foxInformation_message->foxX;
fox_y_force += foxInformation_message->foxY;
/* Increment fox count */
foxes++;
}
