Getting Started with FLAME
81
foxInformation_message = get_next_foxInformation_message
(foxInformation_message);
}
/* If foxes in view distance */
if(foxes)
{
/* Use fox force to calculate angle to move */
theta = atan((fox_y_force - RABBITY)/(fox_x_force - RABBITX));
/* Move rabbit run distance along angle */
RABBITX = RABBITX + (rabbit_run_length * cos(theta));
RABBITY = RABBITY + (rabbit_run_length * sin(theta));
}
else
{
/* Else move randomly */
RABBITX = RABBITX + (rabbit_run_length -
(rand()/(double)(RAND_MAX)*(rabbit_run_length*2.0)));
RABBITY = RABBITY + (rabbit_run_length -
(rand()/(double)(RAND_MAX)*(rabbit_run_length*2.0)));
}
/* Mirror location off boundary */
RABBITX = handle_boundaryX(RABBITX);
RABBITY = handle_boundaryY(RABBITY);
return 0;
}
4.7.4 Additional Files
Additional files can be accompanied by model files. These allow modelers
to organize their code and easily manage complex functions. For instance,
• Modelers can list global values in an additional header file. This allows
modelers to change these values before runtime and maintain one file.
• Modelers can add additional functions used by agents in a separate
functions file, included at runtime.
/**Example Library header file**/
#include "header.h"
#include "Fox_agent_header.h"
#include "Rabbit_agent_header.h"
/** \def Distance foxes can see rabbits */
#define fox_view_length 20.0
/** \def Distance foxes can eat rabbits */
Précédent

- 110/329

Suivant