本文整理汇总了C++中Bot::move方法的典型用法代码示例。如果您正苦于以下问题:C++ Bot::move方法的具体用法?C++ Bot::move怎么用?C++ Bot::move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bot
的用法示例。
在下文中一共展示了Bot::move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moveTowardsTarget
void AI::moveTowardsTarget(Bot& actor, Unit& target)
{
int dist = INT_MAX,startDist = 0;
while(actor.steps()>0 && dist > actor.range() && dist != startDist)
{
//startDist = distance(actor.x(),actor.y(),actor.size(), target.x(),target.y(),target.size());
startDist = distance(actor.x(),actor.y(),actor.size(), target.x(),target.y(),1)+1;
cout<<"Distance to target: "<<startDist<<endl;
dist = startDist;
int dir = 0;
// find the best, non blocked direction
for(unsigned int d=0;d<DIR_SIZE;d++)
{
int x=actor.x()+xMod[d];
int y=actor.y()+yMod[d];
if(x>=0 && x<boardX() && y>=0 && y<boardY())
{
//int tempDist = distance(x,y,actor.size(), target.x(),target.y(),target.size());
int tempDist = distance(x,y,actor.size(), target.x(),target.y(),1);
if(tempDist < dist)
{
bool blocked = false;
// check if blocked TODO add other blocking calls
for(unsigned int b=0;b<bots.size() && !blocked;b++)
{
//if(bots[b].x()==x && bots[b].y()==y && bots[b].partOf()==0)
if(bots[b].partOf()==0 && distance(bots[b].x(),bots[b].y(),bots[b].size(),x,y,actor.size())==0 && bots[b].id() != actor.id())
{
blocked=true;
}
}
if(!blocked)
{
dir=d;
dist = tempDist;
}
}
}
}
if(dist != startDist)
{
cout<<"Big guy moving: "<<direction[dir]<<endl;
actor.move(direction[dir]);
}
else
{
cout<<"Nothing worth going to!"<<endl;
}
}
}