222
X-Machines for Agent-Based Modeling: FLAME Perspectives
return 0;
}
nestInformation_message = get_next_nestInformation_message
(nestInformation_message);
}
pheromoneInformation_message = get_first_pheromoneInformation_message();
while (pheromoneInformation_message) {
double pheromoneLocalX = pheromoneInformation_message->pheromoneX;
double pheromoneLocalY = pheromoneInformation_message->pheromoneY;
double pheromoneLocalLife = pheromoneInformation_message->life;
distanceToPheromone = getDistance(pheromoneLocalX, pheromoneLocalY,
currentX, currentY);
if (distanceToPheromone <= antStepSize && pheromoneLocalLife > 0.2
&& distanceToPheromone > minPheromoneDistance) {
int newDirection = getDirection(ANTX, ANTY, pheromoneLocalX, pheromoneLocalY);
if (newDirection == direction || newDirection == nextdir
|| newDirection == prevdir) {
if (p.pheromoneLife <= pheromoneLocalLife) {
p.pheromoneLife = pheromoneLocalLife;
p.pheromoneX = pheromoneLocalX;
p.pheromoneY = pheromoneLocalY;
p.direction = getDirection(ANTX, ANTY, p.pheromoneX, p.pheromoneY);
pheromoneFound = 1;
}
}
else if (newDirection == next2dir || newDirection == prev2dir) {
if (ep.pheromoneLife <= pheromoneLocalLife) {
ep.pheromoneLife = pheromoneLocalLife;
ep.pheromoneX = pheromoneLocalX;
ep.pheromoneY = pheromoneLocalY;
ep.direction = getDirection(ANTX, ANTY, ep.pheromoneX, ep.pheromoneY);
epFound = 1;
}
}
}
pheromoneInformation_message = get_next_pheromoneInformation_message
(pheromoneInformation_message);
}
if (pheromoneFound == 1) {
direction = p.direction;
updatePosition(¤tX, ¤tY, direction);
ANTX = checkAntPositionX(currentX);
ANTY = checkAntPositionY(currentY);
ANTDIRECTION = direction;
//checkAntWalkThroughNest(ANTX, ANTY);
} else if (epFound == 1) {
direction = ep.direction;
//printf("after pheromone: direction is %d\n", direction);
updatePosition(¤tX, ¤tY, direction);
ANTX = checkAntPositionX(currentX);
ANTY = checkAntPositionY(currentY);
ANTDIRECTION = direction;
//checkAntWalkThroughNest(ANTX, ANTY);
} else {
turningKernel();
}
X-Machines for Agent-Based Modeling: FLAME Perspectives
return 0;
}
nestInformation_message = get_next_nestInformation_message
(nestInformation_message);
}
pheromoneInformation_message = get_first_pheromoneInformation_message();
while (pheromoneInformation_message) {
double pheromoneLocalX = pheromoneInformation_message->pheromoneX;
double pheromoneLocalY = pheromoneInformation_message->pheromoneY;
double pheromoneLocalLife = pheromoneInformation_message->life;
distanceToPheromone = getDistance(pheromoneLocalX, pheromoneLocalY,
currentX, currentY);
if (distanceToPheromone <= antStepSize && pheromoneLocalLife > 0.2
&& distanceToPheromone > minPheromoneDistance) {
int newDirection = getDirection(ANTX, ANTY, pheromoneLocalX, pheromoneLocalY);
if (newDirection == direction || newDirection == nextdir
|| newDirection == prevdir) {
if (p.pheromoneLife <= pheromoneLocalLife) {
p.pheromoneLife = pheromoneLocalLife;
p.pheromoneX = pheromoneLocalX;
p.pheromoneY = pheromoneLocalY;
p.direction = getDirection(ANTX, ANTY, p.pheromoneX, p.pheromoneY);
pheromoneFound = 1;
}
}
else if (newDirection == next2dir || newDirection == prev2dir) {
if (ep.pheromoneLife <= pheromoneLocalLife) {
ep.pheromoneLife = pheromoneLocalLife;
ep.pheromoneX = pheromoneLocalX;
ep.pheromoneY = pheromoneLocalY;
ep.direction = getDirection(ANTX, ANTY, ep.pheromoneX, ep.pheromoneY);
epFound = 1;
}
}
}
pheromoneInformation_message = get_next_pheromoneInformation_message
(pheromoneInformation_message);
}
if (pheromoneFound == 1) {
direction = p.direction;
updatePosition(¤tX, ¤tY, direction);
ANTX = checkAntPositionX(currentX);
ANTY = checkAntPositionY(currentY);
ANTDIRECTION = direction;
//checkAntWalkThroughNest(ANTX, ANTY);
} else if (epFound == 1) {
direction = ep.direction;
//printf("after pheromone: direction is %d\n", direction);
updatePosition(¤tX, ¤tY, direction);
ANTX = checkAntPositionX(currentX);
ANTY = checkAntPositionY(currentY);
ANTDIRECTION = direction;
//checkAntWalkThroughNest(ANTX, ANTY);
} else {
turningKernel();
}
