Agents in Biology
221
{
if((data.information1[i] == x) && (data.information2[i] == y))
{
found = 1;
}
}
if (found == 0)
{
data.information1[data.maxIndex] = x;
data.information2[data.maxIndex] = y;
data.maxIndex = data.maxIndex + 1;
}
newPheromoneInput_message = get_next_newPheromoneInput_message
(newPheromoneInput_message);
}
for (int i = 0; i < data.maxIndex; i++)
{
MEMORYID++;
// printf("New agent");
add_Pheromone_agent(MEMORYID, antPheromoneDepositionUnit,
data.information1[i], data.information2[i]);
}
return 0;
}
//Ant agent
//after eating food, ant agent goes back to nest
int findNest() {
int pheromoneFound = 0;
int epFound = 0;
double currentX = ANTX;
double currentY = ANTY;
struct PheromoneData p;
p.pheromoneX = -1;
p.pheromoneY = -1;
p.pheromoneLife = -1;
p.direction = ANTDIRECTION;
struct PheromoneData ep;
ep.pheromoneX = -1;
ep.pheromoneY = -1;
ep.pheromoneLife = -1;
ep.direction = ANTDIRECTION;
int direction = ANTDIRECTION;
int nextdir = (direction + 1) > 8 ? 1 : direction + 1;
int prevdir = (direction - 1) < 1 ? 8 : direction - 1;
int next2dir = (direction + 2) > 8 ? 1 : direction + 2;
int prev2dir = (direction - 2) < 1 ? 8 : direction - 2;
double distanceToPheromone = 0;
nestInformation_message = get_first_nestInformation_message();
while (nestInformation_message) {
double xNest = nestInformation_message->nestX;
double yNest = nestInformation_message->nestY;
double nestRadius = nestInformation_message->nestRadius;
double distanceToNest = getDistance(xNest, yNest, currentX, currentY);
if (distanceToNest <= nestRadius + 2) {
ISINNEST = 1;
Précédent

- 250/329

Suivant