Skip to content

Commit 4c651bd

Browse files
Merge branch 'robocup_2019' of github.com:UBC-Thunderbots/Software into robocup_2019
2 parents 307454d + 581de74 commit 4c651bd

File tree

6 files changed

+38
-20
lines changed

6 files changed

+38
-20
lines changed

src/thunderbots/software/ai/hl/stp/play/defense_play.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)
5050

5151
std::shared_ptr<ShadowEnemyTactic> shadow_enemy_tactic =
5252
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
53-
world.enemyTeam(), true, true);
53+
world.enemyTeam(), true, world.ball(), true);
5454

5555

5656
std::array<std::shared_ptr<CreaseDefenderTactic>, 2> crease_defender_tactics = {
@@ -153,7 +153,8 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)
153153
if (enemy_threats.size() > 1) {
154154
shadow_enemy_tactic->updateParams(
155155
enemy_threats.at(1), world.field(), world.friendlyTeam(),
156-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
156+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3,
157+
enemy_team_can_pass, world.ball());
157158
result.emplace_back(shadow_enemy_tactic);
158159
} else {
159160
Robot nearest_enemy_robot = *std::min_element(

src/thunderbots/software/ai/hl/stp/play/enemy_freekick_play.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
5353

5454
// Init Shadow Enemy Tactics for extra robots
5555
auto shadow_tactic_main = std::make_shared<ShadowEnemyTactic>(
56-
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
56+
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);
5757
auto shadow_tactic_secondary = std::make_shared<ShadowEnemyTactic>(
58-
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
58+
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);
5959

6060
// Init Move Tactics for extra robots (These will be used if there are no robots to
6161
// shadow)
@@ -114,7 +114,7 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
114114
{
115115
shadow_tactic_main->updateParams(
116116
enemy_threats.at(1), world.field(), world.friendlyTeam(),
117-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
117+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
118118
move_tactic_main->updateParams(
119119
world.field().friendlyGoal() + Point(0, 2 * ROBOT_MAX_RADIUS_METERS),
120120
(world.ball().position() - world.field().friendlyGoal()).orientation(),
@@ -127,10 +127,10 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
127127
{
128128
shadow_tactic_main->updateParams(
129129
enemy_threats.at(1), world.field(), world.friendlyTeam(),
130-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
130+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
131131
shadow_tactic_secondary->updateParams(
132132
enemy_threats.at(2), world.field(), world.friendlyTeam(),
133-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
133+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
134134

135135
tactics_to_run.emplace_back(shadow_tactic_main);
136136
tactics_to_run.emplace_back(shadow_tactic_secondary);

src/thunderbots/software/ai/hl/stp/play/kickoff_enemy_play.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
3535
// on the field to be evenly spread out
3636
std::vector<std::shared_ptr<ShadowEnemyTactic>> shadow_enemy_tactics = {
3737
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
38-
world.enemyTeam(), true, true),
38+
world.enemyTeam(), true, world.ball(), true),
3939
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
40-
world.enemyTeam(), true, true),
40+
world.enemyTeam(), true, world.ball(), true),
4141
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
42-
world.enemyTeam(), true, true)};
42+
world.enemyTeam(), true, world.ball(), true)};
4343

4444
// these positions are picked according to the following slide
4545
// https://images.slideplayer.com/32/9922349/slides/slide_2.jpg
@@ -118,7 +118,7 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
118118
// anyway
119119
shadow_enemy_tactics.at(i)->updateParams(
120120
enemy_threat, world.field(), world.friendlyTeam(), world.enemyTeam(),
121-
shadow_dist, false);
121+
shadow_dist, false, world.ball());
122122
result.emplace_back(shadow_enemy_tactics.at(i));
123123
}
124124
else

src/thunderbots/software/ai/hl/stp/tactic/penalty_kick_tactic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void PenaltyKickTactic::calculateNextIntent(IntentCoroutine::push_type& yield)
134134

135135
auto [shot_location, extra] = raySegmentIntersection(shot_ray, Segment(field.enemyGoalpostPos(), field.enemyGoalpostNeg()));
136136

