ms = Max_smell;
Break
}
if (Istrace (i,j)) continue;
if (smell[type][i][j]>ms) ms = Smell[type][i][j];
}
Break
Case Down:for (i=xxx-ant_eyeshot;i<=xxx+ant_eyeshot;i++)
for (j=yyy+1;j<=yyy+ant_eyeshot;j++)
{
if (! Judgecango (I,J)) continue;
if ((I==food.xxx&&j==food.yyy&&type==smell_type_food) | |
(I==home.xxx&&j==home.yyy&&type==smell_type_home))
{
ms = Max_smell;
Break
}
if (Istrace (i,j)) continue;
if (smell[type][i][j]>ms) ms = Smell[type][i][j];
}
Break
Case Left:for (i=xxx-ant_eyeshot;i<xxx;i++)
for (j=yyy-ant_eyeshot;j<=yyy+ant_eyeshot;j++)
{
if (! Judgecango (I,J)) continue;
if ((I==food.xxx&&j==food.yyy&&type==smell_type_food) | |
(I==home.xxx&&j==home.yyy&&type==smell_type_home))
{
ms = Max_smell;
Break
}
if (Istrace (i,j)) continue;
if (smell[type][i][j]>ms) ms = Smell[type][i][j];
}
Break
Case Right:for (i=xxx+1;i<=xxx+ant_eyeshot;i++)
for (j=yyy-ant_eyeshot;j<=yyy+ant_eyeshot;j++)
{
if (! Judgecango (I,J)) continue; [Page]
if ((I==food.xxx&&j==food.yyy&&type==smell_type_food) | |
(I==home.xxx&&j==home.yyy&&type==smell_type_home))
{
ms = Max_smell;
Break
}
if (Istrace (i,j)) continue;
if (smell[type][i][j]>ms) ms = Smell[type][i][j];
}
Break
Default:break;
}
return (MS);
}
int istrace (int xxx,int yyy)
{
int i;
for (i=0;i<trace_remember;i++)
if (ANT[ANTNOW].TRACEX[I]==XXX&&ANT[ANTNOW].TRACEY[I]==YYY) return (1);
return (0);
}
int maxlocation (int num1,int num2,int num3)
{
int maxnum;
if (num1==0&&num2==0&&num3==0) return (0);
Maxnum = NUM1;
if (num2>maxnum) maxnum = num2;
if (num3>maxnum) maxnum = num3;
if (MAXNUM==NUM1) return (1);
if (maxnum==num2) return (2);
if (MAXNUM==NUM3) return (3);
}
int Cango (int xxx,int yyy,int ddir)
/* Input:xxx,yyy-location of Ant
Ddir-now dir
Output:0-forward and left and right can go
1-forward can not go
2-left can not go
3-right can not go
4-forward and left can don't go
5-forward and right can don't go
6-left and right can don't go
7-forward and left and right all can don't go
*/
{
int tx,ty,tdir;
int OKF,OKL,OKR;
/* forward can go? */
Tdir = Ddir;
tx = XXX;
ty = yyy;
Switch (TDIR)
{
Case up:ty--;
Break
Case down:ty++;
Break
Case left:tx--;
Break
Case right:tx++;
Break
Default:break;
}/* of Switch dir * *
if (Judgecango (tx,ty)) okf = 1;
else okf = 0;
/* Turn left can go? */
Tdir = TurnLeft (Ddir);
tx = XXX;
ty = yyy;
Switch (TDIR)
{
Case up:ty--;
Break
Case down:ty++;
Break
Case left:tx--;
Break
Case right:tx++;
Break
Default:break;
}/* of Switch dir * *
if (Judgecango (tx,ty)) okl = 1;
else Okl = 0;
/* Turn right can go? */
Tdir = TurnRight (Ddir);
tx = XXX;
ty = yyy;
Switch (TDIR)
{
Case up:ty--;
Break
Case down:ty++;
Break
Case left:tx--;
Break
Case right:tx++;
Break
Default:break;
}/* of Switch dir * *
if (Judgecango (tx,ty)) Okr = 1;
else Okr = 0;
if (OKF&&OKL&&OKR) return (0);
if (!OKF&&OKL&&OKR) return (1);
if (OKF&&!OKL&&OKR) return (2);
if (OKF&&OKL&&!OKR) return (3);
if (!OKF&&!OKL&&OKR) return (4);
if (!OKF&&OKL&&!OKR) return (5);
if (OKF&&!OKL&&!OKR) return (6);
if (!OKF&&!OKL&&!OKR) return (7);
return (7); [Page]
}
int Judgecango (int xxx,int yyy)
/* Input:location to Judeg
output:0--Can not go
1--Can go
*/
{
int i,j;
if (xxx<=0| | Xxx>maxx) return (0);
if (yyy<=0| | Yyy>maxy) return (0);
if (block[xxx][yyy]) return (0);
return (1);
}
int turnleft (int ddir)
{
Switch (DDIR)
{
Case Up:return (left);
Case Down:return (right);
Case Left:return (down);
Case Right:return (UP);
Default:break;
}/* of Switch dir * *
}
int turnright (int ddir)
{
Switch (DDIR)
{
Case Up:return (right);
Case Down:return (left);
Case Left:return (UP);
Case Right:return (down);
Default:break;
}/* of Switch dir * *
}
int turnback (int ddir)
{
Switch (DDIR)
{
Case Up:return (down);
Case Down:return (UP);
Case Left:return (right);
Case Right:return (left);
Default:break;
}/* of Switch dir * *
}