arspolicedirect.cpp
来自「多机器人目标围捕 用MFC自行设计了简单的机器人围捕场景。机器人策略采用注」· C++ 代码 · 共 51 行
CPP
51 行
#include "StdAfx.h"
#include "ARSPoliceDirect.h"
ARSAction* ARSPlDirect::CreateAction()
{
ARSPlDirect * tmp = new ARSPlDirect;
return tmp;
}
bool ARSPlDirect::ExecuteAction(const ARSSTUATION & stSituation, MOVEDIRECTION & nextDirection)
{
int iPoliceID = stSituation.iID-1;
ARSPOINT ptPoliceSelf = stSituation.ptPloice[iPoliceID];
ARSPOINT ptThief = stSituation.ptThief;
int dx = abs(ptThief.x - ptPoliceSelf.x);
int dy = abs(ptThief.y - ptPoliceSelf.y);
if (ptThief.x - ptPoliceSelf.x >=0)
{
if (ptThief.y - ptPoliceSelf.y == 0||dx>dy)
{
nextDirection = RIGHT;
return true;
}
if (ptThief.y - ptPoliceSelf.y > 0)
nextDirection = UP;
else
nextDirection = DOWN;
}
else
{
if (ptThief.y - ptPoliceSelf.y == 0||dx>dy)
{
nextDirection = LEFT;
return true;
}
if (ptThief.y - ptPoliceSelf.y > 0)
nextDirection = UP;
else
nextDirection = DOWN;
}
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?