137-
if(!evaluate_penalty_shot() && !YEET_SHOOTING) {
137+
if(!evaluate_penalty_shot() && !YEET_SHOOTING && !((robot->getMostRecentTimestamp() - start_of_shoot) > Duration::fromSeconds(7))) {
138138
printf("\nGetting to position");
139139
yield(get_behind_ball_act.updateStateAndGetNextIntent(*robot, behind_ball, robot->orientation(), 0, true, false, AutokickType::NONE));
140140
printf("evaluate shot %d", evaluate_penalty_shot());

src/thunderbots/software/ai/hl/stp/tactic/shadow_enemy_tactic.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
#include "ai/hl/stp/action/stop_action.h"
55
#include "ai/hl/stp/evaluation/calc_best_shot.h"
66
#include "shadow_enemy_tactic.h"
7+
#include "ai/hl/stp/evaluation/robot.h"
8+
#include "util/parameter/dynamic_parameters.h"
79

810
ShadowEnemyTactic::ShadowEnemyTactic(const Field &field, const Team &friendly_team,
9-
const Team &enemy_team, bool ignore_goalie,
11+
const Team &enemy_team, bool ignore_goalie, const Ball& ball,
1012
bool loop_forever)
1113
: field(field),
1214
friendly_team(friendly_team),
1315
enemy_team(enemy_team),
1416
shadow_distance(ROBOT_MAX_RADIUS_METERS * 3),
1517
ignore_goalie(ignore_goalie),
18+
ball(ball),
1619
Tactic(loop_forever)
1720
{
1821
}
@@ -25,14 +28,15 @@ std::string ShadowEnemyTactic::getName() const
2528
void ShadowEnemyTactic::updateParams(const Evaluation::EnemyThreat &enemy_threat,
2629
const Field &field, const Team &friendly_team,
2730
const Team &enemy_team, double shadow_distance,
28-
bool enemy_team_can_pass)
31+
bool enemy_team_can_pass, const Ball& ball)
2932
{
3033
this->enemy_threat = enemy_threat;
3134
this->field = field;
3235
this->friendly_team = friendly_team;
3336
this->enemy_team = enemy_team;
3437
this->shadow_distance = shadow_distance;
3538
this->enemy_team_can_pass = enemy_team_can_pass;
39+
this->ball = ball;
3640
}
3741

3842
double ShadowEnemyTactic::calculateRobotCost(const Robot &robot, const World &world)
@@ -94,11 +98,23 @@ void ShadowEnemyTactic::calculateNextIntent(IntentCoroutine::push_type &yield)
9498
{
9599
enemy_shot_vector = field.friendlyGoal() - enemy_robot.position();
96100
}
101+
97102
Point position_to_block_shot =
98-
enemy_robot.position() + enemy_shot_vector.norm(this->shadow_distance);
99-
yield(move_action.updateStateAndGetNextIntent(
100-
*robot, position_to_block_shot,
101-
enemy_shot_vector.orientation() + Angle::half(), 0));
103+
enemy_robot.position() + enemy_shot_vector.norm(this->shadow_distance);
104+
105+
// try to steal the ball and yeet it away if the enemy robot has already
106+
// received the pass
107+
if (Evaluation::robotHasPossession(ball, enemy_robot) && ball.velocity().len() <
108+
Util::DynamicParameters::DefenseShadowEnemyTactic::ball_steal_speed.value()) {
109+
yield(move_action.updateStateAndGetNextIntent(
110+
*robot, ball.position(),
111+
(ball.position() - robot->position()).orientation(), 0,
112+
true, false, AutokickType::AUTOCHIP));
113+
} else {
114+
yield(move_action.updateStateAndGetNextIntent(
115+
*robot, position_to_block_shot,
116+
enemy_shot_vector.orientation() + Angle::half(), 0));
117+
}
102118
}
103119
} while (!move_action.done());
104120
}

src/thunderbots/software/ai/hl/stp/tactic/shadow_enemy_tactic.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ShadowEnemyTactic : public Tactic
2323
* tactic will be restarted every time it completes
2424
*/
2525
explicit ShadowEnemyTactic(const Field &field, const Team &friendly_team,
26-
const Team &enemy_team, bool ignore_goalie,
26+
const Team &enemy_team, bool ignore_goalie, const Ball& ball,
2727
bool loop_forever = false);
2828

2929
std::string getName() const override;
@@ -45,7 +45,7 @@ class ShadowEnemyTactic : public Tactic
4545
*/
4646
void updateParams(const Evaluation::EnemyThreat &enemy_threat, const Field &field,
4747
const Team &friendly_team, const Team &enemy_team,
48-
double shadow_distance, bool enemy_team_can_pass);
48+
double shadow_distance, bool enemy_team_can_pass, const Ball& ball);
4949

5050
/**
5151
* Calculates the cost of assigning the given robot to this Tactic. Prefers robots
@@ -77,4 +77,5 @@ class ShadowEnemyTactic : public Tactic
7777
// Whether or not to ignore the friendly goalie when calculating the enemy's best shot
7878
// to shadow
7979
bool ignore_goalie;
80+
Ball ball;
8081
};

0 commit comments

Comments
 (0)