From 48330a3cba2b2dd3d50652d5f786d653dc6e57dd Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Sun, 29 Oct 2023 20:15:36 +0800 Subject: [PATCH] sdf --- StrategySystem.cpp | 48 +++++++++++++++++++++++++++++++++++++++------- StrategySystem.h | 7 ++++--- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/StrategySystem.cpp b/StrategySystem.cpp index 221ee88..4e116b9 100644 --- a/StrategySystem.cpp +++ b/StrategySystem.cpp @@ -28,7 +28,41 @@ void CStrategySystem::Penalty() { // 争球 void CStrategySystem::Freeball() { - // TODO: Freeball + int d = 3; + if (Status() == 2) { // 左上 + + if (Distance(home3.position, ball.position) > d) + Direction(HOME3, ball.position); + else + spin(HOME3, false); + } + else if (Status() == 3) { // 左下 + if (Distance(home3.position, ball.position) > d) + Direction(HOME1, ball.position); + else + spin(HOME1, true); + } + else if (Status() == 4) { // 右上 + if (Distance(home3.position, ball.position) > d) + Direction(HOME10, ball.position); + else + spin(HOME10, true); + } + + else if (Status() == 5) { // 右下 + + if (Distance(home3.position, ball.position) > d) + Direction(HOME7, ball.position); + else + spin(HOME10, false); + } +} + +void CStrategySystem::spin(int which, bool isClockwise) { // 自旋 + if (isClockwise) + Velocity(which, 127, -127); + else + Velocity(which, -127, 127); } // 射门 @@ -277,16 +311,16 @@ int CStrategySystem::Status() { if (ball.position.x <= 309 && ball.position.x >= 279) { if (ball.position.y >= 394 && ball.position.y <= 424) return 1; - if (ball.position.y <= 638 && ball.position.y >= 628) - return 2; // 左下争球点 if (ball.position.y <= 190 && ball.position.y >= 180) - return 3; // 左上争球点 + return 2; // 左上争球点 + if (ball.position.y <= 638 && ball.position.y >= 628) + return 3; // 左下争球点 } if (ball.position.x <= 950 && ball.position.x >= 920) { - if (ball.position.y <= 638 && ball.position.y >= 628) - return 4; // 右下争球点 if (ball.position.y <= 190 && ball.position.y >= 180) - return 5; // 右上争球点 + return 4; // 右上争球点 + if (ball.position.y <= 638 && ball.position.y >= 628) + return 5; // 右下争球点 } return 0; } diff --git a/StrategySystem.h b/StrategySystem.h index 9574d1a..6d16384 100644 --- a/StrategySystem.h +++ b/StrategySystem.h @@ -21,9 +21,10 @@ private: void Possession(); // 控球 void Goalie(); // 守门 - void shot1(int which); // 直射 - void shot2(int which); // 旋射 - int search(); // 查找在禁区里的机器人 + void spin(int which, bool isClockwise); // 自旋 + void shot1(int which); // 直射 + void shot2(int which); // 旋射 + int search(); // 查找在禁区里的机器人 double Distance(CPoint point1, CPoint point2); // 计算两点之间的距离 double Angle(CPoint point1, CPoint point2); // 计算两点之间的角度