1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| void deplacer_agent(float **g, int *px,int *py,int *px2,int *py2,bool ** cd,int dep1,int tg, bool *init)
{
int k;
if((&px2>&px) && (&py2>&py))
{
k=*px;
*px=*px2;
*px2=k;
}
if(*init&&*px!=-1&&*py!=-1)
{
cd[*px][*py]=false;
*init=false;
}
else
{
if(*init&&*px==-1&&*py==-1)
{
*px=rand() %10;
*py=rand() %10;
cd[*px][*py]=false;
*init=false;
}
else
{
int px1=*px;
int py1=*py;
if(dep1==-1)
{
px1=*px;
py1=*py;
int compt=0;
while(((px1<0||px1>tg-1||py1<0||py1>tg-1)||((dep1==-1)) )&&compt<20)
{
compt++;
px1=*px;
py1=*py;
do
{
dep1=rand() %8;
{
if(dep1==0 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1-1; }
if(dep1==1 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1-1;px1=px1-1;}
if(dep1==2 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){px1=px1-1;}
if(dep1==3 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1+1;px1=px1-1;}
if(dep1==4 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1+1;}
if(dep1==5 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1+1;px1=px1+1;}
if(dep1==6 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){px1=px1+1;}
if(dep1==7 && (*px2<=px1<=*px) && (*py2<=py1<=*py)){py1=py1-1;px1=px1+1;}
}
}
while((*px2<=px1<=*px) && (*py2<=py1<=*py));
if(px1>=0&&px1<=tg-1&&py1>=0&&py1<=tg-1)
{
if(!cd[px1][py1]){px1=-1;py1=-1;}
}
}
if(px1>=0&&px1<=tg-1&&py1>=0&&py1<=tg-1)
{cd[px1][py1]=false;*px=px1;*py=py1; }
else
{*px=-1; *py=-1; }
}
}
}
} |
Partager