diff --git a/StrategySystem.cpp b/StrategySystem.cpp index c89293c..844459b 100644 --- a/StrategySystem.cpp +++ b/StrategySystem.cpp @@ -311,7 +311,8 @@ void CStrategySystem::Freeball() { } } -double CStrategySystem::atwo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) // 两直线间夹角 +// 两直线间夹角 +double CStrategySystem::atwo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { double j = 0; double k1 = (y1 - y2) / (x1 - x2); @@ -440,6 +441,8 @@ double CStrategySystem::atwo(int x1, int y1, int x2, int y2, int x3, int y3, int // for (int i = 1; i < 11; i++) // 1-10 // control(i); //} + +//控球具体实现 void CStrategySystem::Possession() { CPoint pos[10]; RelPos rp[10]; @@ -1208,10 +1211,79 @@ void CStrategySystem::Possession() { } } else { // TODO 无中央球员 + if (fm_id() == 4 || fm_id() == 6) { + pos[0] = CPoint(ball.position.x + (int)cos(0* PI / 180) * 40, ball.position.y + (int)sin(20* PI / 180) * 40); + pos[1] = CPoint(ball.position.x + (int)cos(45.0 * PI / 180.0) * 20, ball.position.y + (int)sin(45.0 * PI / 180.0) * 20); + pos[2] = CPoint(ball.position.x + (int)cos(90.0 * PI / 180.0) * 20, ball.position.y + (int)sin(90.0 * PI / 180.0) * 20); + pos[3] = CPoint(pos[0].x + (int)cos(0.0 * PI / 180.0) * 40, pos[0].y + (int)sin(0.0 * PI / 180.0) * 40); + pos[4] = CPoint(pos[0].x + (int)cos(15.0 * PI / 180.0) * 40, pos[0].y + (int)sin(15.0 * PI / 180.0) * 40); + pos[5] = CPoint(pos[0].x + (int)cos(30.0 * PI / 180.0) * 40, pos[0].y + (int)sin(30.0 * PI / 180.0) * 40); + pos[6] = CPoint(pos[0].x + (int)cos(45.0 * PI / 180.0) * 40, pos[0].y + (int)sin(45.0 * PI / 180.0) * 40); + pos[7] = CPoint(pos[0].x + (int)cos(50.0 * PI / 180.0) * 60, pos[0].y + (int)sin(50.0 * PI / 180.0) * 60); + pos[8] = CPoint(pos[0].x + (int)cos(60.0 * PI / 180.0) * 60, pos[0].y + (int)sin(60.0 * PI / 180.0) * 60); + pos[9] = CPoint(pos[0].x + (int)cos(75.0 * PI / 180.0) * 60, pos[0].y + (int)sin(75.0 * PI / 180.0) * 60); + + fp_sort(rp); + fp_sort(rp, 0, 2); + Direction(rp[0].id, pos[1]); + Direction(rp[1].id, pos[2]); + fp_sort(rp, 2, 5); + Direction(rp[2].id, pos[3]); + Direction(rp[3].id, pos[4]); + Direction(rp[4].id, pos[5]); + fp_sort(rp, 5, 9); + Direction(rp[5].id, pos[6]); + Direction(rp[6].id, pos[7]); + Direction(rp[7].id, pos[8]); + Direction(rp[8].id, pos[9]); + + } + else if (fm_id() == 5) { + pos[0] = CPoint(ball.position.x + (int)cos(0 * PI / 180) * 40, ball.position.y - (int)sin(20 * PI / 180) * 40); + pos[1] = CPoint(ball.position.x + (int)cos(0.0 * PI / 180.0) * 20, ball.position.y + (int)sin(0.0 * PI / 180.0) * 20); + pos[2] = CPoint(ball.position.x + (int)cos(-90.0 * PI / 180.0) * 20, ball.position.y + (int)sin(-90.0 * PI / 180.0) * 20); + pos[3] = CPoint(pos[0].x + (int)cos(0.0 * PI / 180.0) * 40, pos[0].y + (int)sin(0.0 * PI / 180.0) * 40); + pos[4] = CPoint(pos[0].x + (int)cos(-15.0 * PI / 180.0) * 40, pos[0].y + (int)sin(-15.0 * PI / 180.0) * 40); + pos[5] = CPoint(pos[0].x + (int)cos(-30.0 * PI / 180.0) * 40, pos[0].y + (int)sin(-30.0 * PI / 180.0) * 40); + pos[6] = CPoint(pos[0].x + (int)cos(-45.0 * PI / 180.0) * 40, pos[0].y + (int)sin( - 45.0 * PI / 180.0) * 40); + pos[7] = CPoint(pos[0].x + (int)cos(-50.0 * PI / 180.0) * 60, pos[0].y + (int)sin(-50.0 * PI / 180.0) * 60); + pos[8] = CPoint(pos[0].x + (int)cos(-60.0 * PI / 180.0) * 60, pos[0].y + (int)sin(-60.0 * PI / 180.0) * 60); + pos[9] = CPoint(pos[0].x + (int)cos(-75.0 * PI / 180.0) * 60, pos[0].y + (int)sin(-75.0 * PI / 180.0) * 60); + + fp_sort(rp); + fp_sort(rp, 0, 2); + Direction(rp[0].id, pos[1]); + Direction(rp[1].id, pos[2]); + fp_sort(rp, 2, 5); + Direction(rp[2].id, pos[3]); + Direction(rp[3].id, pos[4]); + Direction(rp[4].id, pos[5]); + fp_sort(rp, 5, 9); + Direction(rp[5].id, pos[6]); + Direction(rp[6].id, pos[7]); + Direction(rp[7].id, pos[8]); + Direction(rp[8].id, pos[9]); + } + } } -int CStrategySystem::cp_id() { // 中央球员 ID +//搜索最近球员位置 +CPoint CStrategySystem::searchNear(int which) { + CPoint cur_pos[10]{ home1.position, home2.position, home3.position, home4.position, home5.position, home6.position, home7.position, home8.position, home9.position, home10.position }; + double ddd = 10000; + CPoint near; + for (int i = 0; i < 10; i++) { + if (Distance(cur_pos[i], ball.position) < ddd) { + ddd = Distance(cur_pos[i], ball.position); + near = cur_pos[i]; + } + } + return near; +} + +// 中央球员 ID +int CStrategySystem::cp_id() { int id = 0; CPoint cur_pos[10]{ home1.position, home2.position, home3.position, home4.position, home5.position, home6.position, home7.position, home8.position, home9.position, home10.position }; if (fm_id() == 1) { @@ -1311,7 +1383,8 @@ int CStrategySystem::cp_id() { // 中央球员 ID return id; } -int CStrategySystem::fm_id() { // 阵型 ID +// 阵型 ID +int CStrategySystem::fm_id() { if (ball.position.x < 290) { if (ball.position.y < 217) return 1; @@ -1344,7 +1417,9 @@ int CStrategySystem::fm_id() { // 阵型 ID // double dis; // double ang; // (-π, π] // }; -void CStrategySystem::fp_sort(RelPos *rp, int h, int t) { // 阵型球员排序,h 为该层前的球员数量,t 为包含该层后的球员数量 + +// 阵型球员排序,h 为该层前的球员数量,t 为包含该层后的球员数量 +void CStrategySystem::fp_sort(RelPos *rp, int h, int t) { RelPos r; if (!h && !t) { for (int i = 1; i < 10; i++) { @@ -1366,7 +1441,8 @@ void CStrategySystem::fp_sort(RelPos *rp, int h, int t) { // 阵型球员排序 } } -CPoint CStrategySystem::coor(int which) // 返回机器人的位置 +// 返回机器人的位置 +CPoint CStrategySystem::coor(int which) { Robot2 *robot; switch (which) { @@ -1407,7 +1483,8 @@ CPoint CStrategySystem::coor(int which) // 返回机器人的位置 return robot->position; } -void CStrategySystem::shot(int which, bool de) // 0向下门框射 +// 0向下门框射 +void CStrategySystem::shot(int which, bool de) { Robot2 *robot; switch (which) { @@ -1481,7 +1558,8 @@ void CStrategySystem::shot(int which, bool de) // 0向下门框射 Position(which, t3); // 机器人到足够近的点t3 } -bool CStrategySystem::canshot() // 射? +// 射? +bool CStrategySystem::canshot() { bool t; // 判断球在敌方上半还是下半;0为下半 CPoint D1, D2, t4; @@ -1574,7 +1652,8 @@ bool CStrategySystem::canshot() // 射? // } } -void CStrategySystem::shot(int which, bool de, CPoint t) // 把球向t点射,de向上还是向下射 +// 把球向t点射,de向上还是向下射 +void CStrategySystem::shot(int which, bool de, CPoint t) { Robot2 *robot; switch (which) { @@ -1654,7 +1733,8 @@ void CStrategySystem::shot(int which, bool de, CPoint t) // 把球向t点射,de Position(which, t3); // 机器人到足够近的点t3 } -void CStrategySystem::shot1(int which, double o, CPoint t) { // 直射 +// 直射 +void CStrategySystem::shot1(int which, double o, CPoint t) { Robot2 *robot; switch (which) { case HOME9: @@ -2176,7 +2256,8 @@ void CStrategySystem::shot1(int which, double o, CPoint t) { // 直射 // PositionSE(which, Navigation[which]); // } -int CStrategySystem::search1() // 查找在大区里的机器人 +// 查找在大区里的机器人 +int CStrategySystem::search1() { int sum = 0; if ((home1.position.x >= 105 && home1.position.x <= 157 && home1.position.y >= 247 && home1.position.y <= 577) || (home1.position.x >= 65 && home1.position.x <= 157 && home1.position.y >= 217 && home1.position.y <= 247) || (home1.position.x >= 65 && home1.position.x <= 157 && home1.position.y >= 577 && home1.position.y <= 607)) @@ -2202,7 +2283,8 @@ int CStrategySystem::search1() // 查找在大区里的机器人 return sum; } -int CStrategySystem::search2() // 查找在小区里的机器人 +// 查找在小区里的机器人 +int CStrategySystem::search2() { int sum = 0; if (home1.position.x >= 65 && home1.position.x < 105 && home1.position.y >= 247 && home1.position.y <= 577) @@ -2282,7 +2364,8 @@ void CStrategySystem::Goalie() { // TODO 两侧卡顿 ball.oldPosition = ball.position; } -CPoint CStrategySystem::shooter_pos() { // 对方射门者位置 +// 对方射门者位置 +CPoint CStrategySystem::shooter_pos() { CPoint cur_pos[11]{ opponent.position1, opponent.position2, opponent.position3, opponent.position4, opponent.position5, opponent.position6, opponent.position7, opponent.position8, opponent.position9, opponent.position10, opponent.position11 }; for (int i = 0; i < 11; i++) { if (cur_pos[i].x >= ball.position.x) diff --git a/StrategySystem.h b/StrategySystem.h index 5adbcbf..c4a9968 100644 --- a/StrategySystem.h +++ b/StrategySystem.h @@ -41,6 +41,7 @@ private: bool canshot(); // 射? int search1(); // 查找在大区里的机器人 int search2(); // 查找在小区里的机器人 + CPoint searchNear(int which); // 查找最近的机器人 // void control(int which); // void ccd(int which, double d, double j); // 曲线行驶 double atwo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4); // 两直线间夹角