From 68273f66d52eb7df6e99be11093d27a1f3354182 Mon Sep 17 00:00:00 2001 From: dewfewg <3061784569@qq.com> Date: Fri, 27 Oct 2023 21:50:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StrategySystem.cpp | 65 +++++++++++++++++++++++++++++++++++----------- StrategySystem.h | 6 +++-- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/StrategySystem.cpp b/StrategySystem.cpp index 225f8a0..2eaeb94 100644 --- a/StrategySystem.cpp +++ b/StrategySystem.cpp @@ -32,15 +32,28 @@ void CStrategySystem::Freeball() { } // 射门 -void CStrategySystem::Shot() { - - Position(which,CPoint);//机器人到足够近的点 - if() - shot1(); - if() - shot2(); +void CStrategySystem::Shot(int which) { + Robot2 *robot; + switch (10) { + case HOME9: + robot = &home9; + break; + case HOME10: + robot = &home10; + break; + } + CPoint t1,t2,t3; + t1.x = ball.position.x; + t1.y = ball.position.y; + Position(10, t1); // 机器人到足够近的点 + t2.x = robot->position.x; + t2.y = robot->position.y; + if (Distance(t1,t2)==1) + shot1(10); + /*if () + shot2();*/ } -void CStrategySystem::shot1(int which) // 机器人which侧射 +void CStrategySystem::shot1(int which) // 机器人which直射 { Robot2 *robot; switch (which) { @@ -50,9 +63,32 @@ void CStrategySystem::shot1(int which) // 机器人which侧射 case HOME10: robot = &home10; break; - } - + } + CPoint t; + t.x = ball.position.x; + t.y = ball.position.y; + double o=atan(abs(robot->position.y-t.y)*1.0/abs(robot->position.x-t.x)); + Angle(which,o);//朝向球角度 + Velocity(which,127,127);//射门 } +/*void CStrategySystem::shot2(int which); // 机器人which旋转射 +{ + Robot2 *robot; + switch (which) { + case HOME9: + robot = &home9; + break; + case HOME10: + robot = &home10; + break; + } + +}*/ +/*int CStrategySystem::search()//查找在禁区里的机器人 +{ + +}*/ + // 控球 void CStrategySystem::Possession() { @@ -139,13 +175,13 @@ double CStrategySystem::Distance(CPoint point1, CPoint point2) { } int CStrategySystem::Status() { - if (ball.position.x <= 309 && ball.position.x >= 279 && ball.position.y >= 394 && ball.position.y <= 424) + /*if (ball.position.x <= 309 && ball.position.x >= 279 && ball.position.y >= 394 && ball.position.y <= 424) return 0; // 罚球 if (ball.position.x <= 309 && ball.position.x >= 279 && ball.position.y >= 394 && ball.position.y <= 424) return 1; // 争球 if (ball.position.x >= 900 && ball.position.x <= 930 && ball.position.y >= 394 && ball.position.y <= 424) - return 2; // 射门 - return 3; // 控球 + return 2; // 射门*/ + return 2; // 控球 } void CStrategySystem::Think() { @@ -158,7 +194,7 @@ void CStrategySystem::Think() { return; } if (Status() == 2) { - Shot(); + Shot(10); return; } if (Status() == 3) { @@ -169,7 +205,6 @@ void CStrategySystem::Think() { void CStrategySystem::Action() { Think(); - Goalie(); } void CStrategySystem::Angle(int which, int desired_angle) { diff --git a/StrategySystem.h b/StrategySystem.h index 1d0754a..a5a6813 100644 --- a/StrategySystem.h +++ b/StrategySystem.h @@ -23,13 +23,15 @@ private: void Penalty(); // 罚球 void Freeball(); // 争球 - void Shot(); // 射门 + void Shot(int which); // 射门 void Possession(); // 控球 void Goalie(); // 守门 int Status(); // 判断状态 double Distance(CPoint point1, CPoint point2); - void shot1(int which); + void shot1(int which);// 机器人which直射,只有直射动作 + //void shot2(int which);// 机器人which旋转射 + //int search();//查找在禁区里的机器人 CRect boundRect; int m_nStrategy;