From e9701dd05ab64a84b1152a6a0c0ae4afc252da1c Mon Sep 17 00:00:00 2001 From: Luuk Date: Thu, 20 Jun 2024 20:23:45 +0200 Subject: [PATCH] Formatter --- .../computations/InterceptionComputations.h | 1 - .../stp/computations/PositionComputations.h | 3 ++- roboteam_ai/src/stp/Play.cpp | 10 +++++---- .../stp/computations/PositionComputations.cpp | 22 +++++++++++-------- .../global/WeWillHaveBallGlobalEvaluation.cpp | 4 +++- .../src/stp/plays/defensive/Defend.cpp | 5 +++-- .../referee_specific/BallPlacementThem.cpp | 5 +++-- .../plays/referee_specific/FreeKickThem.cpp | 5 +++-- .../referee_specific/PrepareForcedStart.cpp | 5 +++-- .../plays/referee_specific/StopFormation.cpp | 5 +++-- 10 files changed, 39 insertions(+), 26 deletions(-) diff --git a/roboteam_ai/include/roboteam_ai/stp/computations/InterceptionComputations.h b/roboteam_ai/include/roboteam_ai/stp/computations/InterceptionComputations.h index 92a62f636..22568a0cf 100644 --- a/roboteam_ai/include/roboteam_ai/stp/computations/InterceptionComputations.h +++ b/roboteam_ai/include/roboteam_ai/stp/computations/InterceptionComputations.h @@ -86,7 +86,6 @@ class InterceptionComputations { * @return the point where they will have the ball */ static std::optional calculateTheirBallInterception(const rtt::world::World *world, rtt::LineSegment ballTrajectory) noexcept; - }; } // namespace rtt::ai::stp #endif // RTT_INTERCEPTIONCOMPUTATIONS_H diff --git a/roboteam_ai/include/roboteam_ai/stp/computations/PositionComputations.h b/roboteam_ai/include/roboteam_ai/stp/computations/PositionComputations.h index f3b2071fc..ab19a6bff 100644 --- a/roboteam_ai/include/roboteam_ai/stp/computations/PositionComputations.h +++ b/roboteam_ai/include/roboteam_ai/stp/computations/PositionComputations.h @@ -60,7 +60,7 @@ class PositionComputations { * @param world * @return The amount of wallers needed */ - static void setAmountOfWallers(const rtt::Field &field, rtt::world::World *world) noexcept; + static void setAmountOfWallers(const rtt::Field &field, rtt::world::World *world) noexcept; /** * @brief Makes a wall if not ready done, saves it in calculatedWallPositions and deals the index @@ -159,6 +159,7 @@ class PositionComputations { static void calculateInfoForAvoidBallHarasser(std::unordered_map &stpInfos, world::World *world) noexcept; static int amountOfWallers; + private: /** * @brief Calculates a position outside of a given shape diff --git a/roboteam_ai/src/stp/Play.cpp b/roboteam_ai/src/stp/Play.cpp index bfb331cbe..3e649771d 100644 --- a/roboteam_ai/src/stp/Play.cpp +++ b/roboteam_ai/src/stp/Play.cpp @@ -142,7 +142,7 @@ void Play::distributeRoles() noexcept { auto roleName{role->getName()}; stpInfos[roleName].setRoleName(roleName); } - Play::waller_count = std::count_if(roles.begin(), roles.end(), [](const std::unique_ptr& role) { return role && role->getName().find("waller") != std::string::npos; }); + Play::waller_count = std::count_if(roles.begin(), roles.end(), [](const std::unique_ptr &role) { return role && role->getName().find("waller") != std::string::npos; }); auto flagMap = decideRoleFlags(); @@ -272,9 +272,11 @@ void Play::DrawMargins() noexcept { else color = proto::Drawing::RED; - } else if (!world->getWorld()->getBall()->get()->visible) color = proto::Drawing::CYAN; - else color = proto::Drawing::GREY; - + } else if (!world->getWorld()->getBall()->get()->visible) + color = proto::Drawing::CYAN; + else + color = proto::Drawing::GREY; + for (auto method : {proto::Drawing::CIRCLES, proto::Drawing::LINES_CONNECTED}) { rtt::ai::gui::Out::draw( { diff --git a/roboteam_ai/src/stp/computations/PositionComputations.cpp b/roboteam_ai/src/stp/computations/PositionComputations.cpp index fe2d5ca9b..b9f92aa13 100644 --- a/roboteam_ai/src/stp/computations/PositionComputations.cpp +++ b/roboteam_ai/src/stp/computations/PositionComputations.cpp @@ -44,8 +44,8 @@ void PositionComputations::setAmountOfWallers(const rtt::Field &field, rtt::worl ballPos = GameStateManager::getRefereeDesignatedPosition(); } else { ballPos = FieldComputations::projectPointInField(field, world->getWorld().value().getBall()->get()->position, constants::BALL_RADIUS); - } - + } + if (field.rightPlayArea.contains(ballPos)) { PositionComputations::amountOfWallers = 2; return; @@ -53,9 +53,12 @@ void PositionComputations::setAmountOfWallers(const rtt::Field &field, rtt::worl auto lineToBottomPost = ballPos - field.leftGoalArea.bottomRight(); auto lineToTopPost = ballPos - field.leftGoalArea.topRight(); auto angleBetweenLines = lineToBottomPost.toAngle().shortestAngleDiff(lineToTopPost.toAngle()); - if (angleBetweenLines > 0.25) PositionComputations::amountOfWallers = 4; - else if (angleBetweenLines < 0.1) PositionComputations::amountOfWallers = 2; - else if (angleBetweenLines < 0.2) PositionComputations::amountOfWallers = 3; + if (angleBetweenLines > 0.25) + PositionComputations::amountOfWallers = 4; + else if (angleBetweenLines < 0.1) + PositionComputations::amountOfWallers = 2; + else if (angleBetweenLines < 0.2) + PositionComputations::amountOfWallers = 3; } Vector2 PositionComputations::getWallPosition(int index, int amountDefenders, const rtt::Field &field, rtt::world::World *world) { @@ -88,7 +91,8 @@ std::vector PositionComputations::determineWallPositions(const rtt::Fie } else if (field.leftDefenseArea.contains(ballPos)) { // If the ball is in our defense area, project it out of it ballPos = FieldComputations::projectPointOutOfDefenseArea(field, ballPos, true, false); - } else if ((world->getWorld().value().getBall()->get()->velocity).length() > constants::BALL_GOT_SHOT_LIMIT && InterceptionComputations::calculateTheirBallInterception(world, ballTrajectory).has_value()){ + } else if ((world->getWorld().value().getBall()->get()->velocity).length() > constants::BALL_GOT_SHOT_LIMIT && + InterceptionComputations::calculateTheirBallInterception(world, ballTrajectory).has_value()) { ballPos = *InterceptionComputations::calculateTheirBallInterception(world, ballTrajectory); } else { // Project the ball into the field and use that location @@ -103,7 +107,8 @@ std::vector PositionComputations::determineWallPositions(const rtt::Fie // Find the intersection of the ball-to-goal line with the border of the defense area LineSegment ball2GoalLine = LineSegment(ballPos, field.leftGoalArea.rightLine().center()); - std::vector lineBorderIntersects = FieldComputations::getDefenseArea(field, true, std::get<1>(FieldComputations::getDefenseAreaMargin()), 0).intersections(ball2GoalLine); + std::vector lineBorderIntersects = + FieldComputations::getDefenseArea(field, true, std::get<1>(FieldComputations::getDefenseAreaMargin()), 0).intersections(ball2GoalLine); // If the ball is in our defense area, project it outside, otherwise use the intersection with our defense area std::sort(lineBorderIntersects.begin(), lineBorderIntersects.end(), [](Vector2 a, Vector2 b) { return a.x > b.x; }); projectedPosition = lineBorderIntersects.front() + extraLength; @@ -301,8 +306,7 @@ void PositionComputations::calculateInfoForHarasser(std::unordered_mapend() && !harasser->get()->finished() && strcmp(harasser->get()->getCurrentTactic()->getName(), "Formation") == 0) { auto enemyPos = enemyClosestToBall->get()->getPos(); auto targetPos = enemyPos + (world->getWorld()->getBall()->get()->position - enemyPos).stretchToLength(constants::ROBOT_RADIUS * 3); - if (enemyClosestToBall->get()->hasBall() && - ((stpInfos["harasser"].getRobot()->get()->getPos() - targetPos).length() > 1.5 * constants::GO_TO_POS_ERROR_MARGIN)) { + if (enemyClosestToBall->get()->hasBall() && ((stpInfos["harasser"].getRobot()->get()->getPos() - targetPos).length() > 1.5 * constants::GO_TO_POS_ERROR_MARGIN)) { stpInfos["harasser"].setPositionToMoveTo(targetPos); stpInfos["harasser"].setYaw((world->getWorld()->getBall()->get()->position - targetPos).angle()); } else { diff --git a/roboteam_ai/src/stp/evaluations/global/WeWillHaveBallGlobalEvaluation.cpp b/roboteam_ai/src/stp/evaluations/global/WeWillHaveBallGlobalEvaluation.cpp index 60290a531..a787dbc61 100644 --- a/roboteam_ai/src/stp/evaluations/global/WeWillHaveBallGlobalEvaluation.cpp +++ b/roboteam_ai/src/stp/evaluations/global/WeWillHaveBallGlobalEvaluation.cpp @@ -14,7 +14,9 @@ uint8_t WeWillHaveBallGlobalEvaluation::metricCheck(const world::World* world, c // If we have no bots, we will not get the ball if (us.empty()) return constants::FUZZY_FALSE; - if (world->getWorld()->getRobotClosestToBall(world::them)->get()->getPos().dist(ballPosition) < constants::ROBOT_RADIUS * 1.3 && world->getWorld()->getRobotClosestToBall(world::us)->get()->getPos().dist(ballPosition) < constants::ROBOT_RADIUS * 1.3) return false; + if (world->getWorld()->getRobotClosestToBall(world::them)->get()->getPos().dist(ballPosition) < constants::ROBOT_RADIUS * 1.3 && + world->getWorld()->getRobotClosestToBall(world::us)->get()->getPos().dist(ballPosition) < constants::ROBOT_RADIUS * 1.3) + return false; // If any of our robots has the ball, we will get the ball if (std::any_of(us.begin(), us.end(), [](auto& robot) { return robot->hasBall(); })) return constants::FUZZY_TRUE; diff --git a/roboteam_ai/src/stp/plays/defensive/Defend.cpp b/roboteam_ai/src/stp/plays/defensive/Defend.cpp index a135475b6..083a10e13 100644 --- a/roboteam_ai/src/stp/plays/defensive/Defend.cpp +++ b/roboteam_ai/src/stp/plays/defensive/Defend.cpp @@ -52,9 +52,10 @@ Dealer::FlagMap Defend::decideRoleFlags() const noexcept { flagMap.insert({"keeper", {DealerFlagPriority::KEEPER, {keeperFlag}}}); flagMap.insert({"harasser", {DealerFlagPriority::REQUIRED, {}, harasserInfo.interceptId}}); for (int i = 0; i < Play::waller_count; i++) { - if (i <= PositionComputations::amountOfWallers) { + if (i <= PositionComputations::amountOfWallers) { flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::HIGH_PRIORITY}}); - } else flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); + } else + flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); } flagMap.insert({"defender_0", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); flagMap.insert({"defender_1", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); diff --git a/roboteam_ai/src/stp/plays/referee_specific/BallPlacementThem.cpp b/roboteam_ai/src/stp/plays/referee_specific/BallPlacementThem.cpp index f5ebe2d54..06d883850 100644 --- a/roboteam_ai/src/stp/plays/referee_specific/BallPlacementThem.cpp +++ b/roboteam_ai/src/stp/plays/referee_specific/BallPlacementThem.cpp @@ -45,9 +45,10 @@ Dealer::FlagMap BallPlacementThem::decideRoleFlags() const noexcept { flagMap.insert({"keeper", {DealerFlagPriority::KEEPER, {keeperFlag}}}); flagMap.insert({"harasser", {DealerFlagPriority::REQUIRED, {}}}); for (int i = 0; i < Play::waller_count; i++) { - if (i <= PositionComputations::amountOfWallers) { + if (i <= PositionComputations::amountOfWallers) { flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::HIGH_PRIORITY}}); - } else flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); + } else + flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); } flagMap.insert({"defender_0", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); flagMap.insert({"defender_1", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); diff --git a/roboteam_ai/src/stp/plays/referee_specific/FreeKickThem.cpp b/roboteam_ai/src/stp/plays/referee_specific/FreeKickThem.cpp index 8a1dcb268..0f07be95c 100644 --- a/roboteam_ai/src/stp/plays/referee_specific/FreeKickThem.cpp +++ b/roboteam_ai/src/stp/plays/referee_specific/FreeKickThem.cpp @@ -48,9 +48,10 @@ Dealer::FlagMap FreeKickThem::decideRoleFlags() const noexcept { flagMap.insert({"keeper", {DealerFlagPriority::KEEPER, {keeperFlag}}}); flagMap.insert({"harasser", {DealerFlagPriority::REQUIRED, {}}}); for (int i = 0; i < Play::waller_count; i++) { - if (i <= PositionComputations::amountOfWallers) { + if (i <= PositionComputations::amountOfWallers) { flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::HIGH_PRIORITY}}); - } else flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); + } else + flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); } flagMap.insert({"defender_0", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); flagMap.insert({"defender_1", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); diff --git a/roboteam_ai/src/stp/plays/referee_specific/PrepareForcedStart.cpp b/roboteam_ai/src/stp/plays/referee_specific/PrepareForcedStart.cpp index f8241b876..f6d201c2d 100644 --- a/roboteam_ai/src/stp/plays/referee_specific/PrepareForcedStart.cpp +++ b/roboteam_ai/src/stp/plays/referee_specific/PrepareForcedStart.cpp @@ -48,9 +48,10 @@ Dealer::FlagMap PrepareForcedStart::decideRoleFlags() const noexcept { flagMap.insert({"keeper", {DealerFlagPriority::KEEPER, {keeperFlag}}}); flagMap.insert({"harasser", {DealerFlagPriority::REQUIRED, {}}}); for (int i = 0; i < Play::waller_count; i++) { - if (i <= PositionComputations::amountOfWallers) { + if (i <= PositionComputations::amountOfWallers) { flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::HIGH_PRIORITY}}); - } else flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); + } else + flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); } flagMap.insert({"defender_0", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); flagMap.insert({"defender_1", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); diff --git a/roboteam_ai/src/stp/plays/referee_specific/StopFormation.cpp b/roboteam_ai/src/stp/plays/referee_specific/StopFormation.cpp index 9ee906281..ba53f8a5d 100644 --- a/roboteam_ai/src/stp/plays/referee_specific/StopFormation.cpp +++ b/roboteam_ai/src/stp/plays/referee_specific/StopFormation.cpp @@ -46,9 +46,10 @@ Dealer::FlagMap StopFormation::decideRoleFlags() const noexcept { flagMap.insert({"keeper", {DealerFlagPriority::KEEPER, {keeperFlag}}}); flagMap.insert({"harasser", {DealerFlagPriority::REQUIRED, {}}}); for (int i = 0; i < Play::waller_count; i++) { - if (i <= PositionComputations::amountOfWallers) { + if (i <= PositionComputations::amountOfWallers) { flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::HIGH_PRIORITY}}); - } else flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); + } else + flagMap.insert({"waller_" + std::to_string(i), {DealerFlagPriority::MEDIUM_PRIORITY}}); } flagMap.insert({"defender_0", {DealerFlagPriority::MEDIUM_PRIORITY, {}}}); flagMap.insert({"defender_1", {DealerFlagPriority::MEDIUM_PRIORITY, {}}});