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

📄 strategysystem.cpp

📁 FIRA比赛中的关键策略代码
💻 CPP
字号:
// StrategySystem.cpp: implementation of the CStrategySystem class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "StrategySystem.h"

#include "DecisionMakingx.h"


#define INCH

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CStrategySystem::CStrategySystem()
{
	Initialize();
}

CStrategySystem::~CStrategySystem()
{

}

void CStrategySystem::Step(Environment *env)
{
	RobotInford Robot[2*ROBOTNUMBER+1];

#ifdef INCH
	for (int i=0; i<4; i++)
	{
		Robot[i].pos.SetX((env->home [i+1].pos.x - 6.8118) * 2.54);
		Robot[i].pos.SetY((env->home [i+1].pos.y - 6.3730) * 2.54);
		Robot[i].theta = env->home [i+1].rotation / 180 * PI;
		
		Robot[i+5].pos.SetX((env->opponent [i+1].pos.x - 6.8118) * 2.54);
		Robot[i+5].pos.SetY((env->opponent [i+1].pos.y - 6.3730) * 2.54);
		Robot[i+5].theta = env->opponent [i+1].rotation / 180 * PI;
	}
	Robot[4].pos.SetX((env->home [0].pos.x - 6.8118) * 2.54);
	Robot[4].pos.SetY((env->home [0].pos.y - 6.3730) * 2.54);
	Robot[4].theta = env->home [0].rotation / 180 * PI;
	
	Robot[9].pos.SetX((env->opponent [0].pos.x - 6.8118) * 2.54);
	Robot[9].pos.SetY((env->opponent [0].pos.y - 6.3730) * 2.54);
	Robot[9].theta = env->opponent [0].rotation / 180 * PI;
	
	Robot[10].pos.SetX((env->currentBall.pos.x - 6.8118) * 2.54) ;
	Robot[10].pos.SetY((env->currentBall.pos.y- 6.3730) * 2.54) ;
	Robot[10].theta = 0;
	
#else
	for (int i=0; i<4; i++)
	{
		Robot[i].x = env->home [i+1].pos.x;
		Robot[i].y = env->home [i+1].pos.y ;
		Robot[i].theta = env->home [i+1].rotation;
		
		Robot[i+5].x = env->opponent [i+1].pos.x;
		Robot[i+5].y = env->opponent [i+1].pos.y;
		Robot[i+5].theta = env->opponent [i+1].rotation;
	}
	Robot[4].x = env->home [0].pos.x;
	Robot[4].y = env->home [0].pos.y;
	Robot[4].theta = env->home [0].rotation;
	
	Robot[9].x = env->opponent [0].pos.x;
	Robot[9].y = env->opponent [0].pos.y;
	Robot[9].theta = env->opponent [0].rotation;
	
	Robot[10].x = env->currentBall.pos.x;
	Robot[10].y = env->currentBall.pos.y;
#endif
	for (i=0; i<2*ROBOTNUMBER+1; ++i)
	{
		Robot[i].bFind = true;
	}

	static int nArea = -1;
	
	if (nArea == -1)
	{
		if (Robot[4].pos.GetX() < 110)
			nArea = YELLOW_BALL;
		else
			nArea = BLUE_BALL;
	}
	
	DEGame mode;
	
	if (nArea == YELLOW_BALL)
		mode.DEGameGround = LeftArea;
	else if (nArea == BLUE_BALL)
		mode.DEGameGround = RightArea;
	
	switch (env->gameState)
	{
	case FREE_BALL:
		mode.DEStartMode = FreeBall;
		break;
	case PLACE_KICK:
		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->whosBall == nArea 
		|| env->whosBall == ANYONES_BALL)
	{
		mode.DEStartState = Attack;
	}
	else
	{
		mode.DEStartState = Defense;
	}


	InitDEG(mode);
	
	Startx(Robot);

	//set the velocity of robots
	for (i=0; i<4; i++)
	{
		env->home[i+1].velocityLeft = rbV[i].LeftValue;
		env->home[i+1].velocityRight = rbV[i].RightValue;
	}
	env->home[0].velocityLeft = rbV[4].LeftValue;
	env->home[0].velocityRight = rbV[4].RightValue;
}

⌨️ 快捷键说明

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