Skip to content

Commit 28587dd

Browse files
committed
Revert penalty changes
1 parent 377c017 commit 28587dd

File tree

4 files changed

+93
-66
lines changed

4 files changed

+93
-66
lines changed

roboteam_ai/include/roboteam_ai/stp/computations/PositionComputations.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ class PositionComputations {
137137
std::array<std::unique_ptr<Role>, stp::control_constants::MAX_ROBOT_COUNT> &roles, const Field &field,
138138
world::World *world) noexcept;
139139

140-
/**
141-
* @brief Calculates info for the formations during a penalty
142-
* @param stpInfos The current stpInfos
143-
* @param field The current field
144-
* @param world The current world
145-
*/
146-
static void calculateInfoForPenalty(std::unordered_map<std::string, StpInfo> &stpInfos, const Field &field, world::World *world) noexcept;
147-
148140
private:
149141
/**
150142
* @brief Calculates a position outside of a given shape

roboteam_ai/src/stp/computations/PositionComputations.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -473,60 +473,4 @@ void PositionComputations::calculateInfoForFormationOurSide(std::unordered_map<s
473473
}
474474
}
475475

476-
void PositionComputations::calculateInfoForPenalty(std::unordered_map<std::string, StpInfo> &stpInfos, const Field &field, world::World *world) noexcept {
477-
// During our penalty, all our robots should be behind the ball to not interfere.
478-
// Create a grid pattern of robots on our side of the field
479-
auto currentGameState = GameStateManager::getCurrentGameState().getStrategyName();
480-
constexpr double PENALTY_MARK_X = 0;
481-
int amountOfPassiveRobots = 0;
482-
if (currentGameState == "penalty_us_prepare") {
483-
constexpr double PENALTY_MARK_X = -2.0;
484-
amountOfPassiveRobots = world->getWorld()->getUs().size() - 2;
485-
} else if (currentGameState == "penalty_them_prepare") {
486-
constexpr double PENALTY_MARK_X = 2.0;
487-
amountOfPassiveRobots = world->getWorld()->getUs().size() - 1;
488-
} else {
489-
RTT_ERROR("Invalid gamestate for penalty");
490-
}
491-
// Determine where behind our robots have to stand
492-
auto ballPosition = world->getWorld()->getBall();
493-
// If there is no ball, use the default division A penalty mark position
494-
double ballX = ballPosition.has_value() ? ballPosition.value()->position.x : PENALTY_MARK_X;
495-
double limitX = std::min(ballX, PENALTY_MARK_X) - Constants::PENALTY_DISTANCE_BEHIND_BALL();
496-
497-
// Then, figure out at what interval the robots will stand on a horizontal line
498-
double horizontalRange = std::fabs(field.playArea.left() - limitX);
499-
double horizontalHalfStep = horizontalRange / (5.0 * 2.0); // 5 robots for stepSize, divided by 2 for half stepSize
500-
501-
// Lastly, figure out vertical stepSize
502-
double verticalRange = std::fabs(field.leftDefenseArea.bottom() - field.playArea.bottom());
503-
double verticalHalfStep = verticalRange / (2.0 * 2.0); // 2 rows, divided by 2 for half stepSize
504-
505-
double startX = field.playArea.left() + horizontalHalfStep;
506-
double bottomY = field.playArea.bottom() + verticalHalfStep;
507-
double topY = bottomY + 2 * verticalHalfStep;
508-
509-
const std::string formationPrefix = "formation_";
510-
511-
/// Bottom row of 5 robots
512-
for (int i = 0; i < amountOfPassiveRobots / 2; i++) {
513-
auto formationName = formationPrefix + std::to_string(i);
514-
auto position = Vector2(startX + i * 2 * horizontalHalfStep, bottomY);
515-
stpInfos[formationName].setPositionToMoveTo(position);
516-
517-
auto angleToGoal = (field.rightGoalArea.leftLine().center() - position).toAngle();
518-
stpInfos[formationName].setAngle(angleToGoal);
519-
}
520-
521-
/// Top row of 5 robots
522-
for (int i = amountOfPassiveRobots / 2; i < amountOfPassiveRobots; i++) {
523-
auto formationName = formationPrefix + std::to_string(i);
524-
auto position = Vector2(startX + (i - 5) * 2 * horizontalHalfStep, topY);
525-
stpInfos[formationName].setPositionToMoveTo(position);
526-
527-
auto angleToGoal = (field.rightGoalArea.leftLine().center() - position).toAngle();
528-
stpInfos[formationName].setAngle(angleToGoal);
529-
}
530-
}
531-
532476
} // namespace rtt::ai::stp

roboteam_ai/src/stp/plays/referee_specific/PenaltyThemPrepare.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace rtt::ai::stp::play {
77

8+
// The x position on which the enemy takes the penalty
9+
constexpr double PENALTY_MARK_THEM_X = 2.0;
10+
811
PenaltyThemPrepare::PenaltyThemPrepare() : Play() {
912
startPlayEvaluation.clear();
1013
startPlayEvaluation.emplace_back(eval::PenaltyThemPrepareGameState);
@@ -55,7 +58,50 @@ Dealer::FlagMap PenaltyThemPrepare::decideRoleFlags() const noexcept {
5558

5659
void PenaltyThemPrepare::calculateInfoForRoles() noexcept {
5760
PositionComputations::calculateInfoForKeeper(stpInfos, field, world);
58-
PositionComputations::calculateInfoForPenalty(stpInfos, field, world);
61+
62+
// During their penalty, all our robots should be behind the ball to not interfere.
63+
// Create a grid pattern of robots on their side of the field
64+
int amountOfPassiveRobots = world->getWorld()->getUs().size() - 1;
65+
// Determine where behind our robots have to stand
66+
auto ballPosition = world->getWorld()->getBall();
67+
// If there is no ball, use the default division A penalty mark position
68+
double ballX = ballPosition.has_value() ? ballPosition.value()->position.x : PENALTY_MARK_THEM_X;
69+
double limitX = std::max(ballX, PENALTY_MARK_THEM_X) + Constants::PENALTY_DISTANCE_BEHIND_BALL();
70+
71+
// First, figure out at what interval the robots will stand on a horizontal line
72+
double horizontalRange = std::fabs(field.playArea.right() - limitX);
73+
double horizontalHalfStep = horizontalRange / amountOfPassiveRobots; // 5 robots for stepSize, divided by 2 for half stepSize
74+
75+
// Then, figure out vertical stepSize
76+
double verticalRange = std::fabs(field.rightDefenseArea.bottom() - field.playArea.bottom());
77+
double verticalHalfStep = verticalRange / (2.0 * 2.0); // 2 rows, divided by 2 for half stepSize
78+
79+
double startX = field.playArea.right() - horizontalHalfStep;
80+
double bottomY = field.playArea.bottom() + verticalHalfStep;
81+
double topY = bottomY + 2 * verticalHalfStep;
82+
83+
const std::string formationPrefix = "formation_";
84+
85+
/// Bottom row of robots
86+
for (int i = 0; i < amountOfPassiveRobots / 2; i++) {
87+
auto formationName = formationPrefix + std::to_string(i);
88+
auto position = Vector2(startX - i * 2 * horizontalHalfStep, bottomY);
89+
stpInfos[formationName].setPositionToMoveTo(position);
90+
91+
auto angleToGoal = (field.leftGoalArea.rightLine().center() - position).toAngle();
92+
stpInfos[formationName].setAngle(angleToGoal);
93+
}
94+
95+
/// Top row of robots
96+
for (int i = amountOfPassiveRobots / 2; i < amountOfPassiveRobots; i++) {
97+
auto formationName = formationPrefix + std::to_string(i);
98+
auto position = Vector2(startX - (i - amountOfPassiveRobots / 2) * 2 * horizontalHalfStep, topY);
99+
stpInfos[formationName].setPositionToMoveTo(position);
100+
101+
auto angleToGoal = (field.leftGoalArea.rightLine().center() - position).toAngle();
102+
stpInfos[formationName].setAngle(angleToGoal);
103+
}
104+
59105
}
60106

61107
const char* PenaltyThemPrepare::getName() const { return "Penalty Them Prepare"; }

roboteam_ai/src/stp/plays/referee_specific/PenaltyUsPrepare.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace rtt::ai::stp::play {
77

8+
// The x position on which we take the penalty
9+
constexpr double PENALTY_MARK_US_X = -2.0;
10+
811
PenaltyUsPrepare::PenaltyUsPrepare() : Play() {
912
startPlayEvaluation.clear();
1013
startPlayEvaluation.emplace_back(eval::PenaltyUsPrepareGameState);
@@ -59,9 +62,51 @@ Dealer::FlagMap PenaltyUsPrepare::decideRoleFlags() const noexcept {
5962

6063
void PenaltyUsPrepare::calculateInfoForRoles() noexcept {
6164
// We need at least a keeper, and a kicker positioned behind the ball
62-
PositionComputations::calculateInfoForPenalty(stpInfos, field, world);
6365
stpInfos["keeper"].setPositionToMoveTo(Vector2(field.leftGoalArea.rightLine().center()));
6466
stpInfos["kicker_formation"].setPositionToMoveTo(world->getWorld()->getBall()->get()->position - Vector2{0.25, 0.0});
67+
68+
// During our penalty, all our robots should be behind the ball to not interfere.
69+
// Create a grid pattern of robots on our side of the field
70+
int amountOfPassiveRobots = world->getWorld()->getUs().size() - 2;
71+
// Determine where behind our robots have to stand
72+
auto ballPosition = world->getWorld()->getBall();
73+
// If there is no ball, use the default division A penalty mark position
74+
double ballX = ballPosition.has_value() ? ballPosition.value()->position.x : PENALTY_MARK_US_X;
75+
double limitX = std::min(ballX, PENALTY_MARK_US_X) - Constants::PENALTY_DISTANCE_BEHIND_BALL();
76+
77+
// Then, figure out at what interval the robots will stand on a horizontal line
78+
double horizontalRange = std::fabs(field.playArea.left() - limitX);
79+
double horizontalHalfStep = horizontalRange / amountOfPassiveRobots; // 5 robots for stepSize, divided by 2 for half stepSize
80+
81+
// Lastly, figure out vertical stepSize
82+
double verticalRange = std::fabs(field.leftDefenseArea.bottom() - field.playArea.bottom());
83+
double verticalHalfStep = verticalRange / (2.0 * 2.0); // 2 rows, divided by 2 for half stepSize
84+
85+
double startX = field.playArea.left() + horizontalHalfStep;
86+
double bottomY = field.playArea.bottom() + verticalHalfStep;
87+
double topY = bottomY + 2 * verticalHalfStep;
88+
89+
const std::string formationPrefix = "formation_";
90+
91+
/// Bottom row of robots
92+
for (int i = 0; i < amountOfPassiveRobots / 2; i++) {
93+
auto formationName = formationPrefix + std::to_string(i);
94+
auto position = Vector2(startX + i * 2 * horizontalHalfStep, bottomY);
95+
stpInfos[formationName].setPositionToMoveTo(position);
96+
97+
auto angleToGoal = (field.rightGoalArea.leftLine().center() - position).toAngle();
98+
stpInfos[formationName].setAngle(angleToGoal);
99+
}
100+
101+
/// Top row of robots
102+
for (int i = amountOfPassiveRobots / 2; i < amountOfPassiveRobots; i++) {
103+
auto formationName = formationPrefix + std::to_string(i);
104+
auto position = Vector2(startX + (i - amountOfPassiveRobots / 2) * 2 * horizontalHalfStep, topY);
105+
stpInfos[formationName].setPositionToMoveTo(position);
106+
107+
auto angleToGoal = (field.rightGoalArea.leftLine().center() - position).toAngle();
108+
stpInfos[formationName].setAngle(angleToGoal);
109+
}
65110
}
66111

67112
const char* PenaltyUsPrepare::getName() const { return "Penalty Us Prepare"; }

0 commit comments

Comments
 (0)