| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 475 人关注过本帖
标题:[求助]“蚁群算法”求注释3
只看楼主 加入收藏
xiazhi123456
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-6-30
收藏
 问题点数:0 回复次数:0 
[求助]“蚁群算法”求注释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 not go
5 - forward and right can not go
6 - left and right can not go
7 - forward and left and right all can not 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);
}

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 */
}

搜索更多相关主题的帖子: 注释 算法 
2007-06-30 16:04
快速回复:[求助]“蚁群算法”求注释3
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039728 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved