⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arspolicedirect.cpp

📁 多机器人目标围捕 用MFC自行设计了简单的机器人围捕场景。机器人策略采用注册机制易于机器人的策略的扩展。捕捉机器人策略应用了人工势场法。
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -