Skip to content

Commit

Permalink
Formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Luuk committed Jun 20, 2024
1 parent a914b7f commit e9701dd
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class InterceptionComputations {
* @return the point where they will have the ball
*/
static std::optional<Vector2> calculateTheirBallInterception(const rtt::world::World *world, rtt::LineSegment ballTrajectory) noexcept;

};
} // namespace rtt::ai::stp
#endif // RTT_INTERCEPTIONCOMPUTATIONS_H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,6 +159,7 @@ class PositionComputations {
static void calculateInfoForAvoidBallHarasser(std::unordered_map<std::string, StpInfo> &stpInfos, world::World *world) noexcept;

static int amountOfWallers;

private:
/**
* @brief Calculates a position outside of a given shape
Expand Down
10 changes: 6 additions & 4 deletions roboteam_ai/src/stp/Play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>& 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> &role) { return role && role->getName().find("waller") != std::string::npos; });

auto flagMap = decideRoleFlags();

Expand Down Expand Up @@ -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(
{
Expand Down
22 changes: 13 additions & 9 deletions roboteam_ai/src/stp/computations/PositionComputations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ 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;
}
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) {
Expand Down Expand Up @@ -88,7 +91,8 @@ std::vector<Vector2> 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
Expand All @@ -103,7 +107,8 @@ std::vector<Vector2> 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<Vector2> lineBorderIntersects = FieldComputations::getDefenseArea(field, true, std::get<1>(FieldComputations::getDefenseAreaMargin()), 0).intersections(ball2GoalLine);
std::vector<Vector2> 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;
Expand Down Expand Up @@ -301,8 +306,7 @@ void PositionComputations::calculateInfoForHarasser(std::unordered_map<std::stri
if (harasser != roles->end() && !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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions roboteam_ai/src/stp/plays/defensive/Defend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}}});
Expand Down
5 changes: 3 additions & 2 deletions roboteam_ai/src/stp/plays/referee_specific/FreeKickThem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}}});
Expand Down
5 changes: 3 additions & 2 deletions roboteam_ai/src/stp/plays/referee_specific/StopFormation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}}});
Expand Down

0 comments on commit e9701dd

Please sign in to comment.