si ça t'intéresse je te conseille d'acheter une nouvelle revue qui vient de sortir: Precision Mac (je l'ai trouvée dans un leclerc en kiosque)
sinon il s'est corrigé deux ou trois truc, mais là je coince:
g++ -Wall -g -I/usr/X11R6/include -c main.cpp -Wall
g++ -Wall -g -I/usr/X11R6/include -c world.cpp -Wall
g++ -Wall -g -I/usr/X11R6/include -c glwindow.cpp -Wall
g++ -Wall -g -I/usr/X11R6/include -c ant.cpp -Wall
ant.cpp: In function `void __static_initialization_and_destruction_0(int,
int)':
ant.cpp:3: Internal compiler error in find_function_data, at function.c:350
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:
http://developer.apple.com/bugreporter> for instructions.
make: *** [ant.o] Error 1
Pour ça:
#include "ant.h"
fero * Ant::raster = new fero[width*height];
Ant::Ant() {
posX = antFarmX;
posY = antFarmY;
found = false;
time = 1;
}
void Ant::update() {
double time_decrease = 0.99;
time *= time_decrease;
if (found) {
randomReturnWalk();
raster[coord(posX,posY)].found+=0.04*time;
if ((posX == antFarmX)&&(posY == antFarmY)) {
foundHome++;
cout << "home:\t" << foundHome <<"\tfood:\t"<<foundFood<<"\t\tHome"<<endl;
found = false;
time = 1;
}
} else {
randomSeekWalk();
raster[coord(posX,posY)].seek+=0.04*time;
if ((posX == foodX)&&(posY == foodY)) {
foundFood++;
cout << "home:\t" << foundHome <<"\tfood:\t"<<foundFood<<"\t\tFood"<<endl;
found = true;
time = 1;
}
}
posX += moveX;
posY += moveY;
if ( (posX < 1) || (posX > (width-1)) || (posY < 1) || (posY > (height-1))) {
// cout << "Send me back home !!!"<<endl;
posX = antFarmX;
posY = antFarmY;
found = false;
time = 1;
}
}
void Ant::display() {
double x = 2*(posX/(double)width)-1.0;
double y = 2*(posY/(double)height)-1.0;
if (found) {
glColor3d(1,1,1);
glVertex2d(x,y);
glColor3d(1,0.5,0.;
} else
glVertex2d(x,y);
}
void Ant::evalSeekCoef(double * coef) {
float base = 0.3;
float tot = 0;
int r = 1;
for (int i = -r; i < r+1; i++) {
for (int j = -r; j < r+1; j++) {
tot += nFeroF(posX+i, posY+j);
}
}
tot -= nFeroF(posX,posY);
if (tot==0) {
for (int i = 0; i < 8; i++)
coef
= 1.0/8.0;
} else {
coef[0] = (nFeroF(posX , posY + 1)/tot+base)/(8*base + 1.0);
coef[1] = (nFeroF(posX + 1, posY + 1)/tot+base)/(8*base + 1.0);
coef[2] = (nFeroF(posX + 1, posY )/tot+base)/(8*base + 1.0);
coef[3] = (nFeroF(posX + 1, posY - 1)/tot+base)/(8*base + 1.0);
coef[4] = (nFeroF(posX , posY - 1)/tot+base)/(8*base + 1.0);
coef[5] = (nFeroF(posX - 1, posY - 1)/tot+base)/(8*base + 1.0);
coef[6] = (nFeroF(posX - 1, posY )/tot+base)/(8*base + 1.0);
coef[7] = (nFeroF(posX - 1, posY + 1)/tot+base)/(8*base + 1.0);
}
}
void Ant::evalFoundCoef(double * coef) {
float base = 0.1;
float tot = 0;
int r = 1;
for (int i = -r; i < r+1; i++) {
for (int j = -r; j < r+1; j++) {
tot += nFeroS(posX+i, posY+j);
}
}
tot -= nFeroS(posX,posY);
if (tot==0) {
for (int i = 0; i < 8; i++)
coef = 1.0/8.0;
} else {
coef[0] = (nFeroS(posX , posY + 1)/tot+base)/(8*base + 1.0);
coef[1] = (nFeroS(posX + 1, posY + 1)/tot+base)/(8*base + 1.0);
coef[2] = (nFeroS(posX + 1, posY )/tot+base)/(8*base + 1.0);
coef[3] = (nFeroS(posX + 1, posY - 1)/tot+base)/(8*base + 1.0);
coef[4] = (nFeroS(posX , posY - 1)/tot+base)/(8*base + 1.0);
coef[5] = (nFeroS(posX - 1, posY - 1)/tot+base)/(8*base + 1.0);
coef[6] = (nFeroS(posX - 1, posY )/tot+base)/(8*base + 1.0);
coef[7] = (nFeroS(posX - 1, posY + 1)/tot+base)/(8*base + 1.0);
}
}
int Ant::coord(int x, int y) {
return x+y*height;
}
float Ant::nFeroF(int x, int y) {
return raster[coord(x,y)].found;
}
float Ant::nFeroS(int x, int y) {
return raster[coord(x,y)].seek;
}
void Ant::randomSeekWalk() {
double coef[8];
evalSeekCoef(coef);
double dir = (rand()/(double)RAND_MAX);
double lim = 0;
if (dir < (lim += coef[0])) {
moveX=0;
moveY=1;
} else {
if (dir < (lim += coef[1])) {
moveX=1;
moveY=1;
} else {
if (dir < (lim += coef[2])) {
moveX=1;
moveY=0;
} else {
if (dir < (lim += coef[3])) {
moveX=1;
moveY=-1;
} else {
if (dir < (lim += coef[4])) {
moveX=0;
moveY=-1;
} else {
if (dir < (lim += coef[5])) {
moveX=-1;
moveY=-1;
} else {
if (dir < (lim += coef[6])) {
moveX=-1;
moveY=0;
} else {
if (dir < (lim += coef[7])) {
moveX=-1;
moveY=1;
}
}
}
}
}
}
}
}
}
void Ant::randomReturnWalk() {
double coef[8];
evalFoundCoef(coef);
double dir = (rand()/(double)RAND_MAX);
double lim = 0;
if (dir < (lim += coef[0])) {
moveX=0;
moveY=1;
} else {
if (dir < (lim += coef[1])) {
moveX=1;
moveY=1;
} else {
if (dir < (lim += coef[2])) {
moveX=1;
moveY=0;
} else {
if (dir < (lim += coef[3])) {
moveX=1;
moveY=-1;
} else {
if (dir < (lim += coef[4])) {
moveX=0;
moveY=-1;
} else {
if (dir < (lim += coef[5])) {
moveX=-1;
moveY=-1;
} else {
if (dir < (lim += coef[6])) {
moveX=-1;
moveY=0;
} else {
if (dir < (lim += coef[7])) {
moveX=-1;
moveY=1;
}
}
}
}
}
}
}
}
}