From 77d49fbee32c612a4e42755a5e8d4f80a237c7ac Mon Sep 17 00:00:00 2001 From: newhandzero <3487260047@qq.com> Date: Thu, 2 Nov 2023 17:13:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=84=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StrategySystem.cpp | 65 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/StrategySystem.cpp b/StrategySystem.cpp index f305230..804c086 100644 --- a/StrategySystem.cpp +++ b/StrategySystem.cpp @@ -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;