📄 robotrole.cpp
字号:
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为进攻队形的上前锋角色
// 因此选择一个在离 球场右上角 最近的机器人但任此角色
//
FIND_ROBOT (FRIGHTX, FBOT);
}
void
RoleVanguardBottom::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
/*
下前锋角色进攻
负责区域为 13, 14, 15, 18, 19, 20
1. 当球在其它区域时以球的 X 轴移动, Y 轴为上半场的中间位置
2. 球一旦进入所负责的区域则执行踢球任务 不执行射门任务
射门由助功角色完成
*/
BallArea area = areaInfo->getArea ();
if (area == BA_13 ||
area == BA_14 ||
area == BA_15 ||
area == BA_18 ||
area == BA_19 ||
area == BA_20) {
if (actKickBall (robot, *env) == false)
actShoot (robot, *env);
return;
}
//
// 跟着球的 X 轴移动, Y 轴为下半场的中间位置
//
double x = 0,
y = FIELD_CENTER_Y - FIELD_HEIGHT / 4;
transform (x, y);
x = env->predictedBall.pos.x;
//
// 如果 X 超过对方小禁区 X 轴,则停留在 对方小禁区 X 轴上
//
double oppSmallForbidX = OPP_SMALL_FORBID_ZONE_X;
BallField fieldInfo = analyseFieldInfo ();
if ((x > oppSmallForbidX && fieldInfo == BF_IS_LEFT) || (x < oppSmallForbidX && fieldInfo == BF_IS_RIGHT)) {
double tempY = 0;
transform (oppSmallForbidX, tempY);
x = oppSmallForbidX;
}
actToPosition (robot, x, y);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 进攻队形的助功角色
//
// public
long
RoleAttack::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为进攻队形的助攻角色
// 因此选择一个在离 敌方球门 最近的机器人但任此角色
//
FIND_ROBOT (OPP_GOAL_CENTER_X, OPP_GOAL_CENTER_Y);
}
// public
void
RoleAttack::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
/*
助攻角色
负责区域 敌方小禁区高度 对应的区域
1. 当球在其它区域时以球的 X 轴移动, Y 轴为球场的中间位置
2. 球一旦进入所负责的区域则执行射门任务
*/
double ballX, ballY;
ballX = env->predictedBall.pos.x;
ballY = env->predictedBall.pos.y;
BallArea area = areaInfo->getArea ();
if (area == BA_9 || area == BA_10 || area == BA_14 || area == BA_15) {
actShoot (robot, *env);
return;
}
//
// 跟着球的 X 轴移动, Y 轴为上半场的中间位置
//
double x = 0,
y = FIELD_CENTER_Y;
transform (x, y);
x = env->predictedBall.pos.x;
//
// 如果 X 超过对方小禁区 X 轴,则停留在 对方小禁区 X 轴上
//
double oppForbidX = OPP_FORBID_ZONE_X;
BallField fieldInfo = analyseFieldInfo ();
if ((x > oppForbidX && fieldInfo == BF_IS_LEFT) || (x < oppForbidX && fieldInfo == BF_IS_RIGHT)) {
double tempY = 0;
transform (oppForbidX, tempY);
x = oppForbidX;
}
actToPosition (robot, x, y);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 进攻护卫角色
//
// public
long
RoleAttackDefend::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为进攻队形的护卫角色
// 因此选择一个在离 我方球门 最近的机器人但任此角色
//
FIND_ROBOT (FORBIDDEN_ZONE_X, FIELD_CENTER_Y);
}
// public
void
RoleAttackDefend::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
/*
进攻护卫角色
负责区域为 1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18
1. 当球在其它区域时以球的 Y 轴移动, X 轴为我方半场的中间位置
2. 球一旦进入所负责的区域则执行踢球任务 不执行射门任务
*/
BallArea area = areaInfo->getArea ();
if (area == BA_1 ||
area == BA_2 ||
area == BA_6 ||
area == BA_7 ||
area == BA_11 ||
area == BA_12 ||
area == BA_16 ||
area == BA_17 ||
area == BA_3 ||
area == BA_8 ||
area == BA_13 ||
area == BA_18) {
actKickBall (robot, *env);
return;
}
//
// 跟着球的 X 轴移动, Y 轴为上半场的中间位置
//
double x = 0,
y = FIELD_CENTER_Y;
transform (x, y);
x = env->predictedBall.pos.x;
//
// 如果 X 超出我方半场的中线 X 轴则 X = 我方半场的中线 X
//
double defendX = FLEFTX + FIELD_WIDTH / 4; // 进攻后卫的默认 X
BallField fieldInfo = analyseFieldInfo ();
if ((x > defendX && fieldInfo == BF_IS_LEFT) || (x < defendX && fieldInfo == BF_IS_RIGHT)) {
double tempY = 0;
transform (defendX, tempY);
x = defendX;
}
actToPosition (robot, x, y);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//防守型角色 - 左上角的后卫
//
// public
long
RoleLeftTopDefend::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为防守队形的左上角的后卫角色
// 因此选择一个在离 球场左上角 最近的机器人但任此角色
//
FIND_ROBOT (FLEFTX, FTOP);
}
void
RoleLeftTopDefend::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
//
// 球在 1, 6 区域内时如果不可以踢球则机器人一直保持在 禁区线上的连线位置
//
BallArea area = areaInfo->getArea ();
if (area == BA_1 || area == BA_6) {
if (actKickBall (robot, *env) == true)
return;
}
double defendX = FLEFTX - ROBOT_DIAMETER / 2;
double defendY = DEFEND_LEFT_TOP_Y;
transform (defendX, defendY);
actToPosition (robot, defendX, defendY);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//防守型角色 - 左下角的后卫
//
// public
long
RoleLeftBotDefend::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为防守队形的左上角的后卫角色
// 因此选择一个在离 球场左上角 最近的机器人但任此角色
//
FIND_ROBOT (FLEFTX, FBOT);
}
void
RoleLeftBotDefend::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
//
// 球在 11, 16 区域内时如果不可以踢球则机器人一直保持在 禁区线上的连线位置
//
BallArea area = areaInfo->getArea ();
if (area == BA_11 || area == BA_16) {
if (actKickBall (robot, *env) == true)
return;
}
double defendX = FLEFTX - ROBOT_DIAMETER / 2;
double defendY = DEFEND_LEFT_BOT_Y;
transform (defendX, defendY);
actToPosition (robot, defendX, defendY);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//防守型角色 - 右上角的后卫
//
// public
long
RoleRightTopDefend::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为防守队形的右上角的后卫角色
// 因此选择一个在离 球场右上角 最近的机器人但任此角色
//
FIND_ROBOT (DEFEND_RIGHT_TOP_X, FTOP);
}
void
RoleRightTopDefend::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
//
// 球在 2, 7 区域内时如果不可以踢球则机器人一直保持在 禁区线上的连线位置
//
BallArea area = areaInfo->getArea ();
if (area == BA_2 || area == BA_7) {
if (actKickBall (robot, *env) == true)
return;
}
double defendX = DEFEND_RIGHT_TOP_X;
double defendY = DEFEND_RIGHT_TOP_Y;
transform (defendX, defendY);
actToPosition (robot, defendX, defendY);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//防守型角色 - 右下角的后卫
//
// public
long
RoleRightBotDefend::assignRobots (const Robot *robots,
const vector <long> &robotIndexs,
const LastRole &lastRole)
{
//
// 因当前角色为防守队形的右下角的后卫角色
// 因此选择一个在离 球场右下角 最近的机器人但任此角色
//
FIND_ROBOT (DEFEND_RIGHT_TOP_X, FBOT);
}
void
RoleRightBotDefend::strategy (Robot &robot,
const AreaInfo *areaInfo,
BallSpeed speed,
BallDirection direction,
BallPower power,
GuardLeak leak,
const Environment *env)
{
//
// 球在 12, 17 区域内时如果不可以踢球则机器人一直保持在 禁区线上的连线位置
//
BallArea area = areaInfo->getArea ();
if (area == BA_12 || area == BA_17) {
if (actKickBall (robot, *env) == true)
return;
}
double defendX = DEFEND_RIGHT_BOT_X;
double defendY = DEFEND_RIGHT_BOT_Y;
transform (defendX, defendY);
actToPosition (robot, defendX, defendY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -