射完了

This commit is contained in:
newhandzero committed 2023-11-02 17:13:12 +08:00
1 parent 519dc6fa71
commit 77d49fbee3
1 file changed
+33 -32
+33 -32
View File
@@ -22,30 +22,30 @@ extern int nKick;
#define G_BOUND_BOUND 10
// 罚球
void CStrategySystem::Penalty() {
srand(time(nullptr));
int x = rand() % 2;
// 简单直线函数点球,向上射终点为(60,313),向下射终点为(60,505);
int k, b;
// 1往上射
if (x) {
k = (ball.position.y - 313) / (ball.position.x - 60);
b = 313 - 60 * k;
if (home1.position.x <= (ball.position.x + 16) && home1.position.x >= (ball.position.x + 16 - 1) && home1.position.y >= ((ball.position.x + 16) * k + b) - 1 && home1.position.y <= (ball.position.x + 16) * k + b)
Direction(HOME1, ball.position); // 跟踪球射门
else
Position(HOME1, CPoint(ball.position.x + 16 /*球每次更新位置,则将机器人放到函数直线上与球不同位置上,下一周期在踢球*/, (ball.position.x + 16) * k + b)); // 机器人最开始不在范围,则移动到指定位置
}
// 往下射
else {
k = (ball.position.y - 505) / (ball.position.x - 60);
b = 505 - 60 * k;
if (home1.position.x <= (ball.position.x + 16) && home1.position.x >= (ball.position.x + 16) - 1 && home1.position.y >= ((ball.position.x + 16) * k + b) - 1 && home1.position.y <= (ball.position.x + 16) * k + b)
Direction(HOME1, ball.position); // 跟踪球射门
else
Position(HOME1, CPoint(ball.position.x + 16, /*球每次更新位置,则将机器人放到函数直线上与球不同位置上,下一周期在踢球*/ (ball.position.x + 16) * k + b)); // 机器人最开始不在范围,则移动到指定位置
}
}
// void CStrategySystem::Penalty() {
// srand(time(nullptr));
// int x = rand() % 2;
// // 简单直线函数点球,向上射终点为(60,313),向下射终点为(60,505);
// int k, b;
// // 1往上射
// if (x) {
// k = (ball.position.y - 313) / (ball.position.x - 60);
// b = 313 - 60 * k;
// if (home1.position.x <= (ball.position.x + 16) && home1.position.x >= (ball.position.x + 16 - 1) && home1.position.y >= ((ball.position.x + 16) * k + b) - 1 && home1.position.y <= (ball.position.x + 16) * k + b)
// Direction(HOME1, ball.position); // 跟踪球射门
// else
// Position(HOME1, CPoint(ball.position.x + 16 /*球每次更新位置,则将机器人放到函数直线上与球不同位置上,下一周期在踢球*/, (ball.position.x + 16) * k + b)); // 机器人最开始不在范围,则移动到指定位置
// }
// // 往下射
// else {
// k = (ball.position.y - 505) / (ball.position.x - 60);
// b = 505 - 60 * k;
// if (home1.position.x <= (ball.position.x + 16) && home1.position.x >= (ball.position.x + 16) - 1 && home1.position.y >= ((ball.position.x + 16) * k + b) - 1 && home1.position.y <= (ball.position.x + 16) * k + b)
// Direction(HOME1, ball.position); // 跟踪球射门
// else
// Position(HOME1, CPoint(ball.position.x + 16, /*球每次更新位置,则将机器人放到函数直线上与球不同位置上,下一周期在踢球*/ (ball.position.x + 16) * k + b)); // 机器人最开始不在范围,则移动到指定位置
// }
// }
// 争球
void CStrategySystem::Freeball() {
@@ -103,21 +103,22 @@ void CStrategySystem::Shot(int which) {
t1.y = ball.position.y;
if(t1.y<=409.0)
{
t4.x=65.0;t4.y=505.0;
t4.x=65.0;t4.y=500.0;
O = atan(fabs(ball.position.y - t4.y) / fabs(ball.position.x - t4.x)); // fabs(Angle(,t4));
O1=180-O;
t3.x=t1.x+cos(O)*39;
t3.y=t1.y-sin(O)*39;
t3.x=t1.x+cos(O)*9;
t3.y=t1.y-sin(O)*9;
}
if(t1.y>409.0)
{
t4.x=65.0;t4.y=313.0;
t4.x=65.0;t4.y=320.0;
O = atan(fabs(ball.position.y - t4.y) / fabs(ball.position.x - t4.x)); // fabs(Angle(ball.position,t4));
O1=180+O;
t3.x=t1.x+cos(O)*39;
t3.y=t1.y+sin(O)*39;
t3.x=t1.x+cos(O)*9;
t3.y=t1.y+sin(O)*9;
}
if (Distance(robot->position,ball.position)<=40&&(fabs(Angle(ball.position,t3)-Angle(ball.position,robot->position)))<=3) {
if (Distance(robot->position,ball.position)<=10&&(fabs(Angle(ball.position,t3)-Angle(ball.position,robot->position)))<=3) {
// Angle(which, O1);//射门角度
Direction(which, ball.position);
}
else
@@ -129,7 +130,7 @@ void CStrategySystem::Shot(int which) {
shot1(which);*/
// if ()
// shot2();
}
}
void CStrategySystem::shot1(int which, double o) { // 直射
Robot2 *robot;