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

📄 strategy.cpp

📁 robocup 5vs5修改板决策例程
💻 CPP
字号:
#include "stdafx.h"
#include "Strategy.h"

#include "GeometryR.h"
#include "String.h"
#include "DecisionMakingx.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


//Global Environment variable
static Environment gloabe;
extern "C" STRATEGY_API void StrategyInit(Environment* Env)
{
	//Please allocate your own resource here
	//e.g.	
	Env->pointer=(long)new CDecisionMakingx();
}
extern "C" STRATEGY_API void StrategyStep(Environment* Env)
{
	//Please GET the information of robots first,
	//After strategy making,SET the speed of wheels.

	RobotInford RobotInfo[2*ROBOTNUMBER+1];

	//home goalie,degree input
	RobotInfo[4].pos.SetX(Env->home0_pos_x);
	RobotInfo[4].pos.SetY(Env->home0_pos_y);
	RobotInfo[4].theta=Env->home0_rotation/180 * PI;

	RobotInfo[0].pos.SetX(Env->home1_pos_x);
	RobotInfo[0].pos.SetY(Env->home1_pos_y);
	RobotInfo[0].theta=Env->home1_rotation/180 * PI;

	RobotInfo[1].pos.SetX(Env->home2_pos_x);
	RobotInfo[1].pos.SetY(Env->home2_pos_y);
	RobotInfo[1].theta=Env->home2_rotation/180 * PI;


	RobotInfo[2].pos.SetX(Env->home3_pos_x);
	RobotInfo[2].pos.SetY(Env->home3_pos_y);
	RobotInfo[2].theta=Env->home3_rotation/180 * PI;

	RobotInfo[3].pos.SetX(Env->home4_pos_x);
	RobotInfo[3].pos.SetY(Env->home4_pos_y);
	RobotInfo[3].theta=Env->home4_rotation/180 * PI;

	//opponet goalie,degree input
	RobotInfo[9].pos.SetX(Env->opponent0_pos_x);
	RobotInfo[9].pos.SetY(Env->opponent0_pos_y);
	RobotInfo[9].theta=Env->opponent0_rotation/180 * PI;

	RobotInfo[5].pos.SetX(Env->opponent1_pos_x);
	RobotInfo[5].pos.SetY(Env->opponent1_pos_y);
	RobotInfo[5].theta=Env->opponent1_rotation/180 * PI;

	RobotInfo[6].pos.SetX(Env->opponent2_pos_x);
	RobotInfo[6].pos.SetY(Env->opponent2_pos_y);
	RobotInfo[6].theta=Env->opponent2_rotation/180 * PI;


	RobotInfo[7].pos.SetX(Env->opponent3_pos_x);
	RobotInfo[7].pos.SetY(Env->opponent3_pos_y);
	RobotInfo[7].theta=Env->opponent3_rotation/180 * PI;

	RobotInfo[8].pos.SetX(Env->opponent4_pos_x);
	RobotInfo[8].pos.SetY(Env->opponent4_pos_y);
	RobotInfo[8].theta=Env->opponent4_rotation/180 * PI;

	//ball,degree input
	RobotInfo[10].pos.SetX(Env->currentBall_pos_x);
	RobotInfo[10].pos.SetY(Env->currentBall_pos_y);
	RobotInfo[10].theta=0;

	DEGame mode;

	mode.DEGameGround=Env->halfArea;
	
	switch (Env->kickOffStyle)
	{
	case FREE_BALL:
		mode.DEStartMode = FreeBall;
		break;
	case Normal:
		mode.DEStartMode = NormalStart;
		break;
	case PENALTY_KICK:
		mode.DEStartMode = PenaltyKick;
		break;
	case FREE_KICK:
		mode.DEStartMode = FreeKick;
		break;
	case GOAL_KICK:
		mode.DEStartMode = GoalKick;
		break;
	default:
		mode.DEStartMode = NormalStart;
		break;
	}

	if (Env->whoseBall == Env->halfArea 
		|| Env->whoseBall == ANYONES_BALL)
	{
		mode.DEStartState = Attack;
	}
	else
	{
		mode.DEStartState = Defense;
	}

	CDecisionMakingx* pTmpPointer=(CDecisionMakingx*)(Env->pointer);

	pTmpPointer->InitDEG(mode);
	pTmpPointer->Startx(RobotInfo);

	//set the velocity of robots
	//home goalie
	Env->home0_velocityLeft   =pTmpPointer->rbV[4].LeftValue;
	Env->home0_velocityRight  =pTmpPointer->rbV[4].RightValue;

	Env->home1_velocityLeft   =pTmpPointer->rbV[0].LeftValue;
	Env->home1_velocityRight  =pTmpPointer->rbV[0].RightValue;

	Env->home2_velocityLeft   =pTmpPointer->rbV[1].LeftValue;
	Env->home2_velocityRight  =pTmpPointer->rbV[1].RightValue;
								   
	Env->home3_velocityLeft   =pTmpPointer->rbV[2].LeftValue;
	Env->home3_velocityRight  =pTmpPointer->rbV[2].RightValue;

	Env->home4_velocityLeft   =pTmpPointer->rbV[3].LeftValue;
	Env->home4_velocityRight  =pTmpPointer->rbV[3].RightValue;
}
extern "C" STRATEGY_API void StrategyDrop(	Environment* Env)
{
	//Free the resource you allocated

	//e.g.
	if(NULL!=Env->pointer)
	{
		delete (CDecisionMakingx*)(Env->pointer);
	}
	Env->pointer=NULL;
}

extern "C" STRATEGY_API void Author(char* team)
{
	//Please give you strategy a nice name
	//e.g.
	strcpy(team,"Cool!");
}
extern "C" STRATEGY_API void SetForm(Environment* Env)
{
	//Please GET the information of robots first,
	//Then,SET the location of robots(sometimes,including the ball).
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -