柚子快報激活碼778899分享:算法 ??棺闱驒C器人Day4
柚子快報激活碼778899分享:算法 ??棺闱驒C器人Day4
一、一次傳球(踢球)代碼
(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;
//傳球機器人的位置朝向
//獲取中場機器人的向量坐標(biāo)
const point2f&reciver_pos = model->get_our_player_pos(2);
//獲取中場機器人的朝向
const float& reciver_dir = model->get_our_player_dir(2);
//獲取球的向量坐標(biāo)
const point2f&ball_pos = model->get_ball_pos();
//接球機器人的位置朝向
//獲取前鋒機器人的向量坐標(biāo)
const point2f&kicker_pos = model->get_our_player_pos(1);
//獲取前鋒機器人的朝向
const float& kicker_dir = model->get_our_player_dir(1);
//判斷球是否在小車控球嘴上,從兩個參數(shù)著手: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)
{
//執(zhí)行平擊踢球,力度為最大127
task.kickPower = 127;
//踢球開關(guān)
task.needKick = true;
//挑球開關(guān)
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);
?修改這個代碼的數(shù)值會讓機器人在找到自己位置之后,判斷是否要踢球的時候更加的精確,失誤率更小
(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;
//獲取對方機器人的向量坐標(biāo)
const point2f& kicker_pos = model->get_opp_player_pos(2);
//獲取對方球員的朝向
const float&kicker_dir = model->get_opp_player_dir(2);
//獲取球的向量坐標(biāo)
const point2f&ball_pos = model->get_ball_pos();
//這里設(shè)定face_dir是接球機器人朝向球的方向
const float&face_dir = (kicker_pos - ball_pos).angle();
//到達目標(biāo)點朝向:隊員正對球
task.orientate = face_dir;
//需要到達目標(biāo)點的坐標(biāo)=球的位置+向量偏移距離//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;
//獲取對方機器人的向量坐標(biāo)
const point2f& player_pos = model->get_opp_player_pos(robot_id);
//獲取對方球員的朝向
const float&player_dir = model->get_opp_player_dir(robot_id);
//獲取球的向量坐標(biāo)
const point2f&ball_pos = model->get_ball_pos();
//這里設(shè)定face_dir是接球機器人朝向球的方向
const float&face_dir = (player_pos - ball_pos).angle();
//到達目標(biāo)點朝向:隊員正對球
task.orientate = face_dir;
//需要到達目標(biāo)點的坐標(biāo)=球的位置+向量偏移距離//fac_dir反方向偏移200
task.target_pos = ball_pos - Maths::vector2polar(200, face_dir);
return task;
}
柚子快報激活碼778899分享:算法 ??棺闱驒C器人Day4
好文推薦
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。