睿抗足球机器人Day5

一、注意

(1)头文件的包含是在包含目录里面
          可执行目录里面不可以(2)中场不能执行传球或者踢球代码,只能接球

 这个代码就只能实行找球代码,但是传不了球

gPlayTable.CreatePlay{
firstState = "GetBall",
["GetBall"] = {
  switch = function() 
   if CIsGetBall("receiver")then
       return "Shoot"
    end
  end,
  receiver = task.ReceiverTask("zhaoqiu"),
},
["Shoot"] = {
  switch = function() 
   if CIsBallKick("receiver")then
       return "finish"
    end
  end,
receiver = task.Shoot("receiver")
},
name = "shemen" 
} 
(3)各个角色所对应的名字

Kicker是前锋

receiver是中场

Middle是前腰,可以踢球射门

Defender是后腰,可以踢球射门

Tier是后卫,可以踢球射门

二、一次传球含射门

(1)lua脚本

 lua脚本的文件名是chuanqiu4

gPlayTable.CreatePlay{
firstState = "GetBall",
["GetBall"] = {
  switch = function() 
   if CIsGetBall("Kicker")then
       return "PassBall"
    end
  end,
  Kicker = task.KickerTask("chuanqiu1"),
  Defender = task.DefenderTask("jieqiu")
},
["PassBall"] = {
  switch = function() 
   if CIsBallKick("Kicker")then
       return "zhaoqiu"
    end
  end,
  Kicker = task.KickerTask("chuanqiu2"),
},
["zhaoqiu"] = {
  switch = function() 
   if CIsBallKick("Defender") then
       return "finish"
    end
  end,
  Defender = task.Shoot("Defender")
},
name = "chuanqiu4" 
}
(2)C++代码

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(10, face_dir);

	return task;
}

 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);
	//判断球的位置,我方球员位置,我方球员方向是否三点一线
	bool get_ball = ((abs((kicker_pos - ball_pos).angle() - (reciver_pos - ball_pos).angle() < 0.5)));
	if (get_ball)
	{
		//执行平击踢球,力度为最大127
		task.kickPower = 127;
		//踢球开关
		task.needKick = true;
		//挑球开关
		task.isChipKick = false;
	}

	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 = (ball_pos - player_pos).angle();
	//到达目标点朝向:队员正对球
	task.orientate = face_dir;
	//需要到达目标点的坐标=球的位置+向量偏移距离//fac_dir反方向偏移200
	task.target_pos = ball_pos - Maths::vector2polar(200, face_dir);
   
	return task;
}
(3)lua射门代码
["zhaoqiu"] = {
  switch = function() 
   if CIsGetBall("Defender") then
       return "shoot"
    end
  end,
  Defender = task.GetBall("Defender")
},
["zhaoqiu"] = {
  switch = function() 
   if CIsBallKick("Defender") then
       return "finish"
    end
  end,
  Defender = task.Shoot("Defender")
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值