一、一次传球(踢球)代码
(1)C++代码
这是C++代码里面的chuanqiu2代码
#include "ball.h"
#include "basevision.h"
#include "constants.h"
#include "FilteredObject.h"
#include "game_state.h"
#include "historylogger.h"
#include "matchstate.h"
#include "maths.h"
#include "PlayerTask.h"
#include "referee_commands.h"
#include "robot.h"
#include "singleton.h"
#include "util.h"
#include "vector.h"
#include "worldmodel.h"
extern "C"_declspec(dllexport) PlayerTask player_plan(const WorldModel* model, int robot_id);
PlayerTask player_plan(const WorldModel* model, int robot_id)
{
PlayerTask task;
//传球机器人的位置朝向
//获取中场机器人的向量坐标
const point2f&reciver_pos = model->get_our_player_pos(2);
//获取中场机器人的朝向
const float& reciver_dir = model->get_our_player_dir(2);
//获取球的向量坐标
const point2f&ball_pos = model->get_ball_pos();
//接球机器人的位置朝向
//获取前锋机器人的向量坐标
const point2f&kicker_pos = model->get_our_player_pos(1);
//获取前锋机器人的朝向
const float& kicker_dir = model->get_our_player_dir(1);
//判断球是否在小车控球嘴上,从两个参数着手:1.判断ball到车的距离是否小于某个值,2.车头方向和车到球矢量角度之差值是否小于某个值
bool get_ball = (ball_pos - kicker_pos).length() < get_ball_threshold - 25 && (fabs(anglemod(kicker_dir - (ball_pos - kicker_pos).angle())) < PI / 6);
if (get_ball)
{
//执行平击踢球,力度为最大127
task.kickPower = 127;
//踢球开关
task.needKick = true;
//挑球开关
task.isChipKick = false;
}
return task;
}
重点:
bool get_ball = (ball_pos - kicker_pos).length() < get_ball_threshold - 25 && (fabs(anglemod(kicker_dir - (ball_pos - kicker_pos).angle())) < PI / 6);
修改这个代码的数值会让机器人在找到自己位置之后,判断是否要踢球的时候更加的精确,失误率更小
(2)lua脚本代码
gPlayTable.CreatePlay{
firstState = "GetBall",
["GetBall"] = {
switch = function()
if CIsGetBall("Kicker")then
return "PassBall"
end
end,
Kicker = task.KickerTask("chuanqiu1"),
receiver = task.ReceiverTask("jieqiu")
},
["PassBall"] = {
switch = function()
if CIsBallKick("Kicker")then
return "Finish"
end
end,
Kicker = task.KickerTask("chuanqiu2"),
},
name = "chuanqiu3"
}
(3)C++里面的chuanqiu1和jieqiu代码
chuanqiu1
#include "ball.h"
#include "basevision.h"
#include "constants.h"
#include "FilteredObject.h"
#include "game_state.h"
#include "historylogger.h"
#include "matchstate.h"
#include "maths.h"
#include "PlayerTask.h"
#include "referee_commands.h"
#include "robot.h"
#include "singleton.h"
#include "util.h"
#include "vector.h"
#include "worldmodel.h"
extern "C"_declspec(dllexport) PlayerTask player_plan(const WorldModel* model, int robot_id);
PlayerTask player_plan(const WorldModel* model, int robot_id)
{
PlayerTask task;
//获取对方机器人的向量坐标
const point2f& kicker_pos = model->get_opp_player_pos(2);
//获取对方球员的朝向
const float&kicker_dir = model->get_opp_player_dir(2);
//获取球的向量坐标
const point2f&ball_pos = model->get_ball_pos();
//这里设定face_dir是接球机器人朝向球的方向
const float&face_dir = (kicker_pos - ball_pos).angle();
//到达目标点朝向:队员正对球
task.orientate = face_dir;
//需要到达目标点的坐标=球的位置+向量偏移距离//fac_dir反方向偏移200
task.target_pos = ball_pos - Maths::vector2polar(20, face_dir);
return task;
}
jieqiu
#include "ball.h"
#include "basevision.h"
#include "constants.h"
#include "FilteredObject.h"
#include "game_state.h"
#include "historylogger.h"
#include "matchstate.h"
#include "maths.h"
#include "PlayerTask.h"
#include "referee_commands.h"
#include "robot.h"
#include "singleton.h"
#include "util.h"
#include "vector.h"
#include "worldmodel.h"
extern "C"_declspec(dllexport) PlayerTask player_plan(const WorldModel* model, int robot_id);
PlayerTask player_plan(const WorldModel* model, int robot_id)
{
PlayerTask task;
//获取对方机器人的向量坐标
const point2f& player_pos = model->get_opp_player_pos(robot_id);
//获取对方球员的朝向
const float&player_dir = model->get_opp_player_dir(robot_id);
//获取球的向量坐标
const point2f&ball_pos = model->get_ball_pos();
//这里设定face_dir是接球机器人朝向球的方向
const float&face_dir = (player_pos - ball_pos).angle();
//到达目标点朝向:队员正对球
task.orientate = face_dir;
//需要到达目标点的坐标=球的位置+向量偏移距离//fac_dir反方向偏移200
task.target_pos = ball_pos - Maths::vector2polar(200, face_dir);
return task;
}