Agents in Biology
215
//Check if moving or stationary
double randomNumber1 = ((double) rand() / ((double) RAND_MAX));
double currentX = ANTX;
double currentY = ANTY;
double newX = currentX;
double newY = currentY;
int direction = ANTDIRECTION;
int newDirection = ANTDIRECTION;
//Moving: 66%
if (randomNumber1 <= 0.66) {
double randomNumber2 = ((double) rand() / (double) RAND_MAX);
//DIR 8 = 0 degrees ahead = 41%
if (randomNumber2 <= 0.41) {
newDirection = getNewDirection(direction, 0);
//DIR 1 = 45 degrees clockwise = 27%
}
else if (randomNumber2 <= 0.68) {
newDirection = getNewDirection(direction, 45);
//DIR 7 = 45 degrees anti-clockwise = 19.0%
}
else if (randomNumber2 <= 0.87) {
newDirection = getNewDirection(direction, -45);
//DIR 2 = 90 degrees clockwise = 5.4%
}
else if (randomNumber2 <= 0.924) {
newDirection = getNewDirection(direction, 90);
//DIR 6 = 90 degrees anti-clockwise = 5.4%
} else if (randomNumber2 <= 0.978) {
newDirection = getNewDirection(direction, -90);
//DIR 3 = 135 degrees clockwise = 2.7%
}
else {
newDirection = getNewDirection(direction, 135);
}
updatePosition(&newX, &newY, newDirection);
ANTY = checkAntPositionY(newY);
ANTX = checkAntPositionX(newX);
ANTDIRECTION = newDirection;
//checkAntWalkThroughNest(ANTX, ANTY);
}
else {
//Stationary = 33%
}
return 0;
}
int updateState(){
if ((ISINNEST == 1 && FOODLEVEL < 1.0) || (ISFED == 0
&& FOODLEVEL < 1.0)) {
STATE = stateWalk;
//printf("walk & forage!\n");
}
else if (ISFED == 1 && ISINNEST != 1) {
STATE = stateFindNest;
//printf("find nest!\n");
}
Précédent

- 244/329

Suivant